From 1b379628d77cf7ee29a1c8c70be6b58f97a45664 Mon Sep 17 00:00:00 2001 From: Nick Burke Date: Thu, 7 Dec 2017 14:00:52 -0800 Subject: [PATCH 1/8] key-duplicates: Handle merge keys (<<) Merge keys are described here: http://yaml.org/type/merge.html They shouldn't be considered as duplicated keys. Fixes https://github.com/adrienverge/yamllint/issues/88 --- tests/rules/test_key_duplicates.py | 18 ++++++++++++++++++ yamllint/rules/key_duplicates.py | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/rules/test_key_duplicates.py b/tests/rules/test_key_duplicates.py index 362cbba..b325bf6 100644 --- a/tests/rules/test_key_duplicates.py +++ b/tests/rules/test_key_duplicates.py @@ -78,6 +78,15 @@ class KeyDuplicatesTestCase(RuleTestCase): ' duplicates with\n' ' many styles\n' ': 1\n', conf) + self.check('---\n' + 'Merge Keys are OK:\n' + 'anchor_one: &anchor_one\n' + ' one: one\n' + 'anchor_two: &anchor_two\n' + ' two: two\n' + 'anchor_reference:\n' + ' <<: *anchor_one\n' + ' <<: *anchor_two\n', conf) def test_enabled(self): conf = 'key-duplicates: enable' @@ -147,6 +156,15 @@ class KeyDuplicatesTestCase(RuleTestCase): ': 1\n', conf, problem1=(3, 1), problem2=(4, 1), problem3=(5, 3), problem4=(7, 3)) + self.check('---\n' + 'Merge Keys are OK:\n' + 'anchor_one: &anchor_one\n' + ' one: one\n' + 'anchor_two: &anchor_two\n' + ' two: two\n' + 'anchor_reference:\n' + ' <<: *anchor_one\n' + ' <<: *anchor_two\n', conf) def test_key_tokens_in_flow_sequences(self): conf = 'key-duplicates: enable' diff --git a/yamllint/rules/key_duplicates.py b/yamllint/rules/key_duplicates.py index 12d6e09..fc9c5a3 100644 --- a/yamllint/rules/key_duplicates.py +++ b/yamllint/rules/key_duplicates.py @@ -91,7 +91,9 @@ def check(conf, token, prev, next, nextnext, context): # This check is done because KeyTokens can be found inside flow # sequences... strange, but allowed. if len(context['stack']) > 0 and context['stack'][-1].type == MAP: - if next.value in context['stack'][-1].keys: + if (next.value in context['stack'][-1].keys and + # `<<` is "merge key", see http://yaml.org/type/merge.html + next.value != '<<'): yield LintProblem( next.start_mark.line + 1, next.start_mark.column + 1, 'duplication of key "%s" in mapping' % next.value) From 503bde9e707772e996c9f95c87e4f997da063405 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Fri, 2 Mar 2018 14:54:23 -0800 Subject: [PATCH 2/8] pre-commit is now served over https! --- .pre-commit-hooks.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 8c67058..6de9ed7 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -1,7 +1,7 @@ --- # For use with pre-commit. -# See usage instructions at http://pre-commit.com +# See usage instructions at https://pre-commit.com - id: yamllint name: yamllint From 8ab680635be5d20444dfa730e8cad2ecc1632cbc Mon Sep 17 00:00:00 2001 From: Eimert Date: Mon, 2 Apr 2018 20:05:04 +0200 Subject: [PATCH 3/8] docs: Make `ignore` examples clearer [Solved](https://github.com/metacloud/molecule/issues/1228), when yamllint is used by molecule. --- docs/configuration.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 0815789..134172d 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -129,7 +129,7 @@ You can either totally ignore files (they won't be looked at): ignore: | /this/specific/file.yaml - /all/this/directory/ + all/this/directory/ *.template.yaml or ignore paths only for specific rules: @@ -167,4 +167,4 @@ Here is a more complex example: trailing-spaces: ignore: | *.ignore-trailing-spaces.yaml - /ascii-art/* + ascii-art/* From c16934117b3dff91e2c9aa0d872a689cd435964f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Fri, 6 Apr 2018 09:22:24 +0200 Subject: [PATCH 4/8] CI: Remove Travis hack for enum34 crashing on Python 3.6 Revert commit 8b9eab3, it is not needed anymore. --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f27f4bb..c40c6bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,9 +14,6 @@ install: - pip install . script: - if [[ $TRAVIS_PYTHON_VERSION != 2.6 ]]; then flake8 .; fi - # Because of https://github.com/PyCQA/flake8-import-order/issues/149 - # otherwise tests fail with Python 3.6: - - pip uninstall --yes enum34 - yamllint --strict $(git ls-files '*.yaml' '*.yml') - coverage run --source=yamllint setup.py test - if [[ $TRAVIS_PYTHON_VERSION != 2* ]]; then From 3bdc1b6e1bab4b18cbb881251614716968dbfc76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Fri, 6 Apr 2018 09:30:28 +0200 Subject: [PATCH 5/8] CI: Don't install Sphinx if Python 2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Recently builds started to fail with: Collecting sphinx Downloading Sphinx-1.7.2-py2.py3-none-any.whl (1.9MB) 100% |████████████████████████████████| 1.9MB 731kB/s Sphinx requires Python '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*' but the running Python is 2.6.9 --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c40c6bd..80506f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,9 @@ python: - 3.6 - nightly install: - - pip install pyyaml flake8 flake8-import-order coveralls sphinx + - pip install pyyaml flake8 flake8-import-order coveralls - if [[ $TRAVIS_PYTHON_VERSION == 2.6 ]]; then pip install unittest2; fi + - if [[ $TRAVIS_PYTHON_VERSION != 2* ]]; then pip install sphinx; fi - pip install . script: - if [[ $TRAVIS_PYTHON_VERSION != 2.6 ]]; then flake8 .; fi From 36b47767788024b5b69e6d1651e32561c7e3ed98 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Thu, 5 Apr 2018 15:41:25 +0100 Subject: [PATCH 6/8] Clarify documentation on the 'truthy' rule I like the 'truthy' rule but its documentation and message have confused several of my colleagues. I've tried rewriting it to be clearer. --- yamllint/rules/truthy.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/yamllint/rules/truthy.py b/yamllint/rules/truthy.py index c453c86..c14b06a 100644 --- a/yamllint/rules/truthy.py +++ b/yamllint/rules/truthy.py @@ -15,11 +15,12 @@ # along with this program. If not, see . """ -Use this rule to forbid truthy values that are not quoted nor explicitly typed. +Use this rule to forbid non-explictly typed truthy values other than ``true`` +and ``false``, for example ``YES``, ``False`` and ``off``. -This would prevent YAML parsers from transforming ``[yes, FALSE, Off]`` into -``[true, false, false]`` or ``{y: 1, yes: 2, on: 3, true: 4, True: 5}`` into -``{y: 1, true: 5}``. +This can be useful to prevent surprises from YAML parsers transforming +``[yes, FALSE, Off]`` into ``[true, false, false]`` or +``{y: 1, yes: 2, on: 3, true: 4, True: 5}`` into ``{y: 1, true: 5}``. .. rubric:: Examples @@ -34,8 +35,7 @@ This would prevent YAML parsers from transforming ``[yes, FALSE, Off]`` into "yes": 1 "on": 2 - "true": 3 - "True": 4 + "True": 3 explicit: string1: !!str True @@ -62,8 +62,7 @@ This would prevent YAML parsers from transforming ``[yes, FALSE, Off]`` into yes: 1 on: 2 - true: 3 - True: 4 + True: 3 """ import yaml @@ -90,4 +89,4 @@ def check(conf, token, prev, next, nextnext, context): if token.value in TRUTHY and token.style is None: yield LintProblem(token.start_mark.line + 1, token.start_mark.column + 1, - "truthy value is not quoted") + "truthy value should be true or false") From 54f21c051489999dc8eacde711aea6b6381bcfbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Fri, 6 Apr 2018 09:19:03 +0200 Subject: [PATCH 7/8] parser: Fix crash with latest PyYAML There is a backwards-incompatible change in PyYAML that induces a crash if `check_token()` is not called before `peek_token()`. See commit a02d17a in PyYAML or https://github.com/yaml/pyyaml/pull/150. Closes #105. --- yamllint/parser.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yamllint/parser.py b/yamllint/parser.py index 335fa08..ae1ed5f 100644 --- a/yamllint/parser.py +++ b/yamllint/parser.py @@ -125,7 +125,8 @@ def token_or_comment_generator(buffer): curr = yaml_loader.get_token() while curr is not None: next = yaml_loader.get_token() - nextnext = yaml_loader.peek_token() + nextnext = (yaml_loader.peek_token() + if yaml_loader.check_token() else None) yield Token(curr.start_mark.line + 1, curr, prev, next, nextnext) From 506e066410052c42da36c237b8ba3c661448c86b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Fri, 6 Apr 2018 11:11:32 +0200 Subject: [PATCH 8/8] yamllint version 1.11.1 --- CHANGELOG.rst | 9 +++++++++ yamllint/__init__.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1127c82..71f522e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,15 @@ Changelog ========= +1.11.1 (2018-04-06) +------------------- + +- Handle merge keys (`<<`) in the `key-duplicates` rule +- Update documentation about pre-commit +- Make examples for `ignore` rule clearer +- Clarify documentation on the 'truthy' rule +- Fix crash in parser due to a change in PyYAML > 3.12 + 1.11.0 (2018-02-21) ------------------- diff --git a/yamllint/__init__.py b/yamllint/__init__.py index f86c4ea..e864758 100644 --- a/yamllint/__init__.py +++ b/yamllint/__init__.py @@ -22,7 +22,7 @@ indentation, etc.""" APP_NAME = 'yamllint' -APP_VERSION = '1.11.0' +APP_VERSION = '1.11.1' APP_DESCRIPTION = __doc__ __author__ = u'Adrien Vergé'