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 diff --git a/.travis.yml b/.travis.yml index f27f4bb..80506f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,14 +9,12 @@ 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 - # 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 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/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/* 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/__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é' 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) 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) 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")