diff --git a/proselint/tools.py b/proselint/tools.py index 1525431ba..64eaa9e31 100644 --- a/proselint/tools.py +++ b/proselint/tools.py @@ -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', @@ -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 @@ -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 diff --git a/tests/test_config_flag.py b/tests/test_config_flag.py index 3a2233c6b..2f5ca25cf 100644 --- a/tests/test_config_flag.py +++ b/tests/test_config_flag.py @@ -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"]