| 1 |
"""Use of greylisted words. |
| 2 |
|
| 3 |
--- |
| 4 |
layout: post |
| 5 |
source: Strunk & White |
| 6 |
source_url: ??? |
| 7 |
title: Use of greylisted words |
| 8 |
date: 2014-06-10 12:31:19 |
| 9 |
categories: writing |
| 10 |
--- |
| 11 |
|
| 12 |
Strunk & White say: |
| 13 |
|
| 14 |
|
| 15 |
""" |
| 16 |
import re |
| 17 |
|
| 18 |
from proselint.tools import memoize |
| 19 |
|
| 20 |
|
| 21 |
@memoize |
| 22 |
def check(text): |
| 23 |
"""Check the text.""" |
| 24 |
err = "strunk_white.greylist" |
| 25 |
msg = "Use of '{}'. {}" |
| 26 |
|
| 27 |
bad_words = [ |
| 28 |
"obviously", |
| 29 |
"utilize" |
| 30 |
] |
| 31 |
|
| 32 |
explanations = { |
| 33 |
"obviously": |
| 34 |
"This is obviously an inadvisable word to use.", |
| 35 |
"utilize": |
| 36 |
r"Do you know anyone who *needs* to utilize the word utilize?" |
| 37 |
} |
| 38 |
|
| 39 |
errors = [] |
| 40 |
for word in bad_words: |
| 41 |
occ = [m for m in re.finditer(word, text.lower())] |
| 42 |
for o in occ: |
| 43 |
errors.append(( |
| 44 |
o.start(), |
| 45 |
o.end(), |
| 46 |
err, |
| 47 |
msg.format(word, explanations[word]), |
| 48 |
None)) |
| 49 |
|
| 50 |
return errors |