Skip to content

Commit

Permalink
refactor(tools): add fallbacks to load_options
Browse files Browse the repository at this point in the history
  • Loading branch information
Nytelife26 committed May 24, 2021
1 parent 93117cc commit 905ead6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 7 additions & 4 deletions proselint/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def get_checks(options):
return checks


def load_options(config_file_path=None):
def load_options(config_file_path=None, fallbacks=[]):
"""Read various proselintrc files, allowing user overrides."""
possible_defaults = (
'/etc/proselintrc',
Expand All @@ -176,8 +176,7 @@ def load_options(config_file_path=None):
# try to find a config file in the default locations,
# respecting environment variables
else:
for f in [os.path.join(_get_xdg_config_home(), 'proselint', 'config'),
os.path.join(home_dir, '.proselintrc')]:
for f in fallbacks:
if os.path.exists(f):
user_options = json.load(open(f))
has_overrides = True
Expand Down Expand Up @@ -226,7 +225,11 @@ def line_and_column(text, position):

def lint(input_file, debug=False, config_file_path=None):
"""Run the linter on the input file."""
options = load_options(config_file_path)
options = load_options(
config_file_path,
[os.path.join(_get_xdg_config_home(), 'proselint', 'config'),
os.path.join(home_dir, '.proselintrc')]
)

if isinstance(input_file, str):
text = input_file
Expand Down
7 changes: 7 additions & 0 deletions tests/test_config_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ def test_load_options_function():
overrides = load_options("tests/test_config_flag_proselintrc")
assert load_options()["checks"]["uncomparables.misc"]
assert not overrides["checks"]["uncomparables.misc"]


def test_load_fallbacks():
fallbacks = load_options(None, ["tests/test_config_flag_proselintrc"])
assert not fallbacks["checks"]["uncomparables.misc"]
fallbacks = load_options(None, ["./.proselintrc"])
assert fallbacks["checks"]["uncomparables.misc"]

0 comments on commit 905ead6

Please sign in to comment.