From 3a71ed8e896f34793b8696ec3da34520436f83b0 Mon Sep 17 00:00:00 2001 From: Kuniwak Date: Sun, 31 Jul 2016 05:38:33 +0900 Subject: [PATCH] Support .vintrc.yml and .vintrc --- README.rst | 4 +- .../.vintrc.yaml | 0 .../config/project_with_no_extname/.vintrc | 13 +++++++ .../project_with_short_extname/.vintrc.yml | 13 +++++++ .../config/test_config_project_source.py | 38 ++++++++++++++++++- vint/linting/config/config_project_source.py | 15 +++++--- 6 files changed, 74 insertions(+), 9 deletions(-) rename test/fixture/config/{project => project_with_long_extname}/.vintrc.yaml (100%) create mode 100644 test/fixture/config/project_with_no_extname/.vintrc create mode 100644 test/fixture/config/project_with_short_extname/.vintrc.yml diff --git a/README.rst b/README.rst index cc1b346..ca9a16c 100644 --- a/README.rst +++ b/README.rst @@ -35,10 +35,10 @@ Configure Vint will read config files on the following priority order: - `User config <#user-config>`__: -- e.g. ``~/.vintrc.yaml`` +- e.g. ``~/.vintrc.yaml`` (the filename can be ``.vintrc.yml`` or ``.vintrc``) - `Project config <#project-config>`__: -- e.g. ``path/to/proj/.vintrc.yaml`` +- e.g. ``path/to/proj/.vintrc.yaml`` (the filename can be ``.vintrc.yml`` or ``.vintrc``) - `Command line config <#command-line-config>`__: - e.g. ``$ vint --error``, ``$ vint --max-violations 10`` diff --git a/test/fixture/config/project/.vintrc.yaml b/test/fixture/config/project_with_long_extname/.vintrc.yaml similarity index 100% rename from test/fixture/config/project/.vintrc.yaml rename to test/fixture/config/project_with_long_extname/.vintrc.yaml diff --git a/test/fixture/config/project_with_no_extname/.vintrc b/test/fixture/config/project_with_no_extname/.vintrc new file mode 100644 index 0000000..c85cb9b --- /dev/null +++ b/test/fixture/config/project_with_no_extname/.vintrc @@ -0,0 +1,13 @@ +cmdargs: + verbose: true + severity: warning + error-limit: 10 + + +policies: + ProhibitSomethingEvil: + # Some comments + enabled: false + + ProhibitSomethingDengerous: + enabled: true diff --git a/test/fixture/config/project_with_short_extname/.vintrc.yml b/test/fixture/config/project_with_short_extname/.vintrc.yml new file mode 100644 index 0000000..c85cb9b --- /dev/null +++ b/test/fixture/config/project_with_short_extname/.vintrc.yml @@ -0,0 +1,13 @@ +cmdargs: + verbose: true + severity: warning + error-limit: 10 + + +policies: + ProhibitSomethingEvil: + # Some comments + enabled: false + + ProhibitSomethingDengerous: + enabled: true diff --git a/test/unit/vint/linting/config/test_config_project_source.py b/test/unit/vint/linting/config/test_config_project_source.py index b6ac08b..b2306df 100644 --- a/test/unit/vint/linting/config/test_config_project_source.py +++ b/test/unit/vint/linting/config/test_config_project_source.py @@ -8,7 +8,7 @@ class TestConfigProjectSource(ConfigSourceAssertion, unittest.TestCase): def test_get_config_dict(self): env = { - 'cwd': get_fixture_path('project') + 'cwd': get_fixture_path('project_with_long_extname') } expected_type = { @@ -25,7 +25,41 @@ def test_get_config_dict(self): def test_get_config_dict_on_sub_directory(self): env = { - 'cwd': get_fixture_path(Path('project') / 'sub' / 'subsub') + 'cwd': get_fixture_path(Path('project_with_long_extname') / 'sub' / 'subsub') + } + + expected_type = { + 'cmdargs': { + 'verbose': bool, + 'error-limit': int, + 'severity': Enum, + } + } + + config_source = self.initialize_config_source_with_env(ConfigProjectSource, env) + self.assertConfigValueType(config_source, expected_type) + + + def test_get_config_dict_for_short_extname(self): + env = { + 'cwd': get_fixture_path('project_with_short_extname') + } + + expected_type = { + 'cmdargs': { + 'verbose': bool, + 'error-limit': int, + 'severity': Enum, + } + } + + config_source = self.initialize_config_source_with_env(ConfigProjectSource, env) + self.assertConfigValueType(config_source, expected_type) + + + def test_get_config_dict_for_no_extname(self): + env = { + 'cwd': get_fixture_path('project_with_no_extname') } expected_type = { diff --git a/vint/linting/config/config_project_source.py b/vint/linting/config/config_project_source.py index 75f5f8d..0869f9e 100644 --- a/vint/linting/config/config_project_source.py +++ b/vint/linting/config/config_project_source.py @@ -2,7 +2,11 @@ from vint.asset import get_asset_path from vint.linting.config.config_file_source import ConfigFileSource -PROJECT_CONFIG_FILENAME = '.vintrc.yaml' +PROJECT_CONFIG_FILENAMES = [ + '.vintrc.yaml', + '.vintrc.yml', + '.vintrc', +] VOID_CONFIG_PATH = get_asset_path('void_config.yaml') @@ -13,10 +17,11 @@ def get_file_path(self, env): path_list_to_search = [Path(env['cwd'])] + list(Path(env['cwd']).parents) for project_path in path_list_to_search: - proj_conf_path_tmp = project_path / PROJECT_CONFIG_FILENAME + for basename in PROJECT_CONFIG_FILENAMES: + proj_conf_path_tmp = project_path / basename - if proj_conf_path_tmp.is_file(): - proj_conf_path = proj_conf_path_tmp - break + if proj_conf_path_tmp.is_file(): + proj_conf_path = proj_conf_path_tmp + break return proj_conf_path