Skip to content

Commit

Permalink
Make pep8 and pep257 run cleanly.
Browse files Browse the repository at this point in the history
Closes #67.
  • Loading branch information
Jordan Suchow authored and mpacer committed Sep 27, 2015
1 parent bb7e9d8 commit 2672cb4
Show file tree
Hide file tree
Showing 50 changed files with 184 additions and 120 deletions.
8 changes: 6 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Web app that serves proselint's API."""

from flask import Flask, request, make_response, current_app
import subprocess
import uuid
Expand All @@ -13,6 +15,7 @@
def crossdomain(origin=None, methods=None, headers=None,
max_age=21600, attach_to_all=True,
automatic_options=True):
"""Allow cross-domain requests."""
if methods is not None:
methods = ', '.join(sorted(x.upper() for x in methods))
if headers is not None and not isinstance(headers, basestring):
Expand Down Expand Up @@ -54,9 +57,10 @@ def wrapped_function(*args, **kwargs):


@app.route('/v1/', methods=["GET"])
@crossdomain(origin='*', headers=['Origin, X-Requested-With, Content-Type, Accept'])
@crossdomain(
origin='*', headers=['Origin, X-Requested-With, Content-Type, Accept'])
def lint():

"""Run proselint on the provided text and return the results."""
id = uuid.uuid4()
filename = os.path.join("tmp", "{}.md".format(id))

Expand Down
17 changes: 10 additions & 7 deletions demo.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Consistency
This is a sentence. One space after a period.
This is a sentence. Two spaces after a period.
This is a sentence. Two spaces after a period.
This is a sentence. One space after a period.
This is a sentence. One space after a period.
This is a sentence. One space after a period.
This is a sentence. One space after a period.
This is a sentence. One space after a period.
This is a sentence. Two spaces after a period.
This is a sentence. Two spaces after a period.
This is a sentence. One space after a period.
This is a sentence. One space after a period.
This is a sentence. One space after a period.
This is a sentence. One space after a period.
centre centre center
organize, organized, organizing, organise
recognize, recognise, recognise, recognise
Expand Down Expand Up @@ -102,3 +102,6 @@ Copy­right © 2015
(R) The Corporation
This is so awesome...
Bose-Einstein condensate

# Denizen labels
He's a Michiganite
1 change: 1 addition & 0 deletions proselint/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Proselint applies advice from great writers to your writing."""
1 change: 1 addition & 0 deletions proselint/checks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""All the checks are organized into modules and places here."""
1 change: 1 addition & 0 deletions proselint/checks/butterick/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Advice from Butterick's Practical Typography."""
23 changes: 15 additions & 8 deletions proselint/checks/butterick/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,24 @@

@memoize
def check(text):

"""Check the text."""
err = "BTR100"

symbols = [
["\s\(c\)\s", u"'{}' is a goofy alphabetic approximation. Use ©."],
["\s\(TM\)\s", u"'{}' is a goofy alphabetic approximation. Use ™."],
["\s\(R\)\s", u"'{}' is a goofy alphabetic approximation. Use ®."],
[u"[Cc]opy­right ©", u"'{}' is redundant. Use the word or the symbol."],
[r"\.\.\.", u"'...' is an approximation, use the ellipsis symbol '…'."],
[u"[A-Z][a-z]{1,10}[-\u2014][A-Z][a-z]{1,10}", u"Use an en dash (–) to separate names."],
["\. {3}", "More than two spaces after the period; use 1 or 2."],
["\s\(c\)\s",
u"'{}' is a goofy alphabetic approximation. Use ©."],
["\s\(TM\)\s",
u"'{}' is a goofy alphabetic approximation. Use ™."],
["\s\(R\)\s",
u"'{}' is a goofy alphabetic approximation. Use ®."],
[u"[Cc]opy­right ©",
u"'{}' is redundant. Use the word or the symbol."],
[r"\.\.\.",
u"'...' is an approximation, use the ellipsis symbol '…'."],
[u"[A-Z][a-z]{1,10}[-\u2014][A-Z][a-z]{1,10}",
u"Use an en dash (–) to separate names."],
["\. {3}",
"More than two spaces after the period; use 1 or 2."],
]

