Skip to content
Open
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
23 changes: 23 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,13 +833,36 @@ def test_run_with_ignore_on_ignored_file(self):
' ignore: file-at-root.yaml\n')

sys.stdout = StringIO()
sys.stderr = StringIO()
with self.assertRaises(SystemExit):
cli.run(('-f', 'parsable', 'file.dont-lint-me.yaml',
'file-at-root.yaml'))
self.assertEqual(
sys.stdout.getvalue().strip(),
'file-at-root.yaml:4:17: [error] trailing spaces (trailing-spaces)'
)
self.assertIn('file.dont-lint-me.yaml', sys.stderr.getvalue())
self.assertIn('ignore list', sys.stderr.getvalue())
sys.stderr = sys.__stderr__

def test_run_with_ignore_on_ignored_dir(self):
path = os.path.join(self.wd, '.yamllint')
with open(path, 'w', encoding='utf_8') as f:
f.write('ignore: ign-dup\n'
'rules:\n'
' trailing-spaces: enable\n')

sys.stdout = StringIO()
sys.stderr = StringIO()
with self.assertRaises(SystemExit):
cli.run(('-f', 'parsable', 'ign-dup', 'file-at-root.yaml'))
self.assertEqual(
sys.stdout.getvalue().strip(),
'file-at-root.yaml:4:17: [error] trailing spaces (trailing-spaces)'
)
self.assertIn('ign-dup', sys.stderr.getvalue())
self.assertIn('ignore list', sys.stderr.getvalue())
sys.stderr = sys.__stderr__

def create_ignore_file(self, text, codec):
path = os.path.join(self.wd, f'{codec}.ignore')
Expand Down
10 changes: 8 additions & 2 deletions yamllint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@
def find_files_recursively(items, conf):
for item in items:
if os.path.isdir(item):
if conf.is_file_ignored(item):
print(f'warning: ignoring {item!r}: it is on the ignore list',
file=sys.stderr)
continue
for root, _dirnames, filenames in os.walk(item):
for f in filenames:
filepath = os.path.join(root, f)
if (conf.is_yaml_file(filepath) and
not conf.is_file_ignored(filepath)):
yield filepath
elif conf.is_file_ignored(item):
print(f'warning: ignoring {item!r}: it is on the ignore list',
file=sys.stderr)
else:
yield item

Expand Down Expand Up @@ -210,8 +217,7 @@ def run(argv=None):

if args.list_files:
for file in find_files_recursively(args.files, conf):
if not conf.is_file_ignored(file):
print(file)
print(file)
sys.exit(0)

max_level = 0
Expand Down