From e382965bb0ca875e5acfa00d30c8d259f9625292 Mon Sep 17 00:00:00 2001 From: Jordan Suchow Date: Wed, 18 Mar 2015 20:19:58 -0700 Subject: [PATCH] Create a .proselintrc file Closes #39 --- .proselintrc | 49 +++++++++++++++++++ ...ementary_composition.py => composition.py} | 0 .../{elementary_usage.py => usage.py} | 0 proselint/command_line.py | 17 +++++-- 4 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 .proselintrc rename proselint/checks/strunkwhite/{elementary_composition.py => composition.py} (100%) rename proselint/checks/strunkwhite/{elementary_usage.py => usage.py} (100%) diff --git a/.proselintrc b/.proselintrc new file mode 100644 index 000000000..336eccb0c --- /dev/null +++ b/.proselintrc @@ -0,0 +1,49 @@ +{ + "max_errors": 1000, + "checks": { + "garner.a_vs_an" : true, + "garner.airlinese" : true, + "garner.animal_labels" : true, + "garner.archaism" : true, + "garner.back_formations" : true, + "garner.cliches" : true, + "garner.commercialese" : true, + "garner.dates" : true, + "garner.denizen_labels" : true, + "garner.illogic" : true, + "garner.malaproprisms" : true, + "garner.misspelling" : true, + "garner.needless_variants" : true, + "garner.oxymorons" : true, + "garner.preferred_forms" : true, + "garner.punctuation" : true, + "garner.redundancy" : true, + "garner.sexism" : true, + "consistency.spacing" : true, + "consistency.spelling" : true, + "butterick.symbols" : true, + "misc.annotations" : true, + "misc.chatspeak" : true, + "misc.creditcard" : true, + "misc.currency" : true, + "misc.hyperbolic" : true, + "misc.linkchecker" : true, + "misc.password" : true, + "misc.yelling" : true, + "pinker.apologizing" : true, + "pinker.hedging" : true, + "pinker.latin" : true, + "pinker.metaconcepts" : true, + "pinker.narcisissm" : true, + "pinker.scare_quotes" : true, + "strunkwhite.composition" : true, + "strunkwhite.greylist" : true, + "strunkwhite.usage" : true, + "wallace.tense_present" : true, + "wallace.uncomparables" : true, + "wallstreetjournal.misspelling" : true, + "writegood.cliches" : true, + "writegood.lexical_illusions" : true, + "writegood.weasel_words" : true + } +} diff --git a/proselint/checks/strunkwhite/elementary_composition.py b/proselint/checks/strunkwhite/composition.py similarity index 100% rename from proselint/checks/strunkwhite/elementary_composition.py rename to proselint/checks/strunkwhite/composition.py diff --git a/proselint/checks/strunkwhite/elementary_usage.py b/proselint/checks/strunkwhite/usage.py similarity index 100% rename from proselint/checks/strunkwhite/elementary_usage.py rename to proselint/checks/strunkwhite/usage.py diff --git a/proselint/command_line.py b/proselint/command_line.py index cdf7a13e4..bb97b5d8b 100644 --- a/proselint/command_line.py +++ b/proselint/command_line.py @@ -13,6 +13,8 @@ import ntpath import re import textblob +import json +import importlib base_url = "prose.lifelinter.com/" @@ -43,23 +45,30 @@ def run_initialization(): def lint(path): """Run the linter on the file with the given path.""" - # Extract functions from the checks folder. + # Load the options. + options = json.load(open('.proselintrc')) + + # Extract the checks. checks = [] - for loader, module_name, is_pkg in pkgutil.walk_packages(pl.__path__): - module = loader.find_module(module_name).load_module(module_name) + check_names = [key for key, val in options["checks"].items() if val] + for check_name in check_names: + module = importlib.import_module("proselint.checks." + check_name) for d in dir(module): if re.match("check", d): checks.append(getattr(module, d)) # Apply all the checks. + errors = [] with codecs.open(path, "r", encoding='utf-8') as f: blob = textblob.TextBlob(f.read()) errors = [] for check in checks: errors += check(blob) + if len(errors) > options["max_errors"]: + break # Sort the errors by line and column number. - errors = sorted(errors) + errors = sorted(errors[:options["max_errors"]]) # Display the errors. for error in errors: