Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support .vintrc.yml and .vintrc #172

Merged
merged 1 commit into from
Jul 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand Down
13 changes: 13 additions & 0 deletions test/fixture/config/project_with_no_extname/.vintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmdargs:
verbose: true
severity: warning
error-limit: 10


policies:
ProhibitSomethingEvil:
# Some comments
enabled: false

ProhibitSomethingDengerous:
enabled: true
13 changes: 13 additions & 0 deletions test/fixture/config/project_with_short_extname/.vintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmdargs:
verbose: true
severity: warning
error-limit: 10


policies:
ProhibitSomethingEvil:
# Some comments
enabled: false

ProhibitSomethingDengerous:
enabled: true
38 changes: 36 additions & 2 deletions test/unit/vint/linting/config/test_config_project_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand Down
15 changes: 10 additions & 5 deletions vint/linting/config/config_project_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')


Expand All @@ -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