Skip to content

Commit

Permalink
Appease the linter.
Browse files Browse the repository at this point in the history
  • Loading branch information
laraross committed Sep 28, 2015
1 parent 03bec7d commit 4b0c9a0
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 29 deletions.
9 changes: 4 additions & 5 deletions proselint/checks/dfw_uncomparables.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

def check(text):

error_code = "DFW200"
err = "DFW200"
msg = "Comparison of an uncomparable: {} is not comparable."

comparators = [
Expand All @@ -74,9 +74,8 @@ def check(text):
errors = []
for comp in comparators:
for uncomp in uncomparables:
occurrences = [m.start() for m in
re.finditer(comp + "\s" + uncomp, text.lower())]
for o in occurrences:
errors.append((1, o, error_code, msg.format(uncomp)))
occ = [m for m in re.finditer(comp + "\s" + uncomp, text.lower())]
for o in occ:
errors.append((m.start(), m.end(), err, msg.format(uncomp)))

return errors
14 changes: 7 additions & 7 deletions proselint/checks/mau_a_vs_an.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""MAU100: a vs. an
"""MAU100: Misuse of 'a' vs. 'an'.
---
layout: post
Expand All @@ -21,15 +21,15 @@

def check(text):

error_code = "MAU101"
err = "MAU101"
msg_a = "'a' should be 'an'."
msg_an = "'an' should be 'a'."

dic = cmudict.dict()

@memoize
def starts_with_vowel_sound(word):
"""Does the word start with a vowel sound?"""
"""Check whether the word starts with a vowel sound."""

# Get the pronunciations of the word.
pronunciations = dic.get(word)
Expand All @@ -51,8 +51,8 @@ def starts_with_vowel_sound(word):
regex = re.compile("(?:^|\W)(an?)\s+(\w+)", re.IGNORECASE)

# Find all occurences of the regex in the text.
for m in regex.finditer(text):
words = [group for group in m.groups()]
for g in regex.finditer(text):
words = [w for w in g.groups()]

vowel_sound = starts_with_vowel_sound(words[1])

Expand All @@ -61,10 +61,10 @@ def starts_with_vowel_sound(word):

# A apple.
if words[0] in ["A", "a"] and vowel_sound:
errors.append((g.start(), g.start()+1, error_code, msg_a))
errors.append((g.start(), g.start()+1, err, msg_a))

# An day.
elif words[0] in ["An", "an"] and not vowel_sound:
errors.append((g.start(), g.start()+2, error_code, msg_an))
errors.append((g.start(), g.start()+2, err, msg_an))

return errors
2 changes: 1 addition & 1 deletion proselint/checks/mau_abbetor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""MAU102: abbetor
"""MAU102: Preferred spelling is 'abbetor'.
---
layout: post
Expand Down
2 changes: 1 addition & 1 deletion proselint/checks/mau_abbreviable.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""MAU101: abbreviable
"""MAU101: Misspelling of 'abbreviable'.
---
layout: post
Expand Down
2 changes: 1 addition & 1 deletion proselint/checks/mau_academically.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""MAU102: academically
"""MAU102: Misspelling of 'academically'.
---
layout: post
Expand Down
4 changes: 2 additions & 2 deletions proselint/checks/mau_acquirer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""MAU102: acquirer
"""MAU102: Preferred spelling is 'acquirer'.
---
layout: post
Expand All @@ -11,7 +11,7 @@
categories: writing
---
acquirer. So spellednot *acquiror.
acquirer. So spelled---not *acquiror.
"""
from proselint.tools import supersede
Expand Down
4 changes: 2 additions & 2 deletions proselint/checks/mau_addable.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""MAU105: addable
"""MAU105: Misspelling of 'addable'.
---
layout: post
Expand All @@ -11,7 +11,7 @@
categories: writing
---
addable. So spellednot *addible. See - ABLE (A).
addable. So spelled---not *addible. See - ABLE (A).
"""
from proselint.tools import supersede
Expand Down
4 changes: 2 additions & 2 deletions proselint/checks/mau_adducible.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""MAU106: adducible
"""MAU106: Misspelling of 'adducible'.
---
layout: post
Expand All @@ -11,7 +11,7 @@
categories: writing
---
adducible. So spellednot *adduceable. See -ABLE (A).
adducible. So spelled---not *adduceable. See -ABLE (A).
"""
from proselint.tools import supersede
Expand Down
2 changes: 1 addition & 1 deletion proselint/checks/mau_tortfeasor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""MAU104: tortfeasor
"""MAU104: Incorrect hyphenation of tortfeasor.
---
layout: post
Expand Down
9 changes: 5 additions & 4 deletions proselint/checks/strunk_white_eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def check(text):
error_code = "STW100"
err = "STW100"
msg = "Use of '{}'. {}"

bad_words = [
Expand All @@ -36,8 +36,9 @@ def check(text):

errors = []
for word in bad_words:
occurrences = [m.start() for m in re.finditer(word, text.lower())]
for o in occurrences:
errors.append((1, o, error_code, msg.format(word, explanations[word])))
occ = [m for m in re.finditer(word, text.lower())]
for o in occ:
errors.append((m.start(), m.end(), err,
msg.format(word, explanations[word])))

return errors
8 changes: 5 additions & 3 deletions proselint/tools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""General-purpose tools shared across linting checks."""
import os
import shelve
import inspect
Expand All @@ -6,19 +7,20 @@


def supersede(new, old, error_code):
"""Replace one word with another."""
def check(text):
msg = "It's '{}', not '{}'.".format(new, old)
errors = []
for o in re.finditer(old, text, flags=re.IGNORECASE):
errors.append((o.start(), o.end(), error_code, msg))
for m in re.finditer(old, text, flags=re.IGNORECASE):
errors.append((m.start(), m.end(), error_code, msg))

return errors

return check


def memoize(f):

"""Cache results of computations on disk."""
cache_dirname = 'cached_func_calls'

if not os.path.isdir(cache_dirname):
Expand Down

0 comments on commit 4b0c9a0

Please sign in to comment.