errors = []
Expand Down
1 change: 1 addition & 0 deletions proselint/checks/consistency/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Various consistency checks."""
5 changes: 3 additions & 2 deletions proselint/checks/consistency/spacing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

@memoize
def check(text):

"""Check the text."""
err = "CST200"
msg = "Inconsistent spacing after period (1 vs. 2 spaces)."

return consistency_check(text, [["[^\w\s] [A-Z]", "[^\w\s] [A-Z]"]], err, msg)
regex = "[^\w\s] [A-Z]", "[^\w\s] [A-Z]"
return consistency_check(text, [regex], err, msg)
2 changes: 1 addition & 1 deletion proselint/checks/consistency/spelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

@memoize
def check(text):

"""Check the text."""
err = "IEL100"
msg = "Inconsistent spelling of '{}' (vs. '{}')."

Expand Down
Empty file.
1 change: 1 addition & 0 deletions proselint/checks/garner/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Advice from Garner's Modern Ameican Usage."""
6 changes: 3 additions & 3 deletions proselint/checks/garner/a_vs_an.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""MAU100: Misuse of 'a' vs. 'an'.
u"""MAU100: Misuse of 'a' vs. 'an'.
---
layout: post
Expand All @@ -21,7 +21,7 @@

@memoize
def check(text):

"""Define the check."""
err = "MAU101"
msg_a = "'a' should be 'an'."
msg_an = "'an' should be 'a'."
Expand Down Expand Up @@ -52,7 +52,6 @@ def check(text):
@memoize
def starts_with_vowel_sound(word):
"""Check whether the word starts with a vowel sound."""

# Get the pronunciations of the word.
if 'd' not in globals():
import nltk
Expand Down Expand Up @@ -80,6 +79,7 @@ def starts_with_vowel_sound(word):


def initialize():
"""Initialize the cache of pronunciations."""
print "Running initialization for garner.a_vs_an (may take a few minutes)"
from nltk.corpus import cmudict

Expand Down
6 changes: 3 additions & 3 deletions proselint/checks/garner/airlinese.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
Airlinese.
"""
from proselint.tools import blacklist, memoize
from proselint.tools import existence_check, memoize


@memoize
def check(text):

"""Check the text."""
err = "MAU108"
msg = u"'{}' is airlinese."

Expand All @@ -28,4 +28,4 @@ def check(text):
"momentarily",
]

return blacklist(text, airlinese, err, msg)
return existence_check(text, airlinese, err, msg)
9 changes: 5 additions & 4 deletions proselint/checks/garner/archaism.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
Archaism.
"""
from proselint.tools import blacklist, memoize
from proselint.tools import existence_check, memoize


@memoize
def check(text):

"""Check the text."""
err = "MAU103"
msg = u"'{}' is archaic."

Expand Down Expand Up @@ -78,7 +78,8 @@ def check(text):
# "demean", when used to mean "to behave" in legal contexts
# "by the bye", # variant, modern is "by the by"
# "comptroller" # in british english
# "abortive" Abortive is archaic in reference to abortions of fetuses, except in the sense “causing an abortion.”
# "abortive" Abortive is archaic in reference to abortions of fetuses,
# except in the sense “causing an abortion.”
]

return blacklist(text, archaisms, err, msg)
return existence_check(text, archaisms, err, msg)
4 changes: 2 additions & 2 deletions proselint/checks/garner/cliches.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""MAU100: Cliches.
u"""MAU100: Cliches.
---
layout: post
Expand All @@ -20,7 +20,7 @@

@memoize
def check(text):

"""Check the text."""
err = "MAU101"
msg = u"'{}' is cliché."

Expand Down
6 changes: 3 additions & 3 deletions proselint/checks/garner/commercialese.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
Archaism.
"""
from proselint.tools import blacklist, memoize
from proselint.tools import existence_check, memoize


@memoize
def check(text):

"""Check the text."""
err = "MAU104"
msg = u"'{}' is commercialese."

Expand Down Expand Up @@ -51,4 +51,4 @@ def check(text):
"yours of even date"
]

return blacklist(text, commercialese, err, msg)
return existence_check(text, commercialese, err, msg)
8 changes: 2 additions & 6 deletions proselint/checks/garner/denizen_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
Denizen labels.
"""
import re
from proselint.tools import memoize
from proselint.tools import memoize, existence_check


