diff --git a/docs/configuration.rst b/docs/configuration.rst index 9aeecbe2..18258d03 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -136,6 +136,13 @@ directories, set ``yaml-files`` configuration option. The default is: The same rules as for ignoring paths apply (``.gitignore``-style path pattern, see below). +If you need to know the exact list of files that yamllint would process, +without really linting them, you can use ``--list-files``: + +.. code:: bash + + yamllint --list-files . + Ignoring paths -------------- @@ -220,6 +227,13 @@ or: .. note:: However, this is mutually exclusive with the ``ignore`` key. +If you need to know the exact list of files that yamllint would process, +without really linting them, you can use ``--list-files``: + +.. code:: bash + + yamllint --list-files . + Setting the locale ------------------ diff --git a/tests/test_cli.py b/tests/test_cli.py index 10d2a910..713a4909 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -678,6 +678,39 @@ def test_run_non_universal_newline(self): self.assertEqual( (ctx.returncode, ctx.stdout, ctx.stderr), (1, expected_out, '')) + def test_run_list_files(self): + with RunContext(self) as ctx: + cli.run(('--list-files', self.wd)) + self.assertEqual(ctx.returncode, 0) + self.assertEqual( + sorted(ctx.stdout.splitlines()), + [os.path.join(self.wd, 'a.yaml'), + os.path.join(self.wd, 'c.yaml'), + os.path.join(self.wd, 'dos.yml'), + os.path.join(self.wd, 'empty.yml'), + os.path.join(self.wd, 'en.yaml'), + 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')] + ) + + config = '{ignore: "*.yml", yaml-files: ["*.*"]}' + with RunContext(self) as ctx: + cli.run(('--list-files', '-d', config, self.wd)) + self.assertEqual(ctx.returncode, 0) + self.assertEqual( + sorted(ctx.stdout.splitlines()), + [os.path.join(self.wd, 'a.yaml'), + os.path.join(self.wd, 'c.yaml'), + os.path.join(self.wd, 'en.yaml'), + os.path.join(self.wd, 'no-yaml.json'), + 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/not-yaml.txt'), + os.path.join(self.wd, 'sub/ok.yaml'), + os.path.join(self.wd, 'warn.yaml')] + ) + class CommandLineConfigTestCase(unittest.TestCase): def test_config_file(self): diff --git a/yamllint/cli.py b/yamllint/cli.py index a9de634d..5574f1b4 100644 --- a/yamllint/cli.py +++ b/yamllint/cli.py @@ -157,6 +157,8 @@ def run(argv=None): config_group.add_argument('-d', '--config-data', dest='config_data', action='store', help='custom configuration (as YAML source)') + parser.add_argument('--list-files', action='store_true', dest='list_files', + help='list files to lint and exit') parser.add_argument('-f', '--format', choices=('parsable', 'standard', 'colored', 'github', 'auto'), @@ -207,6 +209,12 @@ def run(argv=None): if conf.locale is not None: locale.setlocale(locale.LC_ALL, conf.locale) + if args.list_files: + for file in find_files_recursively(args.files, conf): + if not conf.is_file_ignored(file): + print(file) + sys.exit(0) + max_level = 0 for file in find_files_recursively(args.files, conf):