From 930c8eea94614142daac00c24a9a5f51c8c43dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Sun, 7 Jul 2019 18:00:24 +0200 Subject: [PATCH 01/16] docs: Simplify installation instruction in the README --- README.rst | 32 +++++--------------------------- docs/quickstart.rst | 9 ++++++++- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/README.rst b/README.rst index 7f59956..0bebb78 100644 --- a/README.rst +++ b/README.rst @@ -38,38 +38,16 @@ Screenshot Installation ^^^^^^^^^^^^ -On Fedora / CentOS (note: `EPEL `_ is -required on CentOS): - -.. code:: bash - - sudo dnf install yamllint - -On Debian 8+ / Ubuntu 16.04+: - -.. code:: bash - - sudo apt-get install yamllint - -On FreeBSD: - -.. code:: sh - - pkg install py27-yamllint - pkg install py36-yamllint - -On Mac OS 10.11+: - -.. code:: bash - - brew install yamllint - -Alternatively using pip, the Python package manager: +Using pip, the Python package manager: .. code:: bash pip install --user yamllint +yamllint is also packaged for all major operating systems, see installation +examples (``dnf``, ``apt-get``...) `in the documentation +`_. + Usage ^^^^^ diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 427a9f3..8d959d6 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -4,7 +4,8 @@ Quickstart Installing yamllint ------------------- -On Fedora / CentOS: +On Fedora / CentOS (note: `EPEL `_ is +required on CentOS): .. code:: bash @@ -22,6 +23,12 @@ On Mac OS 10.11+: brew install yamllint +On FreeBSD: + +.. code:: sh + + pkg install py36-yamllint + Alternatively using pip, the Python package manager: .. code:: bash From cb5fe2c050f09aa5d29331aa1fec62306055c841 Mon Sep 17 00:00:00 2001 From: Remi Pointel Date: Tue, 9 Jul 2019 09:37:43 +0200 Subject: [PATCH 02/16] add OpenBSD installation instructions. --- docs/quickstart.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 8d959d6..9cf5f17 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -29,6 +29,12 @@ On FreeBSD: pkg install py36-yamllint +On OpenBSD: + +.. code:: sh + + doas pkg_add py3-yamllint + Alternatively using pip, the Python package manager: .. code:: bash From 673bdbd32446b161866f75bde47d9014676889aa Mon Sep 17 00:00:00 2001 From: xatier Date: Sun, 11 Aug 2019 05:50:11 -0700 Subject: [PATCH 03/16] fix(truthy): Fix extra whitespace --- yamllint/rules/truthy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yamllint/rules/truthy.py b/yamllint/rules/truthy.py index 3cf058b..7dd778f 100644 --- a/yamllint/rules/truthy.py +++ b/yamllint/rules/truthy.py @@ -101,7 +101,7 @@ from yamllint.linter import LintProblem TRUTHY = ['YES', 'Yes', 'yes', 'NO', 'No', 'no', - 'TRUE', 'True', 'true', + 'TRUE', 'True', 'true', 'FALSE', 'False', 'false', 'ON', 'On', 'on', 'OFF', 'Off', 'off'] From 063c854658d6ae4d92858c4ad231f57c9a256e9f Mon Sep 17 00:00:00 2001 From: grzesuav Date: Fri, 19 Jul 2019 18:28:34 +0200 Subject: [PATCH 04/16] feat: Make YAML file extensions configurable --- docs/configuration.rst | 15 ++++++++ tests/test_cli.py | 76 ++++++++++++++++++++++++++++++++++++-- yamllint/cli.py | 11 +++--- yamllint/conf/default.yaml | 4 ++ yamllint/config.py | 15 ++++++++ 5 files changed, 112 insertions(+), 9 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 817a16d..f7f8ffa 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -115,6 +115,21 @@ return code will be: * ``1`` if one or more errors occur * ``2`` if no errors occur, but one or more warnings occur +YAML files extensions +--------------------- + +To configure what yamllint should consider as YAML files, set ``yaml-files`` +configuration option. The default is: + +.. code-block:: yaml + + yaml-files: + - '*.yaml' + - '*.yml' + +The same rules as for ignoring paths apply (``.gitignore``-style path pattern, +see below). + Ignoring paths -------------- diff --git a/tests/test_cli.py b/tests/test_cli.py index b5ef82a..fbdf75f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -29,6 +29,7 @@ import unittest from tests.common import build_temp_workspace from yamllint import cli +from yamllint import config class CommandLineTestCase(unittest.TestCase): @@ -73,8 +74,9 @@ class CommandLineTestCase(unittest.TestCase): shutil.rmtree(cls.wd) def test_find_files_recursively(self): + conf = config.YamlLintConfig('extends: default') self.assertEqual( - sorted(cli.find_files_recursively([self.wd])), + sorted(cli.find_files_recursively([self.wd], conf)), [os.path.join(self.wd, 'a.yaml'), 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'), @@ -85,14 +87,14 @@ class CommandLineTestCase(unittest.TestCase): items = [os.path.join(self.wd, 'sub/ok.yaml'), os.path.join(self.wd, 'empty-dir')] self.assertEqual( - sorted(cli.find_files_recursively(items)), + sorted(cli.find_files_recursively(items, conf)), [os.path.join(self.wd, 'sub/ok.yaml')], ) items = [os.path.join(self.wd, 'empty.yml'), os.path.join(self.wd, 's')] self.assertEqual( - sorted(cli.find_files_recursively(items)), + sorted(cli.find_files_recursively(items, conf)), [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')], ) @@ -100,11 +102,77 @@ class CommandLineTestCase(unittest.TestCase): items = [os.path.join(self.wd, 'sub'), os.path.join(self.wd, '/etc/another/file')] self.assertEqual( - sorted(cli.find_files_recursively(items)), + sorted(cli.find_files_recursively(items, conf)), [os.path.join(self.wd, '/etc/another/file'), os.path.join(self.wd, 'sub/ok.yaml')], ) + conf = config.YamlLintConfig('extends: default\n' + 'yaml-files:\n' + ' - \'*.yaml\' \n') + self.assertEqual( + sorted(cli.find_files_recursively([self.wd], conf)), + [os.path.join(self.wd, 'a.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/ok.yaml'), + os.path.join(self.wd, 'warn.yaml')] + ) + + conf = config.YamlLintConfig('extends: default\n' + 'yaml-files:\n' + ' - \'*.yml\'\n') + self.assertEqual( + sorted(cli.find_files_recursively([self.wd], conf)), + [os.path.join(self.wd, 'empty.yml')] + ) + + conf = config.YamlLintConfig('extends: default\n' + 'yaml-files:\n' + ' - \'*.json\'\n') + self.assertEqual( + sorted(cli.find_files_recursively([self.wd], conf)), + [os.path.join(self.wd, 'no-yaml.json')] + ) + + conf = config.YamlLintConfig('extends: default\n' + 'yaml-files:\n' + ' - \'*\'\n') + self.assertEqual( + sorted(cli.find_files_recursively([self.wd], conf)), + [os.path.join(self.wd, 'a.yaml'), + os.path.join(self.wd, 'empty.yml'), + 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/ok.yaml'), + os.path.join(self.wd, 'warn.yaml')] + ) + + conf = config.YamlLintConfig('extends: default\n' + 'yaml-files:\n' + ' - \'*.yaml\'\n' + ' - \'*\'\n' + ' - \'**\'\n') + self.assertEqual( + sorted(cli.find_files_recursively([self.wd], conf)), + [os.path.join(self.wd, 'a.yaml'), + os.path.join(self.wd, 'empty.yml'), + 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/ok.yaml'), + os.path.join(self.wd, 'warn.yaml')] + ) + + conf = config.YamlLintConfig('extends: default\n' + 'yaml-files:\n' + ' - \'s/**\'\n' + ' - \'**/utf-8\'\n') + self.assertEqual( + sorted(cli.find_files_recursively([self.wd], conf)), + [os.path.join(self.wd, 'non-ascii/utf-8')] + ) + def test_run_with_bad_arguments(self): sys.stdout, sys.stderr = StringIO(), StringIO() with self.assertRaises(SystemExit) as ctx: diff --git a/yamllint/cli.py b/yamllint/cli.py index 9975b4e..d8f4927 100644 --- a/yamllint/cli.py +++ b/yamllint/cli.py @@ -27,13 +27,14 @@ from yamllint.config import YamlLintConfig, YamlLintConfigError from yamllint.linter import PROBLEM_LEVELS -def find_files_recursively(items): +def find_files_recursively(items, conf): for item in items: if os.path.isdir(item): for root, dirnames, filenames in os.walk(item): - for filename in [f for f in filenames - if f.endswith(('.yml', '.yaml'))]: - yield os.path.join(root, filename) + for f in filenames: + filepath = os.path.join(root, f) + if conf.is_yaml_file(filepath): + yield filepath else: yield item @@ -163,7 +164,7 @@ def run(argv=None): max_level = 0 - for file in find_files_recursively(args.files): + for file in find_files_recursively(args.files, conf): filepath = file[2:] if file.startswith('./') else file try: with open(file) as f: diff --git a/yamllint/conf/default.yaml b/yamllint/conf/default.yaml index da9701e..f0c1edd 100644 --- a/yamllint/conf/default.yaml +++ b/yamllint/conf/default.yaml @@ -1,5 +1,9 @@ --- +yaml-files: + - '*.yaml' + - '*.yml' + rules: braces: enable brackets: enable diff --git a/yamllint/config.py b/yamllint/config.py index 2cafe8a..a9384d6 100644 --- a/yamllint/config.py +++ b/yamllint/config.py @@ -32,6 +32,9 @@ class YamlLintConfig(object): self.ignore = None + self.yaml_files = pathspec.PathSpec.from_lines( + 'gitwildmatch', ['*.yaml', '*.yml']) + if file is not None: with open(file) as f: content = f.read() @@ -42,6 +45,9 @@ class YamlLintConfig(object): 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) + def enabled_rules(self, filepath): return [yamllint.rules.get(id) for id, val in self.rules.items() if val is not False and ( @@ -96,6 +102,15 @@ class YamlLintConfig(object): self.ignore = pathspec.PathSpec.from_lines( 'gitwildmatch', conf['ignore'].splitlines()) + if 'yaml-files' in conf: + if not (isinstance(conf['yaml-files'], list) + and all(isinstance(i, str) for i in conf['yaml-files'])): + raise YamlLintConfigError( + 'invalid config: yaml-files ' + 'should be a list of file patterns') + self.yaml_files = pathspec.PathSpec.from_lines('gitwildmatch', + conf['yaml-files']) + def validate(self): for id in self.rules: try: From ce0336e4306f2da19b71a161499e6fa9d03a388f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Mon, 12 Aug 2019 16:54:51 +0200 Subject: [PATCH 05/16] yamllint version 1.17.0 --- CHANGELOG.rst | 7 +++++++ yamllint/__init__.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 105fccd..39d1773 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,13 @@ Changelog ========= +1.17.0 (2019-08-12) +------------------- + +- Simplify installation instructions in the README +- Add OpenBSD installation instructions +- Make YAML file extensions configurable + 1.16.0 (2019-06-07) ------------------- diff --git a/yamllint/__init__.py b/yamllint/__init__.py index 932054e..12be7f1 100644 --- a/yamllint/__init__.py +++ b/yamllint/__init__.py @@ -22,7 +22,7 @@ indentation, etc.""" APP_NAME = 'yamllint' -APP_VERSION = '1.16.0' +APP_VERSION = '1.17.0' APP_DESCRIPTION = __doc__ __author__ = u'Adrien Vergé' From b62b424dd43acd4b0e08f46f49d88bc15461384e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Mon, 26 Aug 2019 09:36:55 +0200 Subject: [PATCH 06/16] feat: Lint .yamllint by default --- docs/configuration.rst | 1 + tests/test_config.py | 2 ++ yamllint/conf/default.yaml | 1 + yamllint/config.py | 2 +- 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index f7f8ffa..8ae3cc8 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -126,6 +126,7 @@ configuration option. The default is: yaml-files: - '*.yaml' - '*.yml' + - '.yamllint' The same rules as for ignoring paths apply (``.gitignore``-style path pattern, see below). diff --git a/tests/test_config.py b/tests/test_config.py index d676382..b48546c 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -448,11 +448,13 @@ class IgnorePathConfigTestCase(unittest.TestCase): out = sys.stdout.getvalue() out = '\n'.join(sorted(out.splitlines())) + docstart = '[warning] missing document start "---" (document-start)' keydup = '[error] duplication of key "key" in mapping (key-duplicates)' trailing = '[error] trailing spaces (trailing-spaces)' hyphen = '[error] too many spaces after hyphen (hyphens)' self.assertEqual(out, '\n'.join(( + './.yamllint:1:1: ' + docstart, './bin/file.lint-me-anyway.yaml:3:3: ' + keydup, './bin/file.lint-me-anyway.yaml:4:17: ' + trailing, './bin/file.lint-me-anyway.yaml:5:5: ' + hyphen, diff --git a/yamllint/conf/default.yaml b/yamllint/conf/default.yaml index f0c1edd..dc4adf1 100644 --- a/yamllint/conf/default.yaml +++ b/yamllint/conf/default.yaml @@ -3,6 +3,7 @@ yaml-files: - '*.yaml' - '*.yml' + - '.yamllint' rules: braces: enable diff --git a/yamllint/config.py b/yamllint/config.py index a9384d6..0837799 100644 --- a/yamllint/config.py +++ b/yamllint/config.py @@ -33,7 +33,7 @@ class YamlLintConfig(object): self.ignore = None self.yaml_files = pathspec.PathSpec.from_lines( - 'gitwildmatch', ['*.yaml', '*.yml']) + 'gitwildmatch', ['*.yaml', '*.yml', '.yamllint']) if file is not None: with open(file) as f: From 881d30188343287ad2684ce45dadad4e7738aa61 Mon Sep 17 00:00:00 2001 From: Ibrahim AshShohail Date: Sun, 25 Aug 2019 20:11:42 +0300 Subject: [PATCH 07/16] feat: Support reading config from .yamllint.yml and .yamllint.yaml Signed-off-by: Ibrahim AshShohail --- docs/configuration.rst | 3 ++- yamllint/cli.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 8ae3cc8..5e00169 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -14,7 +14,8 @@ To use a custom configuration file, use the ``-c`` option: If ``-c`` is not provided, yamllint will look for a configuration file in the following locations (by order of preference): -- ``.yamllint`` in the current working directory +- ``.yamllint``, ``.yamllint.yaml`` or ``.yamllint.yml`` in the current working + directory - ``$XDG_CONFIG_HOME/yamllint/config`` - ``~/.config/yamllint/config`` diff --git a/yamllint/cli.py b/yamllint/cli.py index d8f4927..0ffaae4 100644 --- a/yamllint/cli.py +++ b/yamllint/cli.py @@ -154,6 +154,10 @@ def run(argv=None): conf = YamlLintConfig(file=args.config_file) elif os.path.isfile('.yamllint'): conf = YamlLintConfig(file='.yamllint') + elif os.path.isfile('.yamllint.yaml'): + conf = YamlLintConfig(file='.yamllint.yaml') + elif os.path.isfile('.yamllint.yml'): + conf = YamlLintConfig(file='.yamllint.yml') elif os.path.isfile(user_global_config): conf = YamlLintConfig(file=user_global_config) else: From f3d9196aa05763b46fc5e62732b324bf04c4e478 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Mon, 9 Sep 2019 22:53:03 +0100 Subject: [PATCH 08/16] docs(configuration): improve `yaml-files` code example * A straight copy/paste of the existing example into the `.yamllint` file results in a `yamllint` error! --- docs/configuration.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 5e00169..866208e 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -125,9 +125,9 @@ configuration option. The default is: .. code-block:: yaml yaml-files: - - '*.yaml' - - '*.yml' - - '.yamllint' + - '*.yaml' + - '*.yml' + - '.yamllint' The same rules as for ignoring paths apply (``.gitignore``-style path pattern, see below). From 579a975b7056f15e5a5a88cbe9fda9bdd6dccaae Mon Sep 17 00:00:00 2001 From: Hossein Zolfi Date: Tue, 1 Oct 2019 12:00:33 +0330 Subject: [PATCH 09/16] docs: Fix pre-commit config file * pre-commit show warning for unsupported key (sha) * Demonstrate how to use custom yamllint --- docs/integration.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/integration.rst b/docs/integration.rst index da67d7f..3457556 100644 --- a/docs/integration.rst +++ b/docs/integration.rst @@ -10,8 +10,10 @@ Here is an example, to add in your .pre-commit-config.yaml .. code:: yaml --- - # Update the sha variable with the release version that you want, from the yamllint repo + # Update the rev variable with the release version that you want, from the yamllint repo + # You can pass your custom .yamllint with args attribute. - repo: https://github.com/adrienverge/yamllint.git - sha: v1.8.1 + rev: v1.17.0 hooks: - id: yamllint + args: [-c=/path/to/.yamllint] From 7359785ea07e117a923a7debb92376192ed633e9 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Thu, 10 Oct 2019 23:40:07 +0100 Subject: [PATCH 10/16] fix(default.yaml): disable `empty-values` & `octal-values` by default * Close #204 --- tests/rules/test_octal_values.py | 8 ++++++-- yamllint/conf/default.yaml | 4 ++-- yamllint/rules/empty_values.py | 4 ++-- yamllint/rules/octal_values.py | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/rules/test_octal_values.py b/tests/rules/test_octal_values.py index 7e82d4e..f2d9a2b 100644 --- a/tests/rules/test_octal_values.py +++ b/tests/rules/test_octal_values.py @@ -28,7 +28,9 @@ class OctalValuesTestCase(RuleTestCase): self.check('user-city: 0o10', conf) def test_implicit_octal_values(self): - conf = ('octal-values: {forbid-implicit-octal: true}\n' + conf = ('octal-values:\n' + ' forbid-implicit-octal: true\n' + ' forbid-explicit-octal: false\n' 'new-line-at-end-of-file: disable\n' 'document-start: disable\n') self.check('user-city: 010', conf, problem=(1, 15)) @@ -50,7 +52,9 @@ class OctalValuesTestCase(RuleTestCase): ' - 0e3\n', conf) def test_explicit_octal_values(self): - conf = ('octal-values: {forbid-explicit-octal: true}\n' + conf = ('octal-values:\n' + ' forbid-implicit-octal: false\n' + ' forbid-explicit-octal: true\n' 'new-line-at-end-of-file: disable\n' 'document-start: disable\n') self.check('user-city: 0o10', conf, problem=(1, 16)) diff --git a/yamllint/conf/default.yaml b/yamllint/conf/default.yaml index dc4adf1..0720ded 100644 --- a/yamllint/conf/default.yaml +++ b/yamllint/conf/default.yaml @@ -18,7 +18,7 @@ rules: document-start: level: warning empty-lines: enable - empty-values: enable + empty-values: disable hyphens: enable indentation: enable key-duplicates: enable @@ -26,7 +26,7 @@ rules: line-length: enable new-line-at-end-of-file: enable new-lines: enable - octal-values: enable + octal-values: disable quoted-strings: disable trailing-spaces: enable truthy: diff --git a/yamllint/rules/empty_values.py b/yamllint/rules/empty_values.py index 14bd0e0..bb4982b 100644 --- a/yamllint/rules/empty_values.py +++ b/yamllint/rules/empty_values.py @@ -75,8 +75,8 @@ ID = 'empty-values' TYPE = 'token' CONF = {'forbid-in-block-mappings': bool, 'forbid-in-flow-mappings': bool} -DEFAULT = {'forbid-in-block-mappings': False, - 'forbid-in-flow-mappings': False} +DEFAULT = {'forbid-in-block-mappings': True, + 'forbid-in-flow-mappings': True} def check(conf, token, prev, next, nextnext, context): diff --git a/yamllint/rules/octal_values.py b/yamllint/rules/octal_values.py index 40de39a..f6e80ce 100644 --- a/yamllint/rules/octal_values.py +++ b/yamllint/rules/octal_values.py @@ -66,8 +66,8 @@ ID = 'octal-values' TYPE = 'token' CONF = {'forbid-implicit-octal': bool, 'forbid-explicit-octal': bool} -DEFAULT = {'forbid-implicit-octal': False, - 'forbid-explicit-octal': False} +DEFAULT = {'forbid-implicit-octal': True, + 'forbid-explicit-octal': True} def check(conf, token, prev, next, nextnext, context): From 92324ae7306f6f4d228af90a42a2d7a95500fdbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Tue, 15 Oct 2019 09:49:20 +0200 Subject: [PATCH 11/16] yamllint version 1.18.0 --- CHANGELOG.rst | 9 +++++++++ yamllint/__init__.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 39d1773..1f75863 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,15 @@ Changelog ========= +1.18.0 (2019-10-15) +------------------- + +- Lint ``.yamllint`` config file by default +- Also read config from ``.yamllint.yml`` and ``.yamllint.yaml`` +- Improve documentation for ``yaml-files`` +- Update documentation for ``pre-commit`` +- Explicitly disable ``empty-values`` and ``octal-values`` rules + 1.17.0 (2019-08-12) ------------------- diff --git a/yamllint/__init__.py b/yamllint/__init__.py index 12be7f1..263b73e 100644 --- a/yamllint/__init__.py +++ b/yamllint/__init__.py @@ -22,7 +22,7 @@ indentation, etc.""" APP_NAME = 'yamllint' -APP_VERSION = '1.17.0' +APP_VERSION = '1.18.0' APP_DESCRIPTION = __doc__ __author__ = u'Adrien Vergé' From fb400dc64b00a2c5769ce951d85fcdd5de955ce8 Mon Sep 17 00:00:00 2001 From: Joel Baranick Date: Wed, 13 Nov 2019 23:32:36 -0800 Subject: [PATCH 12/16] Allow disabling all checks for a file Allow disabling of a file, even if it is invalid YAML (syntax error) by including `# yamllint disable-file` in the first line. --- docs/disable_with_comments.rst | 28 +++++++++ tests/test_yamllint_directives.py | 101 ++++++++++++++++++++++++++++++ yamllint/linter.py | 4 ++ 3 files changed, 133 insertions(+) diff --git a/docs/disable_with_comments.rst b/docs/disable_with_comments.rst index d50a372..40219f2 100644 --- a/docs/disable_with_comments.rst +++ b/docs/disable_with_comments.rst @@ -73,3 +73,31 @@ It is possible, although not recommend, to disabled **all** rules: If you need to disable multiple rules, it is allowed to chain rules like this: ``# yamllint disable rule:hyphens rule:commas rule:indentation``. + +Disabling all checks for a file +------------------------------- + +To prevent yamllint from reporting problems for a specific file, add the +directive comment ``# yamllint disable-file`` as the first line of the file. +For instance: + +.. code-block:: yaml + + # yamllint disable-file + # The following mapping contains the same key twice, but I know what I'm doing: + key: value 1 + key: value 2 + + - This line is waaaaaaaaaay too long but yamllint will not report anything about it. + This line will be checked by yamllint. + +or: + +.. code-block:: jinja + + # yamllint disable-file + # This file is not valid YAML because it is a Jinja template + {% if extra_info %} + key1: value1 + {% endif %} + key2: value2 diff --git a/tests/test_yamllint_directives.py b/tests/test_yamllint_directives.py index 8c6e865..17bb69e 100644 --- a/tests/test_yamllint_directives.py +++ b/tests/test_yamllint_directives.py @@ -302,3 +302,104 @@ class YamllintDirectivesTestCase(RuleTestCase): ' c: [x]\n', conf, problem=(6, 2, 'comments-indentation')) + + def test_disable_file_directive(self): + conf = ('comments: {min-spaces-from-content: 2}\n' + 'comments-indentation: {}\n') + self.check('# yamllint disable-file\n' + '---\n' + '- a: 1 # comment too close\n' + ' b:\n' + ' # wrong indentation\n' + ' c: [x]\n', + conf) + self.check('# yamllint disable-file\n' + '---\n' + '- a: 1 # comment too close\n' + ' b:\n' + ' # wrong indentation\n' + ' c: [x]\n', + conf) + self.check('#yamllint disable-file\n' + '---\n' + '- a: 1 # comment too close\n' + ' b:\n' + ' # wrong indentation\n' + ' c: [x]\n', + conf) + self.check('#yamllint disable-file \n' + '---\n' + '- a: 1 # comment too close\n' + ' b:\n' + ' # wrong indentation\n' + ' c: [x]\n', + conf) + self.check('---\n' + '# yamllint disable-file\n' + '- a: 1 # comment too close\n' + ' b:\n' + ' # wrong indentation\n' + ' c: [x]\n', + conf, + problem1=(3, 8, 'comments'), + problem2=(5, 2, 'comments-indentation')) + self.check('# yamllint disable-file: rules cannot be specified\n' + '---\n' + '- a: 1 # comment too close\n' + ' b:\n' + ' # wrong indentation\n' + ' c: [x]\n', + conf, + problem1=(3, 8, 'comments'), + problem2=(5, 2, 'comments-indentation')) + self.check('AAAA yamllint disable-file\n' + '---\n' + '- a: 1 # comment too close\n' + ' b:\n' + ' # wrong indentation\n' + ' c: [x]\n', + conf, + problem1=(1, 1, 'document-start'), + problem2=(3, 8, 'comments'), + problem3=(5, 2, 'comments-indentation')) + + def test_disable_file_directive_not_at_first_position(self): + self.check('# yamllint disable-file\n' + '---\n' + '- bad : colon and spaces \n', + self.conf) + self.check('---\n' + '# yamllint disable-file\n' + '- bad : colon and spaces \n', + self.conf, + problem1=(3, 7, 'colons'), + problem2=(3, 26, 'trailing-spaces')) + + def test_disable_file_directive_with_syntax_error(self): + self.check('# This file is not valid YAML (it is a Jinja template)\n' + '{% if extra_info %}\n' + 'key1: value1\n' + '{% endif %}\n' + 'key2: value2\n', + self.conf, + problem=(2, 2, 'syntax')) + self.check('# yamllint disable-file\n' + '# This file is not valid YAML (it is a Jinja template)\n' + '{% if extra_info %}\n' + 'key1: value1\n' + '{% endif %}\n' + 'key2: value2\n', + self.conf) + + def test_disable_file_directive_with_dos_lines(self): + self.check('# yamllint disable-file\r\n' + '---\r\n' + '- bad : colon and spaces \r\n', + self.conf) + self.check('# yamllint disable-file\r\n' + '# This file is not valid YAML (it is a Jinja template)\r\n' + '{% if extra_info %}\r\n' + 'key1: value1\r\n' + '{% endif %}\r\n' + 'key2: value2\r\n', + self.conf) diff --git a/yamllint/linter.py b/yamllint/linter.py index ab46dca..fdb3bef 100644 --- a/yamllint/linter.py +++ b/yamllint/linter.py @@ -189,6 +189,10 @@ def _run(buffer, conf, filepath): assert hasattr(buffer, '__getitem__'), \ '_run() argument must be a buffer, not a stream' + first_line = next(parser.line_generator(buffer)).content + if re.match(r'^#\s*yamllint disable-file\s*$', first_line): + return + # If the document contains a syntax error, save it and yield it at the # right line syntax_error = get_syntax_error(buffer) From da3788e95ac50c5463bdcde29c2200ed3854d0d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Tue, 19 Nov 2019 11:28:21 +0100 Subject: [PATCH 13/16] yamllint version 1.19.0 --- CHANGELOG.rst | 5 +++++ yamllint/__init__.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1f75863..0650935 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,11 @@ Changelog ========= +1.19.0 (2019-11-19) +------------------- + +- Allow disabling all checks for a file with ``# yamllint disable-file`` + 1.18.0 (2019-10-15) ------------------- diff --git a/yamllint/__init__.py b/yamllint/__init__.py index 263b73e..9d79116 100644 --- a/yamllint/__init__.py +++ b/yamllint/__init__.py @@ -22,7 +22,7 @@ indentation, etc.""" APP_NAME = 'yamllint' -APP_VERSION = '1.18.0' +APP_VERSION = '1.19.0' APP_DESCRIPTION = __doc__ __author__ = u'Adrien Vergé' From 8fa9eb3cede0b2f36bdf5c34a8912085244ed74b Mon Sep 17 00:00:00 2001 From: ffapitalle Date: Thu, 12 Dec 2019 05:12:53 -0300 Subject: [PATCH 14/16] Add --no-warnings option to suppress warning messages Use `--no-warnings` option to hide warning messages. It only shows problems marked as errors. --- docs/configuration.rst | 3 +++ tests/test_cli.py | 35 +++++++++++++++++++++++++++++++++++ yamllint/cli.py | 15 +++++++++++---- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 866208e..0322ad3 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -116,6 +116,9 @@ return code will be: * ``1`` if one or more errors occur * ``2`` if no errors occur, but one or more warnings occur +If the script is invoked with the ``--no-warnings`` option, it won't output +warning level problems, only error level ones. + YAML files extensions --------------------- diff --git a/tests/test_cli.py b/tests/test_cli.py index fbdf75f..014cf8f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -532,3 +532,38 @@ class CommandLineTestCase(unittest.TestCase): 'stdin:2:10: [error] syntax error: ' 'mapping values are not allowed here\n')) self.assertEqual(err, '') + + def test_run_no_warnings(self): + file = os.path.join(self.wd, 'a.yaml') + + sys.stdout, sys.stderr = StringIO(), StringIO() + with self.assertRaises(SystemExit) as ctx: + cli.run((file, '--no-warnings', '-f', 'auto')) + + self.assertEqual(ctx.exception.code, 1) + + out, err = sys.stdout.getvalue(), sys.stderr.getvalue() + self.assertEqual(out, ( + '%s\n' + ' 2:4 error trailing spaces (trailing-spaces)\n' + ' 3:4 error no new line character at the end of file ' + '(new-line-at-end-of-file)\n' + '\n' % file)) + self.assertEqual(err, '') + + file = os.path.join(self.wd, 'warn.yaml') + + sys.stdout, sys.stderr = StringIO(), StringIO() + with self.assertRaises(SystemExit) as ctx: + cli.run((file, '--no-warnings', '-f', 'auto')) + + self.assertEqual(ctx.exception.code, 0) + + def test_run_no_warnings_and_strict(self): + file = os.path.join(self.wd, 'warn.yaml') + + sys.stdout, sys.stderr = StringIO(), StringIO() + with self.assertRaises(SystemExit) as ctx: + cli.run((file, '--no-warnings', '-s')) + + self.assertEqual(ctx.exception.code, 2) diff --git a/yamllint/cli.py b/yamllint/cli.py index 0ffaae4..26bdb1f 100644 --- a/yamllint/cli.py +++ b/yamllint/cli.py @@ -84,11 +84,14 @@ class Format(object): return line -def show_problems(problems, file, args_format): +def show_problems(problems, file, args_format, no_warn): max_level = 0 first = True for problem in problems: + max_level = max(max_level, PROBLEM_LEVELS[problem.level]) + if no_warn and (problem.level != 'error'): + continue if args_format == 'parsable': print(Format.parsable(problem, file)) elif args_format == 'colored' or \ @@ -102,7 +105,6 @@ def show_problems(problems, file, args_format): print(file) first = False print(Format.standard(problem, file)) - max_level = max(max_level, PROBLEM_LEVELS[problem.level]) if not first and args_format != 'parsable': print('') @@ -133,6 +135,9 @@ def run(argv=None): action='store_true', help='return non-zero exit code on warnings ' 'as well as errors') + parser.add_argument('--no-warnings', + action='store_true', + help='output only error level problems') parser.add_argument('-v', '--version', action='version', version='{} {}'.format(APP_NAME, APP_VERSION)) @@ -176,7 +181,8 @@ def run(argv=None): except EnvironmentError as e: print(e, file=sys.stderr) sys.exit(-1) - prob_level = show_problems(problems, file, args_format=args.format) + prob_level = show_problems(problems, file, args_format=args.format, + no_warn=args.no_warnings) max_level = max(max_level, prob_level) # read yaml from stdin @@ -186,7 +192,8 @@ def run(argv=None): except EnvironmentError as e: print(e, file=sys.stderr) sys.exit(-1) - prob_level = show_problems(problems, 'stdin', args_format=args.format) + prob_level = show_problems(problems, 'stdin', args_format=args.format, + no_warn=args.no_warnings) max_level = max(max_level, prob_level) if max_level == PROBLEM_LEVELS['error']: From 43b95e99d1eadd0c1eb74ad82defd8ba7248f010 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 17 Dec 2019 19:29:49 +0100 Subject: [PATCH 15/16] Use 'syntax' as rule name upon syntax errors --- tests/test_cli.py | 2 +- yamllint/linter.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 014cf8f..4244dc8 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -530,7 +530,7 @@ class CommandLineTestCase(unittest.TestCase): out, err = sys.stdout.getvalue(), sys.stderr.getvalue() self.assertEqual(out, ( 'stdin:2:10: [error] syntax error: ' - 'mapping values are not allowed here\n')) + 'mapping values are not allowed here (syntax)\n')) self.assertEqual(err, '') def test_run_no_warnings(self): diff --git a/yamllint/linter.py b/yamllint/linter.py index fdb3bef..c687f14 100644 --- a/yamllint/linter.py +++ b/yamllint/linter.py @@ -180,7 +180,7 @@ def get_syntax_error(buffer): except yaml.error.MarkedYAMLError as e: problem = LintProblem(e.problem_mark.line + 1, e.problem_mark.column + 1, - 'syntax error: ' + e.problem) + 'syntax error: ' + e.problem + ' (syntax)') problem.level = 'error' return problem From 13a0f11e7c92e8295b5e52d637f7d4c29d2f23b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Thu, 26 Dec 2019 16:06:29 +0100 Subject: [PATCH 16/16] yamllint version 1.20.0 --- CHANGELOG.rst | 6 ++++++ yamllint/__init__.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0650935..119917f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,12 @@ Changelog ========= +1.20.0 (2019-12-26) +------------------- + +- Add --no-warnings option to suppress warning messages +- Use 'syntax' as rule name upon syntax errors + 1.19.0 (2019-11-19) ------------------- diff --git a/yamllint/__init__.py b/yamllint/__init__.py index 9d79116..676c80f 100644 --- a/yamllint/__init__.py +++ b/yamllint/__init__.py @@ -22,7 +22,7 @@ indentation, etc.""" APP_NAME = 'yamllint' -APP_VERSION = '1.19.0' +APP_VERSION = '1.20.0' APP_DESCRIPTION = __doc__ __author__ = u'Adrien Vergé'