@memoize
Expand All @@ -32,8 +31,5 @@ def check(text):
]
errors = []
for p in preferences:
for r in p[1]:
for m in re.finditer("\s{}\s".format(r), text, flags=re.IGNORECASE):
errors.append((m.start()+1, m.end(), err, msg.format(p[0])))

errors += existence_check(text, p[1], err, msg)
return errors
6 changes: 3 additions & 3 deletions proselint/checks/garner/illogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
Archaism.
"""
from proselint.tools import blacklist, memoize
from proselint.tools import existence_check, memoize


@memoize
def check(text):

"""Check the text."""
err = "MAU105"
msg = u"'{}' is illogical."

Expand All @@ -34,4 +34,4 @@ def check(text):
"no longer requires oxygen",
]

return blacklist(text, illogics, err, msg)
return existence_check(text, illogics, err, msg)
3 changes: 1 addition & 2 deletions proselint/checks/garner/preferred_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ def check(text):
errors = []
for p in preferences:
for r in p[1]:
for m in re.finditer("\s{}\s".format(r), text, flags=re.IGNORECASE):

for m in re.finditer("\s{}\s".format(r), text, flags=re.I):
errors.append((m.start()+1, m.end(), err, msg.format(p[0])))

return errors
Empty file.
7 changes: 4 additions & 3 deletions proselint/checks/inprogress/example_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
"""
from proselint.tools import reverse

def check(text):

reversed_text = reverse(text)

def check(text):
"""Check the text."""
error_code = "PL000"
msg = "First line always has an error."

reverse(text)

return [(1, 1, error_code, msg)]
Empty file.
1 change: 0 additions & 1 deletion proselint/checks/inprogress/needless_variants.py

This file was deleted.

1 change: 1 addition & 0 deletions proselint/checks/misc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Miscellaneous advice not otherwise categorized."""
6 changes: 3 additions & 3 deletions proselint/checks/misc/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
Annotation left in text.
"""
from proselint.tools import blacklist, memoize
from proselint.tools import existence_check, memoize


@memoize
def check(text):

"""Check the text."""
err = "ANN100"
msg = u"Annotation left in text."

Expand All @@ -32,4 +32,4 @@ def check(text):
"FIX THIS",
]

return blacklist(text, annotations, err, msg, ignore_case=False)
return existence_check(text, annotations, err, msg, ignore_case=False)
6 changes: 3 additions & 3 deletions proselint/checks/misc/chatspeak.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
Chatspeak.
"""
from proselint.tools import blacklist, memoize
from proselint.tools import existence_check, memoize


@memoize
def check(text):

"""Check the text."""
err = "MSC104"
msg = u"'{}' is chatspeak. Write it out."

Expand Down Expand Up @@ -49,4 +49,4 @@ def check(text):
"XOXO"
]

return blacklist(text, words, err, msg)
return existence_check(text, words, err, msg)
6 changes: 3 additions & 3 deletions proselint/checks/misc/creditcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
Credit card number printed.
"""
from proselint.tools import blacklist, memoize
from proselint.tools import existence_check, memoize


@memoize
def check(text):

"""Check the text."""
err = "MSC102"
msg = u"Don't put credit card numbers in plain text."

Expand All @@ -31,4 +31,4 @@ def check(text):
"6011\d{12}",
]

return blacklist(text, credit_card_numbers, err, msg)
return existence_check(text, credit_card_numbers, err, msg)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""MSC110: Symbols.
"""MSC110: Currency.
---
layout: post
Expand All @@ -14,17 +14,17 @@
Symbols.
"""
from proselint.tools import blacklist, memoize
from proselint.tools import existence_check, memoize


@memoize
def check(text):

"""Check the text."""
err = "MSC110"
msg = u"Incorrent use of symbols in {}."

symbols = [
"\$[\d]* ?(?:dollars|usd|us dollars)"
]

return blacklist(text, symbols, err, msg)
return existence_check(text, symbols, err, msg)
Loading

0 comments on commit 2672cb4

Please sign in to comment.