From a2218988eee7e09968b3d2558663e6465a5157ab Mon Sep 17 00:00:00 2001 From: Jonathan Sokolowski Date: Fri, 10 Jul 2020 17:27:34 +1000 Subject: [PATCH] config: Do no match directories that look like YAML files Fixes #279 --- tests/test_cli.py | 12 +++++++++++- yamllint/config.py | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 1d28908..450507b 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -73,6 +73,9 @@ class CommandLineTestCase(unittest.TestCase): # 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' @@ -108,6 +111,7 @@ class CommandLineTestCase(unittest.TestCase): 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')], ) @@ -132,6 +136,7 @@ class CommandLineTestCase(unittest.TestCase): 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')], ) @@ -152,7 +157,8 @@ class CommandLineTestCase(unittest.TestCase): 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' @@ -174,6 +180,8 @@ class CommandLineTestCase(unittest.TestCase): 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')] ) @@ -191,6 +199,8 @@ class CommandLineTestCase(unittest.TestCase): 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')] ) diff --git a/yamllint/config.py b/yamllint/config.py index a955d8e..0abb242 100644 --- a/yamllint/config.py +++ b/yamllint/config.py @@ -46,7 +46,7 @@ class YamlLintConfig(object): 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()