Skip to content

Commit

Permalink
Support .vintrc.yml and .vintrc
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuniwak committed Jul 30, 2016
1 parent 38c7682 commit ac4523a
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 9 deletions.
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
1 change: 1 addition & 0 deletions test/fixture/ast/fixture_to_parse_rare_syntax.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
if exists("l:last") | close | wincmd p | endif
File renamed without changes.
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

0 comments on commit ac4523a

Please sign in to comment.