Skip to content

Commit

Permalink
config: Do no match directories that look like YAML files
Browse files Browse the repository at this point in the history
Fixes #279
  • Loading branch information
jsok authored Jul 10, 2020
1 parent 954fdd5 commit a221898
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def setUpClass(cls):
# file in dir
'sub/ok.yaml': '---\n'
'key: value\n',
# directory that looks like a yaml file
'sub/directory.yaml/not-yaml.txt': '',
'sub/directory.yaml/empty.yml': '',
# file in very nested dir
's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml': '---\n'
'key: value\n'
Expand Down Expand Up @@ -108,6 +111,7 @@ def test_find_files_recursively(self):
os.path.join(self.wd, 'dos.yml'),
os.path.join(self.wd, 'empty.yml'),
os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
os.path.join(self.wd, 'sub/directory.yaml/empty.yml'),
os.path.join(self.wd, 'sub/ok.yaml'),
os.path.join(self.wd, 'warn.yaml')],
)
Expand All @@ -132,6 +136,7 @@ def test_find_files_recursively(self):
self.assertEqual(
sorted(cli.find_files_recursively(items, conf)),
[os.path.join(self.wd, '/etc/another/file'),
os.path.join(self.wd, 'sub/directory.yaml/empty.yml'),
os.path.join(self.wd, 'sub/ok.yaml')],
)

Expand All @@ -152,7 +157,8 @@ def test_find_files_recursively(self):
self.assertEqual(
sorted(cli.find_files_recursively([self.wd], conf)),
[os.path.join(self.wd, 'dos.yml'),
os.path.join(self.wd, 'empty.yml')]
os.path.join(self.wd, 'empty.yml'),
os.path.join(self.wd, 'sub/directory.yaml/empty.yml')]
)

conf = config.YamlLintConfig('extends: default\n'
Expand All @@ -174,6 +180,8 @@ def test_find_files_recursively(self):
os.path.join(self.wd, 'no-yaml.json'),
os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8'),
os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
os.path.join(self.wd, 'sub/directory.yaml/empty.yml'),
os.path.join(self.wd, 'sub/directory.yaml/not-yaml.txt'),
os.path.join(self.wd, 'sub/ok.yaml'),
os.path.join(self.wd, 'warn.yaml')]
)
Expand All @@ -191,6 +199,8 @@ def test_find_files_recursively(self):
os.path.join(self.wd, 'no-yaml.json'),
os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8'),
os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
os.path.join(self.wd, 'sub/directory.yaml/empty.yml'),
os.path.join(self.wd, 'sub/directory.yaml/not-yaml.txt'),
os.path.join(self.wd, 'sub/ok.yaml'),
os.path.join(self.wd, 'warn.yaml')]
)
Expand Down
2 changes: 1 addition & 1 deletion yamllint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def is_file_ignored(self, filepath):
return self.ignore and self.ignore.match_file(filepath)

def is_yaml_file(self, filepath):
return self.yaml_files.match_file(filepath)
return self.yaml_files.match_file(os.path.basename(filepath))

def enabled_rules(self, filepath):
return [yamllint.rules.get(id) for id, val in self.rules.items()
Expand Down

0 comments on commit a221898

Please sign in to comment.