Compare commits
223 Commits
Author | SHA1 | Date |
---|---|---|
|
a68c3aa69e | 2 years ago |
|
7f2c071545 | 2 years ago |
|
b05e028c58 | 2 years ago |
|
e636848ddc | 2 years ago |
|
019c87d36d | 2 years ago |
|
977f4908b5 | 2 years ago |
|
f874b6607c | 2 years ago |
|
98f2281f56 | 2 years ago |
|
15eafeb80a | 2 years ago |
|
16eae28a50 | 2 years ago |
|
771c3a0412 | 2 years ago |
|
b92fc9cb31 | 2 years ago |
|
e90e0a0eb5 | 2 years ago |
|
6bfd6756e2 | 2 years ago |
|
6b45be1afc | 2 years ago |
|
9d0f59876d | 2 years ago |
|
ebd6b90d3e | 2 years ago |
|
8aaa226830 | 2 years ago |
|
15f8204427 | 2 years ago |
|
404656394c | 2 years ago |
|
06db2af9b0 | 2 years ago |
|
b9e1fd18c1 | 2 years ago |
|
fa0bb03f9a | 2 years ago |
|
2a904f8fc1 | 2 years ago |
|
6194a282fc | 2 years ago |
|
5ac3ed4490 | 3 years ago |
|
5b21a3d9ea | 3 years ago |
|
5fbf44c203 | 3 years ago |
|
c9c5e0b1c7 | 3 years ago |
|
a6e0e1213a | 3 years ago |
|
eb7b7ca627 | 3 years ago |
|
cec4f3383a | 3 years ago |
|
52234b7a46 | 3 years ago |
|
151b1c4086 | 3 years ago |
|
764586d836 | 3 years ago |
|
47cd8f2e9e | 3 years ago |
|
4d271f3daf | 3 years ago |
|
22ddf4c8e5 | 3 years ago |
|
b8c85f0dfd | 3 years ago |
|
e0f749bf5d | 3 years ago |
|
19d00809d1 | 3 years ago |
|
008db4aa09 | 3 years ago |
|
e8391de711 | 3 years ago |
|
a5adec1570 | 3 years ago |
|
9cce294041 | 3 years ago |
|
2f8ad7003a | 3 years ago |
|
fb0c0a5247 | 3 years ago |
|
352e1a975e | 3 years ago |
|
e319a17344 | 3 years ago |
|
6b6fdba3bf | 3 years ago |
|
868350681a | 3 years ago |
|
94c1c2bcf2 | 3 years ago |
|
0130e15c8c | 3 years ago |
|
ae3158cd1f | 3 years ago |
|
4c7b47daf3 | 3 years ago |
|
3346843edc | 3 years ago |
|
ea70520216 | 3 years ago |
|
a09ad89268 | 3 years ago |
|
8d543a4b9c | 3 years ago |
|
8a364e2fde | 3 years ago |
|
dc2d0991e0 | 3 years ago |
|
e6af957131 | 3 years ago |
|
8ac7d58693 | 3 years ago |
|
40cab7f999 | 3 years ago |
|
34a4f76e8b | 3 years ago |
|
7d9c824b83 | 3 years ago |
|
157b06871d | 3 years ago |
|
af843b675a | 3 years ago |
|
695fc5f1f1 | 3 years ago |
|
632665c3e6 | 3 years ago |
|
5658cf7f42 | 3 years ago |
|
bdbec7dc4d | 3 years ago |
|
9700525496 | 3 years ago |
|
327f92e472 | 3 years ago |
|
89b75b7c05 | 3 years ago |
|
e49a101160 | 3 years ago |
|
c268a82c5a | 3 years ago |
|
2f423117c1 | 3 years ago |
|
f58448cb21 | 3 years ago |
|
7974d518cd | 3 years ago |
|
8a320aaf2c | 3 years ago |
|
c34c962691 | 3 years ago |
|
4f1bbc33dc | 3 years ago |
|
bb567ba395 | 3 years ago |
|
d0392b34ca | 3 years ago |
|
7246a0c800 | 3 years ago |
|
9e6dfacceb | 3 years ago |
|
11e8d8ff37 | 3 years ago |
|
f2e2e0c366 | 4 years ago |
|
058fef7559 | 4 years ago |
|
f47d5318cf | 4 years ago |
|
33ce0fa960 | 4 years ago |
|
43744902e9 | 4 years ago |
|
85ccd625a3 | 4 years ago |
|
e53ea093e2 | 4 years ago |
|
5d8ef2ea23 | 4 years ago |
|
4515269233 | 4 years ago |
|
66bf76a362 | 4 years ago |
|
8f682481c7 | 4 years ago |
|
0fff4e29e4 | 4 years ago |
|
1b378ed5b9 | 4 years ago |
|
a3fc64d134 | 4 years ago |
|
ee4d163ff8 | 4 years ago |
|
22335b294d | 4 years ago |
|
0f9dffde23 | 5 years ago |
|
cef0b48993 | 5 years ago |
|
11b1f1c14e | 5 years ago |
|
9ee8c27ac9 | 5 years ago |
|
8eebab68ab | 5 years ago |
|
2103bd73de | 5 years ago |
|
85c8631183 | 5 years ago |
|
16e0f9d7b2 | 5 years ago |
|
1a4f9fe00f | 5 years ago |
|
027d1b0a9a | 5 years ago |
|
67cb4eb24d | 5 years ago |
|
50c7453824 | 5 years ago |
|
549b136a04 | 5 years ago |
|
333ae52c78 | 5 years ago |
|
0a88c55194 | 5 years ago |
|
ac19d1e427 | 5 years ago |
|
597e88bb7b | 5 years ago |
|
29d2b50d50 | 5 years ago |
|
4171cdafc9 | 5 years ago |
|
d274543b72 | 5 years ago |
|
8da98f2122 | 5 years ago |
|
b65769c9d2 | 5 years ago |
|
b80997eba6 | 5 years ago |
|
8b758d4e7e | 5 years ago |
|
b5b436a3a4 | 5 years ago |
|
0fceca2354 | 5 years ago |
|
9403f1f3ec | 5 years ago |
|
0016390e78 | 5 years ago |
|
9e90c777cb | 5 years ago |
|
a2218988ee | 5 years ago |
|
954fdd5e8f | 5 years ago |
|
bbcad943b6 | 5 years ago |
|
30c90dbf70 | 5 years ago |
|
512fe17047 | 5 years ago |
|
278a79f093 | 5 years ago |
|
e98aacf62c | 5 years ago |
|
94c0416f6b | 5 years ago |
|
a54cbce1b6 | 5 years ago |
|
b711fd993e | 5 years ago |
|
d68022b846 | 5 years ago |
|
851d34b9fd | 5 years ago |
|
483a8d89a5 | 5 years ago |
|
fa87913566 | 5 years ago |
|
961c496b4f | 5 years ago |
|
ce7d3fcc7b | 5 years ago |
|
0bffba1e13 | 5 years ago |
|
2d8639c3a1 | 5 years ago |
|
e284d74be1 | 5 years ago |
|
1a13837e84 | 5 years ago |
|
46ed0c02be | 5 years ago |
|
6ce11dedb4 | 5 years ago |
|
542ae758f5 | 5 years ago |
|
3a6a09b7b6 | 5 years ago |
|
15aea73fbe | 5 years ago |
|
91763f5476 | 5 years ago |
|
5b049e4229 | 5 years ago |
|
044c7f0248 | 5 years ago |
|
734d5d5f73 | 5 years ago |
|
fd86455076 | 5 years ago |
|
13a0f11e7c | 5 years ago |
|
43b95e99d1 | 5 years ago |
|
8fa9eb3ced | 5 years ago |
|
da3788e95a | 5 years ago |
|
fb400dc64b | 5 years ago |
|
92324ae730 | 6 years ago |
|
7359785ea0 | 6 years ago |
|
579a975b70 | 6 years ago |
|
f3d9196aa0 | 6 years ago |
|
881d301883 | 6 years ago |
|
b62b424dd4 | 6 years ago |
|
ce0336e430 | 6 years ago |
|
063c854658 | 6 years ago |
|
673bdbd324 | 6 years ago |
|
cb5fe2c050 | 6 years ago |
|
930c8eea94 | 6 years ago |
|
f6a24552d9 | 6 years ago |
|
0ba193331b | 6 years ago |
|
f65553c4f7 | 6 years ago |
|
0fef4c14e7 | 6 years ago |
|
4ef7e05f3a | 6 years ago |
|
43c50379e0 | 6 years ago |
|
fec2c2fba7 | 6 years ago |
|
2a66ec2e5e | 6 years ago |
|
37700ab3e6 | 6 years ago |
|
f66661e36d | 6 years ago |
|
d6b89e94e4 | 6 years ago |
|
05dfcbc109 | 6 years ago |
|
16b939958d | 6 years ago |
|
b4740dc1fb | 6 years ago |
|
b77f78f677 | 6 years ago |
|
0f073f7a09 | 6 years ago |
|
bc7ac81707 | 6 years ago |
|
a56a1015f0 | 6 years ago |
|
6cf5eecdac | 6 years ago |
|
f4c56b8216 | 6 years ago |
|
5852566ff0 | 6 years ago |
|
4a7986b4cf | 6 years ago |
|
3d1ad9a176 | 6 years ago |
|
8da6e36bf1 | 6 years ago |
|
c281d48507 | 6 years ago |
|
8bdddf6e89 | 7 years ago |
|
c8032c086b | 7 years ago |
|
ea045c41b7 | 7 years ago |
|
c803dd5f6d | 7 years ago |
|
318a12bbe6 | 7 years ago |
|
66adaee66c | 7 years ago |
|
5062b91cac | 7 years ago |
|
3ef85739e3 | 7 years ago |
|
dc4a9f4fff | 7 years ago |
|
8354d50016 | 7 years ago |
|
524d721f0d | 7 years ago |
|
e864f57d37 | 7 years ago |
|
d41b64aa97 | 7 years ago |
|
aaa8777f1d | 7 years ago |
|
479f580202 | 7 years ago |
|
e4e99f0aba | 7 years ago |
|
203cfc20f0 | 7 years ago |
|
51c30505b5 | 7 years ago |
|
ff9ebde608 | 7 years ago |
@ -0,0 +1,4 @@
|
|||||||
|
[flake8]
|
||||||
|
import-order-style = pep8
|
||||||
|
application-import-names = yamllint
|
||||||
|
ignore = W503,W504
|
@ -0,0 +1,61 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
name: CI
|
||||||
|
|
||||||
|
on: # yamllint disable-line rule:truthy
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
name: Linters
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
- run:
|
||||||
|
pip install flake8 flake8-import-order sphinx rstcheck[sphinx] doc8
|
||||||
|
- run: pip install .
|
||||||
|
- run: flake8 .
|
||||||
|
- run: doc8 $(git ls-files '*.rst')
|
||||||
|
- run: rstcheck --ignore-directives automodule $(git ls-files '*.rst')
|
||||||
|
- run: yamllint --strict $(git ls-files '*.yaml' '*.yml')
|
||||||
|
- run: make -C docs html
|
||||||
|
- name: Check for broken links in documentation
|
||||||
|
run: make -C docs linkcheck
|
||||||
|
|
||||||
|
test:
|
||||||
|
name: Tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
python-version:
|
||||||
|
- '3.7'
|
||||||
|
- '3.8'
|
||||||
|
- '3.9'
|
||||||
|
- '3.10'
|
||||||
|
- '3.11'
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
- name: Append GitHub Actions system path
|
||||||
|
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
|
||||||
|
- run: pip install coverage
|
||||||
|
- run: pip install .
|
||||||
|
# https://github.com/AndreMiras/coveralls-python-action/issues/18
|
||||||
|
- run: echo -e "[run]\nrelative_files = True" > .coveragerc
|
||||||
|
- run: coverage run -m unittest discover
|
||||||
|
- name: Coveralls
|
||||||
|
uses: AndreMiras/coveralls-python-action@develop
|
@ -1,24 +0,0 @@
|
|||||||
---
|
|
||||||
language: python
|
|
||||||
python:
|
|
||||||
- 2.6
|
|
||||||
- 2.7
|
|
||||||
- 3.3
|
|
||||||
- 3.4
|
|
||||||
- 3.5
|
|
||||||
- 3.6
|
|
||||||
- nightly
|
|
||||||
install:
|
|
||||||
- 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
|
|
||||||
- yamllint --strict $(git ls-files '*.yaml' '*.yml')
|
|
||||||
- coverage run --source=yamllint setup.py test
|
|
||||||
- if [[ $TRAVIS_PYTHON_VERSION != 2* ]]; then
|
|
||||||
python setup.py build_sphinx;
|
|
||||||
fi
|
|
||||||
after_success:
|
|
||||||
coveralls
|
|
@ -0,0 +1,48 @@
|
|||||||
|
Contributing
|
||||||
|
============
|
||||||
|
|
||||||
|
Pull requests are the best way to propose changes to the codebase.
|
||||||
|
Contributions are welcome, but they have to meet some criteria.
|
||||||
|
|
||||||
|
Pull Request Process
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
1. Fork this Git repository and create your branch from ``master``.
|
||||||
|
|
||||||
|
2. Make sure the tests pass:
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
pip install --user .
|
||||||
|
python -m unittest discover # all tests...
|
||||||
|
python -m unittest tests/rules/test_commas.py # or just some tests (faster)
|
||||||
|
|
||||||
|
3. If you add code that should be tested, add tests.
|
||||||
|
|
||||||
|
4. Make sure the linters pass:
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
flake8 .
|
||||||
|
|
||||||
|
If you added/modified documentation:
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
doc8 $(git ls-files '*.rst')
|
||||||
|
|
||||||
|
If you touched YAML files:
|
||||||
|
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
yamllint --strict $(git ls-files '*.yaml' '*.yml')
|
||||||
|
|
||||||
|
5. If relevant, update documentation (either in ``docs`` directly or in rules
|
||||||
|
files themselves).
|
||||||
|
|
||||||
|
6. Write a `good commit message
|
||||||
|
<http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html>`_.
|
||||||
|
If the pull request has multiple commits, each must be atomic (single
|
||||||
|
irreducible change that makes sense on its own).
|
||||||
|
|
||||||
|
7. Then, open a pull request.
|
@ -1,4 +0,0 @@
|
|||||||
include LICENSE
|
|
||||||
include README.rst
|
|
||||||
include docs/*
|
|
||||||
include tests/*.py tests/rules/*.py tests/yaml-1.2-spec-examples/*
|
|
Binary file not shown.
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 31 KiB |
@ -0,0 +1,54 @@
|
|||||||
|
[project]
|
||||||
|
name = "yamllint"
|
||||||
|
description = "A linter for YAML files."
|
||||||
|
readme = {file = "README.rst", content-type = "text/x-rst"}
|
||||||
|
requires-python = ">=3.7"
|
||||||
|
license = {text = "GPL-3.0-or-later"}
|
||||||
|
authors = [{name = "Adrien Vergé"}]
|
||||||
|
keywords = ["yaml", "lint", "linter", "syntax", "checker"]
|
||||||
|
classifiers = [
|
||||||
|
"Development Status :: 5 - Production/Stable",
|
||||||
|
"Environment :: Console",
|
||||||
|
"Intended Audience :: Developers",
|
||||||
|
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
|
||||||
|
"Programming Language :: Python",
|
||||||
|
"Topic :: Software Development",
|
||||||
|
"Topic :: Software Development :: Debuggers",
|
||||||
|
"Topic :: Software Development :: Quality Assurance",
|
||||||
|
"Topic :: Software Development :: Testing",
|
||||||
|
]
|
||||||
|
dependencies = [
|
||||||
|
"pathspec >= 0.5.3",
|
||||||
|
"pyyaml",
|
||||||
|
]
|
||||||
|
dynamic = ["version"]
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
|
dev = [
|
||||||
|
"doc8",
|
||||||
|
"flake8",
|
||||||
|
"flake8-import-order",
|
||||||
|
"rstcheck[sphinx]",
|
||||||
|
"sphinx",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
yamllint = "yamllint.cli:run"
|
||||||
|
|
||||||
|
[project.urls]
|
||||||
|
homepage = "https://github.com/adrienverge/yamllint"
|
||||||
|
repository = "https://github.com/adrienverge/yamllint"
|
||||||
|
documentation = "https://yamllint.readthedocs.io"
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
|
requires = ["setuptools >= 61"]
|
||||||
|
|
||||||
|
[tool.setuptools]
|
||||||
|
packages = ["yamllint", "yamllint.conf", "yamllint.rules"]
|
||||||
|
|
||||||
|
[tool.setuptools.package-data]
|
||||||
|
yamllint = ["conf/*.yaml"]
|
||||||
|
|
||||||
|
[tool.setuptools.dynamic]
|
||||||
|
version = {attr = "yamllint.__version__"}
|
@ -1,12 +0,0 @@
|
|||||||
[bdist_wheel]
|
|
||||||
universal = 1
|
|
||||||
|
|
||||||
[flake8]
|
|
||||||
import-order-style = pep8
|
|
||||||
application-import-names = yamllint
|
|
||||||
|
|
||||||
[build_sphinx]
|
|
||||||
all-files = 1
|
|
||||||
source-dir = docs
|
|
||||||
build-dir = docs/_build
|
|
||||||
warning-is-error = 1
|
|
@ -0,0 +1,281 @@
|
|||||||
|
# Copyright (C) 2023 Adrien Vergé
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from tests.common import RuleTestCase
|
||||||
|
|
||||||
|
|
||||||
|
class AnchorsTestCase(RuleTestCase):
|
||||||
|
rule_id = 'anchors'
|
||||||
|
|
||||||
|
def test_disabled(self):
|
||||||
|
conf = 'anchors: disable'
|
||||||
|
self.check('---\n'
|
||||||
|
'- &b true\n'
|
||||||
|
'- &i 42\n'
|
||||||
|
'- &s hello\n'
|
||||||
|
'- &f_m {k: v}\n'
|
||||||
|
'- &f_s [1, 2]\n'
|
||||||
|
'- *b\n'
|
||||||
|
'- *i\n'
|
||||||
|
'- *s\n'
|
||||||
|
'- *f_m\n'
|
||||||
|
'- *f_s\n'
|
||||||
|
'---\n' # redeclare anchors in a new document
|
||||||
|
'- &b true\n'
|
||||||
|
'- &i 42\n'
|
||||||
|
'- &s hello\n'
|
||||||
|
'- *b\n'
|
||||||
|
'- *i\n'
|
||||||
|
'- *s\n'
|
||||||
|
'---\n'
|
||||||
|
'block mapping: &b_m\n'
|
||||||
|
' key: value\n'
|
||||||
|
'extended:\n'
|
||||||
|
' <<: *b_m\n'
|
||||||
|
' foo: bar\n'
|
||||||
|
'---\n'
|
||||||
|
'{a: 1, &x b: 2, c: &y 3, *x : 4, e: *y}\n'
|
||||||
|
'...\n', conf)
|
||||||
|
self.check('---\n'
|
||||||
|
'- &i 42\n'
|
||||||
|
'---\n'
|
||||||
|
'- &b true\n'
|
||||||
|
'- &b true\n'
|
||||||
|
'- &b true\n'
|
||||||
|
'- &s hello\n'
|
||||||
|
'- *b\n'
|
||||||
|
'- *i\n' # declared in a previous document
|
||||||
|
'- *f_m\n' # never declared
|
||||||
|
'- *f_m\n'
|
||||||
|
'- *f_m\n'
|
||||||
|
'- *f_s\n' # declared after
|
||||||
|
'- &f_s [1, 2]\n'
|
||||||
|
'---\n'
|
||||||
|
'block mapping: &b_m\n'
|
||||||
|
' key: value\n'
|
||||||
|
'---\n'
|
||||||
|
'block mapping 1: &b_m_bis\n'
|
||||||
|
' key: value\n'
|
||||||
|
'block mapping 2: &b_m_bis\n'
|
||||||
|
' key: value\n'
|
||||||
|
'extended:\n'
|
||||||
|
' <<: *b_m\n'
|
||||||
|
' foo: bar\n'
|
||||||
|
'---\n'
|
||||||
|
'{a: 1, &x b: 2, c: &x 3, *x : 4, e: *y}\n'
|
||||||
|
'...\n', conf)
|
||||||
|
|
||||||
|
def test_forbid_undeclared_aliases(self):
|
||||||
|
conf = ('anchors:\n'
|
||||||
|
' forbid-undeclared-aliases: true\n'
|
||||||
|
' forbid-duplicated-anchors: false\n'
|
||||||
|
' forbid-unused-anchors: false\n')
|
||||||
|
self.check('---\n'
|
||||||
|
'- &b true\n'
|
||||||
|
'- &i 42\n'
|
||||||
|
'- &s hello\n'
|
||||||
|
'- &f_m {k: v}\n'
|
||||||
|
'- &f_s [1, 2]\n'
|
||||||
|
'- *b\n'
|
||||||
|
'- *i\n'
|
||||||
|
'- *s\n'
|
||||||
|
'- *f_m\n'
|
||||||
|
'- *f_s\n'
|
||||||
|
'---\n' # redeclare anchors in a new document
|
||||||
|
'- &b true\n'
|
||||||
|
'- &i 42\n'
|
||||||
|
'- &s hello\n'
|
||||||
|
'- *b\n'
|
||||||
|
'- *i\n'
|
||||||
|
'- *s\n'
|
||||||
|
'---\n'
|
||||||
|
'block mapping: &b_m\n'
|
||||||
|
' key: value\n'
|
||||||
|
'extended:\n'
|
||||||
|
' <<: *b_m\n'
|
||||||
|
' foo: bar\n'
|
||||||
|
'---\n'
|
||||||
|
'{a: 1, &x b: 2, c: &y 3, *x : 4, e: *y}\n'
|
||||||
|
'...\n', conf)
|
||||||
|
self.check('---\n'
|
||||||
|
'- &i 42\n'
|
||||||
|
'---\n'
|
||||||
|
'- &b true\n'
|
||||||
|
'- &b true\n'
|
||||||
|
'- &b true\n'
|
||||||
|
'- &s hello\n'
|
||||||
|
'- *b\n'
|
||||||
|
'- *i\n' # declared in a previous document
|
||||||
|
'- *f_m\n' # never declared
|
||||||
|
'- *f_m\n'
|
||||||
|
'- *f_m\n'
|
||||||
|
'- *f_s\n' # declared after
|
||||||
|
'- &f_s [1, 2]\n'
|
||||||
|
'...\n'
|
||||||
|
'---\n'
|
||||||
|
'block mapping: &b_m\n'
|
||||||
|
' key: value\n'
|
||||||
|
'---\n'
|
||||||
|
'block mapping 1: &b_m_bis\n'
|
||||||
|
' key: value\n'
|
||||||
|
'block mapping 2: &b_m_bis\n'
|
||||||
|
' key: value\n'
|
||||||
|
'extended:\n'
|
||||||
|
' <<: *b_m\n'
|
||||||
|
' foo: bar\n'
|
||||||
|
'---\n'
|
||||||
|
'{a: 1, &x b: 2, c: &x 3, *x : 4, e: *y}\n'
|
||||||
|
'...\n', conf,
|
||||||
|
problem1=(9, 3),
|
||||||
|
problem2=(10, 3),
|
||||||
|
problem3=(11, 3),
|
||||||
|
problem4=(12, 3),
|
||||||
|
problem5=(13, 3),
|
||||||
|
problem6=(25, 7),
|
||||||
|
problem7=(28, 37))
|
||||||
|
|
||||||
|
def test_forbid_duplicated_anchors(self):
|
||||||
|
conf = ('anchors:\n'
|
||||||
|
' forbid-undeclared-aliases: false\n'
|
||||||
|
' forbid-duplicated-anchors: true\n'
|
||||||
|
' forbid-unused-anchors: false\n')
|
||||||
|
self.check('---\n'
|
||||||
|
'- &b true\n'
|
||||||
|
'- &i 42\n'
|
||||||
|
'- &s hello\n'
|
||||||
|
'- &f_m {k: v}\n'
|
||||||
|
'- &f_s [1, 2]\n'
|
||||||
|
'- *b\n'
|
||||||
|
'- *i\n'
|
||||||
|
'- *s\n'
|
||||||
|
'- *f_m\n'
|
||||||
|
'- *f_s\n'
|
||||||
|
'---\n' # redeclare anchors in a new document
|
||||||
|
'- &b true\n'
|
||||||
|
'- &i 42\n'
|
||||||
|
'- &s hello\n'
|
||||||
|
'- *b\n'
|
||||||
|
'- *i\n'
|
||||||
|
'- *s\n'
|
||||||
|
'---\n'
|
||||||
|
'block mapping: &b_m\n'
|
||||||
|
' key: value\n'
|
||||||
|
'extended:\n'
|
||||||
|
' <<: *b_m\n'
|
||||||
|
' foo: bar\n'
|
||||||
|
'---\n'
|
||||||
|
'{a: 1, &x b: 2, c: &y 3, *x : 4, e: *y}\n'
|
||||||
|
'...\n', conf)
|
||||||
|
self.check('---\n'
|
||||||
|
'- &i 42\n'
|
||||||
|
'---\n'
|
||||||
|
'- &b true\n'
|
||||||
|
'- &b true\n'
|
||||||
|
'- &b true\n'
|
||||||
|
'- &s hello\n'
|
||||||
|
'- *b\n'
|
||||||
|
'- *i\n' # declared in a previous document
|
||||||
|
'- *f_m\n' # never declared
|
||||||
|
'- *f_m\n'
|
||||||
|
'- *f_m\n'
|
||||||
|
'- *f_s\n' # declared after
|
||||||
|
'- &f_s [1, 2]\n'
|
||||||
|
'...\n'
|
||||||
|
'---\n'
|
||||||
|
'block mapping: &b_m\n'
|
||||||
|
' key: value\n'
|
||||||
|
'---\n'
|
||||||
|
'block mapping 1: &b_m_bis\n'
|
||||||
|
' key: value\n'
|
||||||
|
'block mapping 2: &b_m_bis\n'
|
||||||
|
' key: value\n'
|
||||||
|
'extended:\n'
|
||||||
|
' <<: *b_m\n'
|
||||||
|
' foo: bar\n'
|
||||||
|
'---\n'
|
||||||
|
'{a: 1, &x b: 2, c: &x 3, *x : 4, e: *y}\n'
|
||||||
|
'...\n', conf,
|
||||||
|
problem1=(5, 3),
|
||||||
|
problem2=(6, 3),
|
||||||
|
problem3=(22, 18),
|
||||||
|
problem4=(28, 20))
|
||||||
|
|
||||||
|
def test_forbid_unused_anchors(self):
|
||||||
|
conf = ('anchors:\n'
|
||||||
|
' forbid-undeclared-aliases: false\n'
|
||||||
|
' forbid-duplicated-anchors: false\n'
|
||||||
|
' forbid-unused-anchors: true\n')
|
||||||
|
|
||||||
|
self.check('---\n'
|
||||||
|
'- &b true\n'
|
||||||
|
'- &i 42\n'
|
||||||
|
'- &s hello\n'
|
||||||
|
'- &f_m {k: v}\n'
|
||||||
|
'- &f_s [1, 2]\n'
|
||||||
|
'- *b\n'
|
||||||
|
'- *i\n'
|
||||||
|
'- *s\n'
|
||||||
|
'- *f_m\n'
|
||||||
|
'- *f_s\n'
|
||||||
|
'---\n' # redeclare anchors in a new document
|
||||||
|
'- &b true\n'
|
||||||
|
'- &i 42\n'
|
||||||
|
'- &s hello\n'
|
||||||
|
'- *b\n'
|
||||||
|
'- *i\n'
|
||||||
|
'- *s\n'
|
||||||
|
'---\n'
|
||||||
|
'block mapping: &b_m\n'
|
||||||
|
' key: value\n'
|
||||||
|
'extended:\n'
|
||||||
|
' <<: *b_m\n'
|
||||||
|
' foo: bar\n'
|
||||||
|
'---\n'
|
||||||
|
'{a: 1, &x b: 2, c: &y 3, *x : 4, e: *y}\n'
|
||||||
|
'...\n', conf)
|
||||||
|
self.check('---\n'
|
||||||
|
'- &i 42\n'
|
||||||
|
'---\n'
|
||||||
|
'- &b true\n'
|
||||||
|
'- &b true\n'
|
||||||
|
'- &b true\n'
|
||||||
|
'- &s hello\n'
|
||||||
|
'- *b\n'
|
||||||
|
'- *i\n' # declared in a previous document
|
||||||
|
'- *f_m\n' # never declared
|
||||||
|
'- *f_m\n'
|
||||||
|
'- *f_m\n'
|
||||||
|
'- *f_s\n' # declared after
|
||||||
|
'- &f_s [1, 2]\n'
|
||||||
|
'...\n'
|
||||||
|
'---\n'
|
||||||
|
'block mapping: &b_m\n'
|
||||||
|
' key: value\n'
|
||||||
|
'---\n'
|
||||||
|
'block mapping 1: &b_m_bis\n'
|
||||||
|
' key: value\n'
|
||||||
|
'block mapping 2: &b_m_bis\n'
|
||||||
|
' key: value\n'
|
||||||
|
'extended:\n'
|
||||||
|
' <<: *b_m\n'
|
||||||
|
' foo: bar\n'
|
||||||
|
'---\n'
|
||||||
|
'{a: 1, &x b: 2, c: &x 3, *x : 4, e: *y}\n'
|
||||||
|
'...\n', conf,
|
||||||
|
problem1=(2, 3),
|
||||||
|
problem2=(7, 3),
|
||||||
|
problem3=(14, 3),
|
||||||
|
problem4=(17, 16),
|
||||||
|
problem5=(22, 18))
|
@ -0,0 +1,128 @@
|
|||||||
|
# Copyright (C) 2022 the yamllint contributors
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from tests.common import RuleTestCase
|
||||||
|
|
||||||
|
|
||||||
|
class FloatValuesTestCase(RuleTestCase):
|
||||||
|
rule_id = 'float-values'
|
||||||
|
|
||||||
|
def test_disabled(self):
|
||||||
|
conf = 'float-values: disable\n'
|
||||||
|
self.check('---\n'
|
||||||
|
'- 0.0\n'
|
||||||
|
'- .NaN\n'
|
||||||
|
'- .INF\n'
|
||||||
|
'- .1\n'
|
||||||
|
'- 10e-6\n',
|
||||||
|
conf)
|
||||||
|
|
||||||
|
def test_numeral_before_decimal(self):
|
||||||
|
conf = (
|
||||||
|
'float-values:\n'
|
||||||
|
' require-numeral-before-decimal: true\n'
|
||||||
|
' forbid-scientific-notation: false\n'
|
||||||
|
' forbid-nan: false\n'
|
||||||
|
' forbid-inf: false\n')
|
||||||
|
self.check('---\n'
|
||||||
|
'- 0.0\n'
|
||||||
|
'- .1\n'
|
||||||
|
'- \'.1\'\n'
|
||||||
|
'- string.1\n'
|
||||||
|
'- .1string\n'
|
||||||
|
'- !custom_tag .2\n'
|
||||||
|
'- &angle1 0.0\n'
|
||||||
|
'- *angle1\n'
|
||||||
|
'- &angle2 .3\n'
|
||||||
|
'- *angle2\n',
|
||||||
|
conf,
|
||||||
|
problem1=(3, 3),
|
||||||
|
problem2=(10, 11))
|
||||||
|
|
||||||
|
def test_scientific_notation(self):
|
||||||
|
conf = (
|
||||||
|
'float-values:\n'
|
||||||
|
' require-numeral-before-decimal: false\n'
|
||||||
|
' forbid-scientific-notation: true\n'
|
||||||
|
' forbid-nan: false\n'
|
||||||
|
' forbid-inf: false\n')
|
||||||
|
self.check('---\n'
|
||||||
|
'- 10e6\n'
|
||||||
|
'- 10e-6\n'
|
||||||
|
'- 0.00001\n'
|
||||||
|
'- \'10e-6\'\n'
|
||||||
|
'- string10e-6\n'
|
||||||
|
'- 10e-6string\n'
|
||||||
|
'- !custom_tag 10e-6\n'
|
||||||
|
'- &angle1 0.000001\n'
|
||||||
|
'- *angle1\n'
|
||||||
|
'- &angle2 10e-6\n'
|
||||||
|
'- *angle2\n'
|
||||||
|
'- &angle3 10e6\n'
|
||||||
|
'- *angle3\n',
|
||||||
|
conf,
|
||||||
|
problem1=(2, 3),
|
||||||
|
problem2=(3, 3),
|
||||||
|
problem3=(11, 11),
|
||||||
|
problem4=(13, 11))
|
||||||
|
|
||||||
|
def test_nan(self):
|
||||||
|
conf = (
|
||||||
|
'float-values:\n'
|
||||||
|
' require-numeral-before-decimal: false\n'
|
||||||
|
' forbid-scientific-notation: false\n'
|
||||||
|
' forbid-nan: true\n'
|
||||||
|
' forbid-inf: false\n')
|
||||||
|
self.check('---\n'
|
||||||
|
'- .NaN\n'
|
||||||
|
'- .NAN\n'
|
||||||
|
'- \'.NaN\'\n'
|
||||||
|
'- a.NaN\n'
|
||||||
|
'- .NaNa\n'
|
||||||
|
'- !custom_tag .NaN\n'
|
||||||
|
'- &angle .nan\n'
|
||||||
|
'- *angle\n',
|
||||||
|
conf,
|
||||||
|
problem1=(2, 3),
|
||||||
|
problem2=(3, 3),
|
||||||
|
problem3=(8, 10))
|
||||||
|
|
||||||
|
def test_inf(self):
|
||||||
|
conf = (
|
||||||
|
'float-values:\n'
|
||||||
|
' require-numeral-before-decimal: false\n'
|
||||||
|
' forbid-scientific-notation: false\n'
|
||||||
|
' forbid-nan: false\n'
|
||||||
|
' forbid-inf: true\n')
|
||||||
|
self.check('---\n'
|
||||||
|
'- .inf\n'
|
||||||
|
'- .INF\n'
|
||||||
|
'- -.inf\n'
|
||||||
|
'- -.INF\n'
|
||||||
|
'- \'.inf\'\n'
|
||||||
|
'- ∞.infinity\n'
|
||||||
|
'- .infinity∞\n'
|
||||||
|
'- !custom_tag .inf\n'
|
||||||
|
'- &angle .inf\n'
|
||||||
|
'- *angle\n'
|
||||||
|
'- &angle -.inf\n'
|
||||||
|
'- *angle\n',
|
||||||
|
conf,
|
||||||
|
problem1=(2, 3),
|
||||||
|
problem2=(3, 3),
|
||||||
|
problem3=(4, 3),
|
||||||
|
problem4=(5, 3),
|
||||||
|
problem5=(10, 10),
|
||||||
|
problem6=(12, 10))
|
@ -0,0 +1,558 @@
|
|||||||
|
# Copyright (C) 2018 ClearScore
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from tests.common import RuleTestCase
|
||||||
|
|
||||||
|
from yamllint import config
|
||||||
|
|
||||||
|
|
||||||
|
class QuotedTestCase(RuleTestCase):
|
||||||
|
rule_id = 'quoted-strings'
|
||||||
|
|
||||||
|
def test_disabled(self):
|
||||||
|
conf = 'quoted-strings: disable'
|
||||||
|
|
||||||
|
self.check('---\n'
|
||||||
|
'foo: bar\n', conf)
|
||||||
|
self.check('---\n'
|
||||||
|
'foo: "bar"\n', conf)
|
||||||
|
self.check('---\n'
|
||||||
|
'foo: \'bar\'\n', conf)
|
||||||
|
self.check('---\n'
|
||||||
|
'bar: 123\n', conf)
|
||||||
|
self.check('---\n'
|
||||||
|
'bar: "123"\n', conf)
|
||||||
|
|
||||||
|
def test_quote_type_any(self):
|
||||||
|
conf = 'quoted-strings: {quote-type: any}\n'
|
||||||
|
|
||||||
|
self.check('---\n'
|
||||||
|
'boolean1: true\n'
|
||||||
|
'number1: 123\n'
|
||||||
|
'string1: foo\n' # fails
|
||||||
|
'string2: "foo"\n'
|
||||||
|
'string3: "true"\n'
|
||||||
|
'string4: "123"\n'
|
||||||
|
'string5: \'bar\'\n'
|
||||||
|
'string6: !!str genericstring\n'
|
||||||
|
'string7: !!str 456\n'
|
||||||
|
'string8: !!str "quotedgenericstring"\n'
|
||||||
|
'binary: !!binary binstring\n'
|
||||||
|
'integer: !!int intstring\n'
|
||||||
|
'boolean2: !!bool boolstring\n'
|
||||||
|
'boolean3: !!bool "quotedboolstring"\n'
|
||||||
|
'block-seq:\n'
|
||||||
|
' - foo\n' # fails
|
||||||
|
' - "foo"\n'
|
||||||
|
'flow-seq: [foo, "foo"]\n' # fails
|
||||||
|
'flow-map: {a: foo, b: "foo"}\n', # fails
|
||||||
|
conf, problem1=(4, 10), problem2=(17, 5),
|
||||||
|
problem3=(19, 12), problem4=(20, 15))
|
||||||
|
self.check('---\n'
|
||||||
|
'multiline string 1: |\n'
|
||||||
|
' line 1\n'
|
||||||
|
' line 2\n'
|
||||||
|
'multiline string 2: >\n'
|
||||||
|
' word 1\n'
|
||||||
|
' word 2\n'
|
||||||
|
'multiline string 3:\n'
|
||||||
|
' word 1\n' # fails
|
||||||
|
' word 2\n'
|
||||||
|
'multiline string 4:\n'
|
||||||
|
' "word 1\\\n'
|
||||||
|
' word 2"\n',
|
||||||
|
conf, problem1=(9, 3))
|
||||||
|
|
||||||
|
def test_quote_type_single(self):
|
||||||
|
conf = 'quoted-strings: {quote-type: single}\n'
|
||||||
|
|
||||||
|
self.check('---\n'
|
||||||
|
'boolean1: true\n'
|
||||||
|
'number1: 123\n'
|
||||||
|
'string1: foo\n' # fails
|
||||||
|
'string2: "foo"\n' # fails
|
||||||
|
'string3: "true"\n' # fails
|
||||||
|
'string4: "123"\n' # fails
|
||||||
|
'string5: \'bar\'\n'
|
||||||
|
'string6: !!str genericstring\n'
|
||||||
|
'string7: !!str 456\n'
|
||||||
|
'string8: !!str "quotedgenericstring"\n'
|
||||||
|
'binary: !!binary binstring\n'
|
||||||
|
'integer: !!int intstring\n'
|
||||||
|
'boolean2: !!bool boolstring\n'
|
||||||
|
'boolean3: !!bool "quotedboolstring"\n'
|
||||||
|
'block-seq:\n'
|
||||||
|
' - foo\n' # fails
|
||||||
|
' - "foo"\n' # fails
|
||||||
|
'flow-seq: [foo, "foo"]\n' # fails
|
||||||
|
'flow-map: {a: foo, b: "foo"}\n', # fails
|
||||||
|
conf, problem1=(4, 10), problem2=(5, 10), problem3=(6, 10),
|
||||||
|
problem4=(7, 10), problem5=(17, 5), problem6=(18, 5),
|
||||||
|
problem7=(19, 12), problem8=(19, 17), problem9=(20, 15),
|
||||||
|
problem10=(20, 23))
|
||||||
|
self.check('---\n'
|
||||||
|
'multiline string 1: |\n'
|
||||||
|
' line 1\n'
|
||||||
|
' line 2\n'
|
||||||
|
'multiline string 2: >\n'
|
||||||
|
' word 1\n'
|
||||||
|
' word 2\n'
|
||||||
|
'multiline string 3:\n'
|
||||||
|
' word 1\n' # fails
|
||||||
|
' word 2\n'
|
||||||
|
'multiline string 4:\n'
|
||||||
|
' "word 1\\\n'
|
||||||
|
' word 2"\n',
|
||||||
|
conf, problem1=(9, 3), problem2=(12, 3))
|
||||||
|
|
||||||
|
def test_quote_type_double(self):
|
||||||
|
conf = 'quoted-strings: {quote-type: double}\n'
|
||||||
|
|
||||||
|
self.check('---\n'
|
||||||
|
'boolean1: true\n'
|
||||||
|
'number1: 123\n'
|
||||||
|
'string1: foo\n' # fails
|
||||||
|
'string2: "foo"\n'
|
||||||
|
'string3: "true"\n'
|
||||||
|
'string4: "123"\n'
|
||||||
|
'string5: \'bar\'\n' # fails
|
||||||
|
'string6: !!str genericstring\n'
|
||||||
|
'string7: !!str 456\n'
|
||||||
|
'string8: !!str "quotedgenericstring"\n'
|
||||||
|
'binary: !!binary binstring\n'
|
||||||
|
'integer: !!int intstring\n'
|
||||||
|
'boolean2: !!bool boolstring\n'
|
||||||
|
'boolean3: !!bool "quotedboolstring"\n'
|
||||||
|
'block-seq:\n'
|
||||||
|
' - foo\n' # fails
|
||||||
|
' - "foo"\n'
|
||||||
|
'flow-seq: [foo, "foo"]\n' # fails
|
||||||
|
'flow-map: {a: foo, b: "foo"}\n', # fails
|
||||||
|
conf, problem1=(4, 10), problem2=(8, 10), problem3=(17, 5),
|
||||||
|
problem4=(19, 12), problem5=(20, 15))
|
||||||
|
self.check('---\n'
|
||||||
|
'multiline string 1: |\n'
|
||||||
|
' line 1\n'
|
||||||
|
' line 2\n'
|
||||||
|
'multiline string 2: >\n'
|
||||||
|
' word 1\n'
|
||||||
|
' word 2\n'
|
||||||
|
'multiline string 3:\n'
|
||||||
|
' word 1\n' # fails
|
||||||
|
' word 2\n'
|
||||||
|
'multiline string 4:\n'
|
||||||
|
' "word 1\\\n'
|
||||||
|
' word 2"\n',
|
||||||
|
conf, problem1=(9, 3))
|
||||||
|
|
||||||
|
def test_any_quotes_not_required(self):
|
||||||
|
conf = 'quoted-strings: {quote-type: any, required: false}\n'
|
||||||
|
|
||||||
|
self.check('---\n'
|
||||||
|
'boolean1: true\n'
|
||||||
|
'number1: 123\n'
|
||||||
|
'string1: foo\n'
|
||||||
|
'string2: "foo"\n'
|
||||||
|
'string3: "true"\n'
|
||||||
|
'string4: "123"\n'
|
||||||
|
'string5: \'bar\'\n'
|
||||||
|
'string6: !!str genericstring\n'
|
||||||
|
'string7: !!str 456\n'
|
||||||
|
'string8: !!str "quotedgenericstring"\n'
|
||||||
|
'binary: !!binary binstring\n'
|
||||||
|
'integer: !!int intstring\n'
|
||||||
|
'boolean2: !!bool boolstring\n'
|
||||||
|
'boolean3: !!bool "quotedboolstring"\n'
|
||||||
|
'block-seq:\n'
|
||||||
|
' - foo\n' # fails
|
||||||
|
' - "foo"\n'
|
||||||
|
'flow-seq: [foo, "foo"]\n' # fails
|
||||||
|
'flow-map: {a: foo, b: "foo"}\n', # fails
|
||||||
|
conf)
|
||||||
|
self.check('---\n'
|
||||||
|
'multiline string 1: |\n'
|
||||||
|
' line 1\n'
|
||||||
|
' line 2\n'
|
||||||
|
'multiline string 2: >\n'
|
||||||
|
' word 1\n'
|
||||||
|
' word 2\n'
|
||||||
|
'multiline string 3:\n'
|
||||||
|
' word 1\n'
|
||||||
|
' word 2\n'
|
||||||
|
'multiline string 4:\n'
|
||||||
|
' "word 1\\\n'
|
||||||
|
' word 2"\n',
|
||||||
|
conf)
|
||||||
|
|
||||||
|
def test_single_quotes_not_required(self):
|
||||||
|
conf = 'quoted-strings: {quote-type: single, required: false}\n'
|
||||||
|
|
||||||
|
self.check('---\n'
|
||||||
|
'boolean1: true\n'
|
||||||
|
'number1: 123\n'
|
||||||
|
'string1: foo\n'
|
||||||
|
'string2: "foo"\n' # fails
|
||||||
|
'string3: "true"\n' # fails
|
||||||
|
'string4: "123"\n' # fails
|
||||||
|
'string5: \'bar\'\n'
|
||||||
|
'string6: !!str genericstring\n'
|
||||||
|
'string7: !!str 456\n'
|
||||||
|
'string8: !!str "quotedgenericstring"\n'
|
||||||
|
'binary: !!binary binstring\n'
|
||||||
|
'integer: !!int intstring\n'
|
||||||
|
'boolean2: !!bool boolstring\n'
|
||||||
|
'boolean3: !!bool "quotedboolstring"\n'
|
||||||
|
'block-seq:\n'
|
||||||
|
' - foo\n' # fails
|
||||||
|
' - "foo"\n'
|
||||||
|
'flow-seq: [foo, "foo"]\n' # fails
|
||||||
|
'flow-map: {a: foo, b: "foo"}\n', # fails
|
||||||
|
conf, problem1=(5, 10), problem2=(6, 10), problem3=(7, 10),
|
||||||
|
problem4=(18, 5), problem5=(19, 17), problem6=(20, 23))
|
||||||
|
self.check('---\n'
|
||||||
|
'multiline string 1: |\n'
|
||||||
|
' line 1\n'
|
||||||
|
' line 2\n'
|
||||||
|
'multiline string 2: >\n'
|
||||||
|
' word 1\n'
|
||||||
|
' word 2\n'
|
||||||
|
'multiline string 3:\n'
|
||||||
|
' word 1\n'
|
||||||
|
' word 2\n'
|
||||||
|
'multiline string 4:\n'
|
||||||
|
' "word 1\\\n' # fails
|
||||||
|
' word 2"\n',
|
||||||
|
conf, problem1=(12, 3))
|
||||||
|
|
||||||
|
def test_only_when_needed(self):
|
||||||
|
conf = 'quoted-strings: {required: only-when-needed}\n'
|
||||||
|
|
||||||
|
self.check('---\n'
|
||||||
|
'boolean1: true\n'
|
||||||
|
'number1: 123\n'
|
||||||
|
'string1: foo\n'
|
||||||
|
'string2: "foo"\n' # fails
|
||||||
|
'string3: "true"\n'
|
||||||
|
'string4: "123"\n'
|
||||||
|
'string5: \'bar\'\n' # fails
|
||||||
|
'string6: !!str genericstring\n'
|
||||||
|
'string7: !!str 456\n'
|
||||||
|
'string8: !!str "quotedgenericstring"\n'
|
||||||
|
'binary: !!binary binstring\n'
|
||||||
|
'integer: !!int intstring\n'
|
||||||
|
'boolean2: !!bool boolstring\n'
|
||||||
|
'boolean3: !!bool "quotedboolstring"\n'
|
||||||
|
'block-seq:\n'
|
||||||
|
' - foo\n'
|
||||||
|
' - "foo"\n' # fails
|
||||||
|
'flow-seq: [foo, "foo"]\n' # fails
|
||||||
|
'flow-map: {a: foo, b: "foo"}\n', # fails
|
||||||
|
conf, problem1=(5, 10), problem2=(8, 10), problem3=(18, 5),
|
||||||
|
problem4=(19, 17), problem5=(20, 23))
|
||||||
|
self.check('---\n'
|
||||||
|
'multiline string 1: |\n'
|
||||||
|
' line 1\n'
|
||||||
|
' line 2\n'
|
||||||
|
'multiline string 2: >\n'
|
||||||
|
' word 1\n'
|
||||||
|
' word 2\n'
|
||||||
|
'multiline string 3:\n'
|
||||||
|
' word 1\n'
|
||||||
|
' word 2\n'
|
||||||
|
'multiline string 4:\n'
|
||||||
|
' "word 1\\\n' # fails
|
||||||
|
' word 2"\n',
|
||||||
|
conf, problem1=(12, 3))
|
||||||
|
|
||||||
|
def test_only_when_needed_single_quotes(self):
|
||||||
|
conf = ('quoted-strings: {quote-type: single,\n'
|
||||||
|
' required: only-when-needed}\n')
|
||||||
|
|
||||||
|
self.check('---\n'
|
||||||
|
'boolean1: true\n'
|
||||||
|
'number1: 123\n'
|
||||||
|
'string1: foo\n'
|
||||||
|
'string2: "foo"\n' # fails
|
||||||
|
'string3: "true"\n' # fails
|
||||||
|
'string4: "123"\n' # fails
|
||||||
|
'string5: \'bar\'\n' # fails
|
||||||
|
'string6: !!str genericstring\n'
|
||||||
|
'string7: !!str 456\n'
|
||||||
|
'string8: !!str "quotedgenericstring"\n'
|
||||||
|
'binary: !!binary binstring\n'
|
||||||
|
'integer: !!int intstring\n'
|
||||||
|
'boolean2: !!bool boolstring\n'
|
||||||
|
'boolean3: !!bool "quotedboolstring"\n'
|
||||||
|
'block-seq:\n'
|
||||||
|
' - foo\n'
|
||||||
|
' - "foo"\n' # fails
|
||||||
|
'flow-seq: [foo, "foo"]\n' # fails
|
||||||
|
'flow-map: {a: foo, b: "foo"}\n', # fails
|
||||||
|
conf, problem1=(5, 10), problem2=(6, 10), problem3=(7, 10),
|
||||||
|
problem4=(8, 10), problem5=(18, 5), problem6=(19, 17),
|
||||||
|
problem7=(20, 23))
|
||||||
|
self.check('---\n'
|
||||||
|
'multiline string 1: |\n'
|
||||||
|
' line 1\n'
|
||||||
|
' line 2\n'
|
||||||
|
'multiline string 2: >\n'
|
||||||
|
' word 1\n'
|
||||||
|
' word 2\n'
|
||||||
|
'multiline string 3:\n'
|
||||||
|
' word 1\n'
|
||||||
|
' word 2\n'
|
||||||
|
'multiline string 4:\n'
|
||||||
|
' "word 1\\\n' # fails
|
||||||
|
' word 2"\n',
|
||||||
|
conf, problem1=(12, 3))
|
||||||
|
|
||||||
|
def test_only_when_needed_corner_cases(self):
|
||||||
|
conf = 'quoted-strings: {required: only-when-needed}\n'
|
||||||
|
|
||||||
|
self.check('---\n'
|
||||||
|
'- ""\n'
|
||||||
|
'- "- item"\n'
|
||||||
|
'- "key: value"\n'
|
||||||
|
'- "%H:%M:%S"\n'
|
||||||
|
'- "%wheel ALL=(ALL) NOPASSWD: ALL"\n'
|
||||||
|
'- \'"quoted"\'\n'
|
||||||
|
'- "\'foo\' == \'bar\'"\n'
|
||||||
|
'- "\'Mac\' in ansible_facts.product_name"\n'
|
||||||
|
'- \'foo # bar\'\n',
|
||||||
|
conf)
|
||||||
|
self.check('---\n'
|
||||||
|
'k1: ""\n'
|
||||||
|
'k2: "- item"\n'
|
||||||
|
'k3: "key: value"\n'
|
||||||
|
'k4: "%H:%M:%S"\n'
|
||||||
|
'k5: "%wheel ALL=(ALL) NOPASSWD: ALL"\n'
|
||||||
|
'k6: \'"quoted"\'\n'
|
||||||
|
'k7: "\'foo\' == \'bar\'"\n'
|
||||||
|
'k8: "\'Mac\' in ansible_facts.product_name"\n',
|
||||||
|
conf)
|
||||||
|
|
||||||
|
self.check('---\n'
|
||||||
|
'- ---\n'
|
||||||
|
'- "---"\n' # fails
|
||||||
|
'- ----------\n'
|
||||||
|
'- "----------"\n' # fails
|
||||||
|
'- :wq\n'
|
||||||
|
'- ":wq"\n', # fails
|
||||||
|
conf, problem1=(3, 3), problem2=(5, 3), problem3=(7, 3))
|
||||||
|
self.check('---\n'
|
||||||
|
'k1: ---\n'
|
||||||
|
'k2: "---"\n' # fails
|
||||||
|
'k3: ----------\n'
|
||||||
|
'k4: "----------"\n' # fails
|
||||||
|
'k5: :wq\n'
|
||||||
|
'k6: ":wq"\n', # fails
|
||||||
|
conf, problem1=(3, 5), problem2=(5, 5), problem3=(7, 5))
|
||||||
|
|
||||||
|
def test_only_when_needed_extras(self):
|
||||||
|
conf = ('quoted-strings:\n'
|
||||||
|
' required: true\n'
|
||||||
|
' extra-allowed: [^http://]\n')
|
||||||
|
self.assertRaises(config.YamlLintConfigError, self.check, '', conf)
|
||||||
|
|
||||||
|
conf = ('quoted-strings:\n'
|
||||||
|
' required: true\n'
|
||||||
|
' extra-required: [^http://]\n')
|
||||||
|
self.assertRaises(config.YamlLintConfigError, self.check, '', conf)
|
||||||
|
|
||||||
|
conf = ('quoted-strings:\n'
|
||||||
|
' required: false\n'
|
||||||
|
' extra-allowed: [^http://]\n')
|
||||||
|
self.assertRaises(config.YamlLintConfigError, self.check, '', conf)
|
||||||
|
|
||||||
|
conf = ('quoted-strings:\n'
|
||||||
|
' required: true\n')
|
||||||
|
self.check('---\n'
|
||||||
|
'- 123\n'
|
||||||
|
'- "123"\n'
|
||||||
|
'- localhost\n' # fails
|
||||||
|
'- "localhost"\n'
|
||||||
|
'- http://localhost\n' # fails
|
||||||
|
'- "http://localhost"\n'
|
||||||
|
'- ftp://localhost\n' # fails
|
||||||
|
'- "ftp://localhost"\n',
|
||||||
|
conf, problem1=(4, 3), problem2=(6, 3), problem3=(8, 3))
|
||||||
|
|
||||||
|
conf = ('quoted-strings:\n'
|
||||||
|
' required: only-when-needed\n'
|
||||||
|
' extra-allowed: [^ftp://]\n'
|
||||||
|
' extra-required: [^http://]\n')
|
||||||
|
self.check('---\n'
|
||||||
|
'- 123\n'
|
||||||
|
'- "123"\n'
|
||||||
|
'- localhost\n'
|
||||||
|
'- "localhost"\n' # fails
|
||||||
|
'- http://localhost\n' # fails
|
||||||
|
'- "http://localhost"\n'
|
||||||
|
'- ftp://localhost\n'
|
||||||
|
'- "ftp://localhost"\n',
|
||||||
|
conf, problem1=(5, 3), problem2=(6, 3))
|
||||||
|
|
||||||
|
conf = ('quoted-strings:\n'
|
||||||
|
' required: false\n'
|
||||||
|
' extra-required: [^http://, ^ftp://]\n')
|
||||||
|
self.check('---\n'
|
||||||
|
'- 123\n'
|
||||||
|
'- "123"\n'
|
||||||
|
'- localhost\n'
|
||||||
|
'- "localhost"\n'
|
||||||
|
'- http://localhost\n' # fails
|
||||||
|
'- "http://localhost"\n'
|
||||||
|
'- ftp://localhost\n' # fails
|
||||||
|
'- "ftp://localhost"\n',
|
||||||
|
conf, problem1=(6, 3), problem2=(8, 3))
|
||||||
|
|
||||||
|
conf = ('quoted-strings:\n'
|
||||||
|
' required: only-when-needed\n'
|
||||||
|
' extra-allowed: [^ftp://, ";$", " "]\n')
|
||||||
|
self.check('---\n'
|
||||||
|
'- localhost\n'
|
||||||
|
'- "localhost"\n' # fails
|
||||||
|
'- ftp://localhost\n'
|
||||||
|
'- "ftp://localhost"\n'
|
||||||
|
'- i=i+1\n'
|
||||||
|
'- "i=i+1"\n' # fails
|
||||||
|
'- i=i+2;\n'
|
||||||
|
'- "i=i+2;"\n'
|
||||||
|
'- foo\n'
|
||||||
|
'- "foo"\n' # fails
|
||||||
|
'- foo bar\n'
|
||||||
|
'- "foo bar"\n',
|
||||||
|
conf, problem1=(3, 3), problem2=(7, 3), problem3=(11, 3))
|
||||||
|
|
||||||
|
def test_octal_values(self):
|
||||||
|
conf = 'quoted-strings: {required: true}\n'
|
||||||
|
|
||||||
|
self.check('---\n'
|
||||||
|
'- 100\n'
|
||||||
|
'- 0100\n'
|
||||||
|
'- 0o100\n'
|
||||||
|
'- 777\n'
|
||||||
|
'- 0777\n'
|
||||||
|
'- 0o777\n'
|
||||||
|
'- 800\n'
|
||||||
|
'- 0800\n'
|
||||||
|
'- 0o800\n'
|
||||||
|
'- "0800"\n'
|
||||||
|
'- "0o800"\n',
|
||||||
|
conf,
|
||||||
|
problem1=(9, 3), problem2=(10, 3))
|
||||||
|
|
||||||
|
def test_allow_quoted_quotes(self):
|
||||||
|
conf = ('quoted-strings: {quote-type: single,\n'
|
||||||
|
' required: false,\n'
|
||||||
|
' allow-quoted-quotes: false}\n')
|
||||||
|
self.check('---\n'
|
||||||
|
'foo1: "[barbaz]"\n' # fails
|
||||||
|
'foo2: "[bar\'baz]"\n', # fails
|
||||||
|
conf, problem1=(2, 7), problem2=(3, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: single,\n'
|
||||||
|
' required: false,\n'
|
||||||
|
' allow-quoted-quotes: true}\n')
|
||||||
|
self.check('---\n'
|
||||||
|
'foo1: "[barbaz]"\n' # fails
|
||||||
|
'foo2: "[bar\'baz]"\n',
|
||||||
|
conf, problem1=(2, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: single,\n'
|
||||||
|
' required: true,\n'
|
||||||
|
' allow-quoted-quotes: false}\n')
|
||||||
|
self.check('---\n'
|
||||||
|
'foo1: "[barbaz]"\n' # fails
|
||||||
|
'foo2: "[bar\'baz]"\n', # fails
|
||||||
|
conf, problem1=(2, 7), problem2=(3, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: single,\n'
|
||||||
|
' required: true,\n'
|
||||||
|
' allow-quoted-quotes: true}\n')
|
||||||
|
self.check('---\n'
|
||||||
|
'foo1: "[barbaz]"\n' # fails
|
||||||
|
'foo2: "[bar\'baz]"\n',
|
||||||
|
conf, problem1=(2, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: single,\n'
|
||||||
|
' required: only-when-needed,\n'
|
||||||
|
' allow-quoted-quotes: false}\n')
|
||||||
|
self.check('---\n'
|
||||||
|
'foo1: "[barbaz]"\n' # fails
|
||||||
|
'foo2: "[bar\'baz]"\n', # fails
|
||||||
|
conf, problem1=(2, 7), problem2=(3, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: single,\n'
|
||||||
|
' required: only-when-needed,\n'
|
||||||
|
' allow-quoted-quotes: true}\n')
|
||||||
|
self.check('---\n'
|
||||||
|
'foo1: "[barbaz]"\n' # fails
|
||||||
|
'foo2: "[bar\'baz]"\n',
|
||||||
|
conf, problem1=(2, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: double,\n'
|
||||||
|
' required: false,\n'
|
||||||
|
' allow-quoted-quotes: false}\n')
|
||||||
|
self.check("---\n"
|
||||||
|
"foo1: '[barbaz]'\n" # fails
|
||||||
|
"foo2: '[bar\"baz]'\n", # fails
|
||||||
|
conf, problem1=(2, 7), problem2=(3, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: double,\n'
|
||||||
|
' required: false,\n'
|
||||||
|
' allow-quoted-quotes: true}\n')
|
||||||
|
self.check("---\n"
|
||||||
|
"foo1: '[barbaz]'\n" # fails
|
||||||
|
"foo2: '[bar\"baz]'\n",
|
||||||
|
conf, problem1=(2, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: double,\n'
|
||||||
|
' required: true,\n'
|
||||||
|
' allow-quoted-quotes: false}\n')
|
||||||
|
self.check("---\n"
|
||||||
|
"foo1: '[barbaz]'\n" # fails
|
||||||
|
"foo2: '[bar\"baz]'\n", # fails
|
||||||
|
conf, problem1=(2, 7), problem2=(3, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: double,\n'
|
||||||
|
' required: true,\n'
|
||||||
|
' allow-quoted-quotes: true}\n')
|
||||||
|
self.check("---\n"
|
||||||
|
"foo1: '[barbaz]'\n" # fails
|
||||||
|
"foo2: '[bar\"baz]'\n",
|
||||||
|
conf, problem1=(2, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: double,\n'
|
||||||
|
' required: only-when-needed,\n'
|
||||||
|
' allow-quoted-quotes: false}\n')
|
||||||
|
self.check("---\n"
|
||||||
|
"foo1: '[barbaz]'\n" # fails
|
||||||
|
"foo2: '[bar\"baz]'\n", # fails
|
||||||
|
conf, problem1=(2, 7), problem2=(3, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: double,\n'
|
||||||
|
' required: only-when-needed,\n'
|
||||||
|
' allow-quoted-quotes: true}\n')
|
||||||
|
self.check("---\n"
|
||||||
|
"foo1: '[barbaz]'\n" # fails
|
||||||
|
"foo2: '[bar\"baz]'\n",
|
||||||
|
conf, problem1=(2, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: any}\n')
|
||||||
|
self.check("---\n"
|
||||||
|
"foo1: '[barbaz]'\n"
|
||||||
|
"foo2: '[bar\"baz]'\n",
|
||||||
|
conf)
|
@ -1,58 +1,35 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
|
yaml-files:
|
||||||
|
- '*.yaml'
|
||||||
|
- '*.yml'
|
||||||
|
- '.yamllint'
|
||||||
|
|
||||||
rules:
|
rules:
|
||||||
braces:
|
anchors: enable
|
||||||
min-spaces-inside: 0
|
braces: enable
|
||||||
max-spaces-inside: 0
|
brackets: enable
|
||||||
min-spaces-inside-empty: -1
|
colons: enable
|
||||||
max-spaces-inside-empty: -1
|
commas: enable
|
||||||
brackets:
|
|
||||||
min-spaces-inside: 0
|
|
||||||
max-spaces-inside: 0
|
|
||||||
min-spaces-inside-empty: -1
|
|
||||||
max-spaces-inside-empty: -1
|
|
||||||
colons:
|
|
||||||
max-spaces-before: 0
|
|
||||||
max-spaces-after: 1
|
|
||||||
commas:
|
|
||||||
max-spaces-before: 0
|
|
||||||
min-spaces-after: 1
|
|
||||||
max-spaces-after: 1
|
|
||||||
comments:
|
comments:
|
||||||
level: warning
|
level: warning
|
||||||
require-starting-space: true
|
|
||||||
min-spaces-from-content: 2
|
|
||||||
comments-indentation:
|
comments-indentation:
|
||||||
level: warning
|
level: warning
|
||||||
document-end: disable
|
document-end: disable
|
||||||
document-start:
|
document-start:
|
||||||
level: warning
|
level: warning
|
||||||
present: true
|
empty-lines: enable
|
||||||
empty-lines:
|
empty-values: disable
|
||||||
max: 2
|
float-values: disable
|
||||||
max-start: 0
|
hyphens: enable
|
||||||
max-end: 0
|
indentation: enable
|
||||||
empty-values:
|
|
||||||
forbid-in-block-mappings: false
|
|
||||||
forbid-in-flow-mappings: false
|
|
||||||
hyphens:
|
|
||||||
max-spaces-after: 1
|
|
||||||
indentation:
|
|
||||||
spaces: consistent
|
|
||||||
indent-sequences: true
|
|
||||||
check-multi-line-strings: false
|
|
||||||
key-duplicates: enable
|
key-duplicates: enable
|
||||||
key-ordering: disable
|
key-ordering: disable
|
||||||
line-length:
|
line-length: enable
|
||||||
max: 80
|
|
||||||
allow-non-breakable-words: true
|
|
||||||
allow-non-breakable-inline-mappings: false
|
|
||||||
new-line-at-end-of-file: enable
|
new-line-at-end-of-file: enable
|
||||||
new-lines:
|
new-lines: enable
|
||||||
type: unix
|
octal-values: disable
|
||||||
octal-values:
|
quoted-strings: disable
|
||||||
forbid-implicit-octal: false
|
|
||||||
forbid-explicit-octal: false
|
|
||||||
trailing-spaces: enable
|
trailing-spaces: enable
|
||||||
truthy:
|
truthy:
|
||||||
level: warning
|
level: warning
|
||||||
|
@ -0,0 +1,174 @@
|
|||||||
|
# Copyright (C) 2023 Adrien Vergé
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
"""
|
||||||
|
Use this rule to report duplicated anchors and aliases referencing undeclared
|
||||||
|
anchors.
|
||||||
|
|
||||||
|
.. rubric:: Options
|
||||||
|
|
||||||
|
* Set ``forbid-undeclared-aliases`` to ``true`` to avoid aliases that reference
|
||||||
|
an anchor that hasn't been declared (either not declared at all, or declared
|
||||||
|
later in the document).
|
||||||
|
* Set ``forbid-duplicated-anchors`` to ``true`` to avoid duplications of a same
|
||||||
|
anchor.
|
||||||
|
* Set ``forbid-unused-anchors`` to ``true`` to avoid anchors being declared but
|
||||||
|
not used anywhere in the YAML document via alias.
|
||||||
|
|
||||||
|
.. rubric:: Default values (when enabled)
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
rules:
|
||||||
|
anchors:
|
||||||
|
forbid-undeclared-aliases: true
|
||||||
|
forbid-duplicated-anchors: false
|
||||||
|
forbid-unused-anchors: false
|
||||||
|
|
||||||
|
.. rubric:: Examples
|
||||||
|
|
||||||
|
#. With ``anchors: {forbid-undeclared-aliases: true}``
|
||||||
|
|
||||||
|
the following code snippet would **PASS**:
|
||||||
|
::
|
||||||
|
|
||||||
|
---
|
||||||
|
- &anchor
|
||||||
|
foo: bar
|
||||||
|
- *anchor
|
||||||
|
|
||||||
|
the following code snippet would **FAIL**:
|
||||||
|
::
|
||||||
|
|
||||||
|
---
|
||||||
|
- &anchor
|
||||||
|
foo: bar
|
||||||
|
- *unknown
|
||||||
|
|
||||||
|
the following code snippet would **FAIL**:
|
||||||
|
::
|
||||||
|
|
||||||
|
---
|
||||||
|
- &anchor
|
||||||
|
foo: bar
|
||||||
|
- <<: *unknown
|
||||||
|
extra: value
|
||||||
|
|
||||||
|
#. With ``anchors: {forbid-duplicated-anchors: true}``
|
||||||
|
|
||||||
|
the following code snippet would **PASS**:
|
||||||
|
::
|
||||||
|
|
||||||
|
---
|
||||||
|
- &anchor1 Foo Bar
|
||||||
|
- &anchor2 [item 1, item 2]
|
||||||
|
|
||||||
|
the following code snippet would **FAIL**:
|
||||||
|
::
|
||||||
|
|
||||||
|
---
|
||||||
|
- &anchor Foo Bar
|
||||||
|
- &anchor [item 1, item 2]
|
||||||
|
|
||||||
|
#. With ``anchors: {forbid-unused-anchors: true}``
|
||||||
|
|
||||||
|
the following code snippet would **PASS**:
|
||||||
|
::
|
||||||
|
|
||||||
|
---
|
||||||
|
- &anchor
|
||||||
|
foo: bar
|
||||||
|
- *anchor
|
||||||
|
|
||||||
|
the following code snippet would **FAIL**:
|
||||||
|
::
|
||||||
|
|
||||||
|
---
|
||||||
|
- &anchor
|
||||||
|
foo: bar
|
||||||
|
- items:
|
||||||
|
- item1
|
||||||
|
- item2
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
from yamllint.linter import LintProblem
|
||||||
|
|
||||||
|
|
||||||
|
ID = 'anchors'
|
||||||
|
TYPE = 'token'
|
||||||
|
CONF = {'forbid-undeclared-aliases': bool,
|
||||||
|
'forbid-duplicated-anchors': bool,
|
||||||
|
'forbid-unused-anchors': bool}
|
||||||
|
DEFAULT = {'forbid-undeclared-aliases': True,
|
||||||
|
'forbid-duplicated-anchors': False,
|
||||||
|
'forbid-unused-anchors': False}
|
||||||
|
|
||||||
|
|
||||||
|
def check(conf, token, prev, next, nextnext, context):
|
||||||
|
if (conf['forbid-undeclared-aliases'] or
|
||||||
|
conf['forbid-duplicated-anchors'] or
|
||||||
|
conf['forbid-unused-anchors']):
|
||||||
|
if isinstance(token, (
|
||||||
|
yaml.StreamStartToken,
|
||||||
|
yaml.DocumentStartToken,
|
||||||
|
yaml.DocumentEndToken)):
|
||||||
|
context['anchors'] = {}
|
||||||
|
|
||||||
|
if (conf['forbid-undeclared-aliases'] and
|
||||||
|
isinstance(token, yaml.AliasToken) and
|
||||||
|
token.value not in context['anchors']):
|
||||||
|
yield LintProblem(
|
||||||
|
token.start_mark.line + 1, token.start_mark.column + 1,
|
||||||
|
f'found undeclared alias "{token.value}"')
|
||||||
|
|
||||||
|
if (conf['forbid-duplicated-anchors'] and
|
||||||
|
isinstance(token, yaml.AnchorToken) and
|
||||||
|
token.value in context['anchors']):
|
||||||
|
yield LintProblem(
|
||||||
|
token.start_mark.line + 1, token.start_mark.column + 1,
|
||||||
|
f'found duplicated anchor "{token.value}"')
|
||||||
|
|
||||||
|
if conf['forbid-unused-anchors']:
|
||||||
|
# Unused anchors can only be detected at the end of Document.
|
||||||
|
# End of document can be either
|
||||||
|
# - end of stream
|
||||||
|
# - end of document sign '...'
|
||||||
|
# - start of a new document sign '---'
|
||||||
|
# If next token indicates end of document,
|
||||||
|
# check if the anchors have been used or not.
|
||||||
|
# If they haven't been used, report problem on those anchors.
|
||||||
|
if isinstance(next, (yaml.StreamEndToken,
|
||||||
|
yaml.DocumentStartToken,
|
||||||
|
yaml.DocumentEndToken)):
|
||||||
|
for anchor, info in context['anchors'].items():
|
||||||
|
if not info['used']:
|
||||||
|
yield LintProblem(info['line'] + 1,
|
||||||
|
info['column'] + 1,
|
||||||
|
f'found unused anchor "{anchor}"')
|
||||||
|
elif isinstance(token, yaml.AliasToken):
|
||||||
|
context['anchors'].get(token.value, {})['used'] = True
|
||||||
|
|
||||||
|
if (conf['forbid-undeclared-aliases'] or
|
||||||
|
conf['forbid-duplicated-anchors'] or
|
||||||
|
conf['forbid-unused-anchors']):
|
||||||
|
if isinstance(token, yaml.AnchorToken):
|
||||||
|
context['anchors'][token.value] = {
|
||||||
|
'line': token.start_mark.line,
|
||||||
|
'column': token.start_mark.column,
|
||||||
|
'used': False
|
||||||
|
}
|
@ -0,0 +1,158 @@
|
|||||||
|
# Copyright (C) 2022 the yamllint contributors
|
||||||
|
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
"""
|
||||||
|
Use this rule to limit the permitted values for floating-point numbers.
|
||||||
|
YAML permits three classes of float expressions: approximation to real numbers,
|
||||||
|
positive and negative infinity and "not a number".
|
||||||
|
|
||||||
|
.. rubric:: Options
|
||||||
|
|
||||||
|
* Use ``require-numeral-before-decimal`` to require floats to start
|
||||||
|
with a numeral (ex ``0.0`` instead of ``.0``).
|
||||||
|
* Use ``forbid-scientific-notation`` to forbid scientific notation.
|
||||||
|
* Use ``forbid-nan`` to forbid NaN (not a number) values.
|
||||||
|
* Use ``forbid-inf`` to forbid infinite values.
|
||||||
|
|
||||||
|
.. rubric:: Default values (when enabled)
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
rules:
|
||||||
|
float-values:
|
||||||
|
forbid-inf: false
|
||||||
|
forbid-nan: false
|
||||||
|
forbid-scientific-notation: false
|
||||||
|
require-numeral-before-decimal: false
|
||||||
|
|
||||||
|
.. rubric:: Examples
|
||||||
|
|
||||||
|
#. With ``float-values: {require-numeral-before-decimal: true}``
|
||||||
|
|
||||||
|
the following code snippets would **PASS**:
|
||||||
|
::
|
||||||
|
|
||||||
|
anemometer:
|
||||||
|
angle: 0.0
|
||||||
|
|
||||||
|
the following code snippets would **FAIL**:
|
||||||
|
::
|
||||||
|
|
||||||
|
anemometer:
|
||||||
|
angle: .0
|
||||||
|
|
||||||
|
#. With ``float-values: {forbid-scientific-notation: true}``
|
||||||
|
|
||||||
|
the following code snippets would **PASS**:
|
||||||
|
::
|
||||||
|
|
||||||
|
anemometer:
|
||||||
|
angle: 0.00001
|
||||||
|
|
||||||
|
the following code snippets would **FAIL**:
|
||||||
|
::
|
||||||
|
|
||||||
|
anemometer:
|
||||||
|
angle: 10e-6
|
||||||
|
|
||||||
|
#. With ``float-values: {forbid-nan: true}``
|
||||||
|
|
||||||
|
the following code snippets would **FAIL**:
|
||||||
|
::
|
||||||
|
|
||||||
|
anemometer:
|
||||||
|
angle: .NaN
|
||||||
|
|
||||||
|
#. With ``float-values: {forbid-inf: true}``
|
||||||
|
|
||||||
|
the following code snippets would **FAIL**:
|
||||||
|
::
|
||||||
|
|
||||||
|
anemometer:
|
||||||
|
angle: .inf
|
||||||
|
"""
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
from yamllint.linter import LintProblem
|
||||||
|
|
||||||
|
|
||||||
|
ID = 'float-values'
|
||||||
|
TYPE = 'token'
|
||||||
|
CONF = {
|
||||||
|
'require-numeral-before-decimal': bool,
|
||||||
|
'forbid-scientific-notation': bool,
|
||||||
|
'forbid-nan': bool,
|
||||||
|
'forbid-inf': bool,
|
||||||
|
}
|
||||||
|
DEFAULT = {
|
||||||
|
'require-numeral-before-decimal': False,
|
||||||
|
'forbid-scientific-notation': False,
|
||||||
|
'forbid-nan': False,
|
||||||
|
'forbid-inf': False,
|
||||||
|
}
|
||||||
|
|
||||||
|
IS_NUMERAL_BEFORE_DECIMAL_PATTERN = (
|
||||||
|
re.compile('[-+]?(\\.[0-9]+)([eE][-+]?[0-9]+)?$')
|
||||||
|
)
|
||||||
|
IS_SCIENTIFIC_NOTATION_PATTERN = re.compile(
|
||||||
|
'[-+]?(\\.[0-9]+|[0-9]+(\\.[0-9]*)?)([eE][-+]?[0-9]+)$'
|
||||||
|
)
|
||||||
|
IS_INF_PATTERN = re.compile('[-+]?(\\.inf|\\.Inf|\\.INF)$')
|
||||||
|
IS_NAN_PATTERN = re.compile('(\\.nan|\\.NaN|\\.NAN)$')
|
||||||
|
|
||||||
|
|
||||||
|
def check(conf, token, prev, next, nextnext, context):
|
||||||
|
if prev and isinstance(prev, yaml.tokens.TagToken):
|
||||||
|
return
|
||||||
|
if not isinstance(token, yaml.tokens.ScalarToken):
|
||||||
|
return
|
||||||
|
if token.style:
|
||||||
|
return
|
||||||
|
val = token.value
|
||||||
|
|
||||||
|
if conf['forbid-nan'] and IS_NAN_PATTERN.match(val):
|
||||||
|
yield LintProblem(
|
||||||
|
token.start_mark.line + 1,
|
||||||
|
token.start_mark.column + 1,
|
||||||
|
f'forbidden not a number value "{token.value}"',
|
||||||
|
)
|
||||||
|
|
||||||
|
if conf['forbid-inf'] and IS_INF_PATTERN.match(val):
|
||||||
|
yield LintProblem(
|
||||||
|
token.start_mark.line + 1,
|
||||||
|
token.start_mark.column + 1,
|
||||||
|
f'forbidden infinite value "{token.value}"',
|
||||||
|
)
|
||||||
|
|
||||||
|
if conf[
|
||||||
|
'forbid-scientific-notation'
|
||||||
|
] and IS_SCIENTIFIC_NOTATION_PATTERN.match(val):
|
||||||
|
yield LintProblem(
|
||||||
|
token.start_mark.line + 1,
|
||||||
|
token.start_mark.column + 1,
|
||||||
|
f'forbidden scientific notation "{token.value}"',
|
||||||
|
)
|
||||||
|
|
||||||
|
if conf[
|
||||||
|
'require-numeral-before-decimal'
|
||||||
|
] and IS_NUMERAL_BEFORE_DECIMAL_PATTERN.match(val):
|
||||||
|
yield LintProblem(
|
||||||
|
token.start_mark.line + 1,
|
||||||
|
token.start_mark.column + 1,
|
||||||
|
f'forbidden decimal missing 0 prefix "{token.value}"',
|
||||||
|
)
|
@ -0,0 +1,289 @@
|
|||||||
|
# Copyright (C) 2018 ClearScore
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
"""
|
||||||
|
Use this rule to forbid any string values that are not quoted, or to prevent
|
||||||
|
quoted strings without needing it. You can also enforce the type of the quote
|
||||||
|
used.
|
||||||
|
|
||||||
|
.. rubric:: Options
|
||||||
|
|
||||||
|
* ``quote-type`` defines allowed quotes: ``single``, ``double`` or ``any``
|
||||||
|
(default).
|
||||||
|
* ``required`` defines whether using quotes in string values is required
|
||||||
|
(``true``, default) or not (``false``), or only allowed when really needed
|
||||||
|
(``only-when-needed``).
|
||||||
|
* ``extra-required`` is a list of PCRE regexes to force string values to be
|
||||||
|
quoted, if they match any regex. This option can only be used with
|
||||||
|
``required: false`` and ``required: only-when-needed``.
|
||||||
|
* ``extra-allowed`` is a list of PCRE regexes to allow quoted string values,
|
||||||
|
even if ``required: only-when-needed`` is set.
|
||||||
|
* ``allow-quoted-quotes`` allows (``true``) using disallowed quotes for strings
|
||||||
|
with allowed quotes inside. Default ``false``.
|
||||||
|
|
||||||
|
**Note**: Multi-line strings (with ``|`` or ``>``) will not be checked.
|
||||||
|
|
||||||
|
.. rubric:: Default values (when enabled)
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
rules:
|
||||||
|
quoted-strings:
|
||||||
|
quote-type: any
|
||||||
|
required: true
|
||||||
|
extra-required: []
|
||||||
|
extra-allowed: []
|
||||||
|
allow-quoted-quotes: false
|
||||||
|
|
||||||
|
.. rubric:: Examples
|
||||||
|
|
||||||
|
#. With ``quoted-strings: {quote-type: any, required: true}``
|
||||||
|
|
||||||
|
the following code snippet would **PASS**:
|
||||||
|
::
|
||||||
|
|
||||||
|
foo: "bar"
|
||||||
|
bar: 'foo'
|
||||||
|
number: 123
|
||||||
|
boolean: true
|
||||||
|
|
||||||
|
the following code snippet would **FAIL**:
|
||||||
|
::
|
||||||
|
|
||||||
|
foo: bar
|
||||||
|
|
||||||
|
#. With ``quoted-strings: {quote-type: single, required: only-when-needed}``
|
||||||
|
|
||||||
|
the following code snippet would **PASS**:
|
||||||
|
::
|
||||||
|
|
||||||
|
foo: bar
|
||||||
|
bar: foo
|
||||||
|
not_number: '123'
|
||||||
|
not_boolean: 'true'
|
||||||
|
not_comment: '# comment'
|
||||||
|
not_list: '[1, 2, 3]'
|
||||||
|
not_map: '{a: 1, b: 2}'
|
||||||
|
|
||||||
|
the following code snippet would **FAIL**:
|
||||||
|
::
|
||||||
|
|
||||||
|
foo: 'bar'
|
||||||
|
|
||||||
|
#. With ``quoted-strings: {required: false, extra-required: [^http://,
|
||||||
|
^ftp://]}``
|
||||||
|
|
||||||
|
the following code snippet would **PASS**:
|
||||||
|
::
|
||||||
|
|
||||||
|
- localhost
|
||||||
|
- "localhost"
|
||||||
|
- "http://localhost"
|
||||||
|
- "ftp://localhost"
|
||||||
|
|
||||||
|
the following code snippet would **FAIL**:
|
||||||
|
::
|
||||||
|
|
||||||
|
- http://localhost
|
||||||
|
- ftp://localhost
|
||||||
|
|
||||||
|
#. With ``quoted-strings: {required: only-when-needed, extra-allowed:
|
||||||
|
[^http://, ^ftp://], extra-required: [QUOTED]}``
|
||||||
|
|
||||||
|
the following code snippet would **PASS**:
|
||||||
|
::
|
||||||
|
|
||||||
|
- localhost
|
||||||
|
- "http://localhost"
|
||||||
|
- "ftp://localhost"
|
||||||
|
- "this is a string that needs to be QUOTED"
|
||||||
|
|
||||||
|
the following code snippet would **FAIL**:
|
||||||
|
::
|
||||||
|
|
||||||
|
- "localhost"
|
||||||
|
- this is a string that needs to be QUOTED
|
||||||
|
|
||||||
|
#. With ``quoted-strings: {quote-type: double, allow-quoted-quotes: false}``
|
||||||
|
|
||||||
|
the following code snippet would **PASS**:
|
||||||
|
::
|
||||||
|
|
||||||
|
foo: "bar\\"baz"
|
||||||
|
|
||||||
|
the following code snippet would **FAIL**:
|
||||||
|
::
|
||||||
|
|
||||||
|
foo: 'bar"baz'
|
||||||
|
|
||||||
|
#. With ``quoted-strings: {quote-type: double, allow-quoted-quotes: true}``
|
||||||
|
|
||||||
|
the following code snippet would **PASS**:
|
||||||
|
::
|
||||||
|
|
||||||
|
foo: 'bar"baz'
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
from yamllint.linter import LintProblem
|
||||||
|
|
||||||
|
ID = 'quoted-strings'
|
||||||
|
TYPE = 'token'
|
||||||
|
CONF = {'quote-type': ('any', 'single', 'double'),
|
||||||
|
'required': (True, False, 'only-when-needed'),
|
||||||
|
'extra-required': [str],
|
||||||
|
'extra-allowed': [str],
|
||||||
|
'allow-quoted-quotes': bool}
|
||||||
|
DEFAULT = {'quote-type': 'any',
|
||||||
|
'required': True,
|
||||||
|
'extra-required': [],
|
||||||
|
'extra-allowed': [],
|
||||||
|
'allow-quoted-quotes': False}
|
||||||
|
|
||||||
|
|
||||||
|
def VALIDATE(conf):
|
||||||
|
if conf['required'] is True and len(conf['extra-allowed']) > 0:
|
||||||
|
return 'cannot use both "required: true" and "extra-allowed"'
|
||||||
|
if conf['required'] is True and len(conf['extra-required']) > 0:
|
||||||
|
return 'cannot use both "required: true" and "extra-required"'
|
||||||
|
if conf['required'] is False and len(conf['extra-allowed']) > 0:
|
||||||
|
return 'cannot use both "required: false" and "extra-allowed"'
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_SCALAR_TAG = 'tag:yaml.org,2002:str'
|
||||||
|
|
||||||
|
# https://stackoverflow.com/a/36514274
|
||||||
|
yaml.resolver.Resolver.add_implicit_resolver(
|
||||||
|
'tag:yaml.org,2002:int',
|
||||||
|
re.compile(r'''^(?:[-+]?0b[0-1_]+
|
||||||
|
|[-+]?0o?[0-7_]+
|
||||||
|
|[-+]?0[0-7_]+
|
||||||
|
|[-+]?(?:0|[1-9][0-9_]*)
|
||||||
|
|[-+]?0x[0-9a-fA-F_]+
|
||||||
|
|[-+]?[1-9][0-9_]*(?::[0-5]?[0-9])+)$''', re.X),
|
||||||
|
list('-+0123456789'))
|
||||||
|
|
||||||
|
|
||||||
|
def _quote_match(quote_type, token_style):
|
||||||
|
return ((quote_type == 'any') or
|
||||||
|
(quote_type == 'single' and token_style == "'") or
|
||||||
|
(quote_type == 'double' and token_style == '"'))
|
||||||
|
|
||||||
|
|
||||||
|
def _quotes_are_needed(string):
|
||||||
|
loader = yaml.BaseLoader('key: ' + string)
|
||||||
|
# Remove the 5 first tokens corresponding to 'key: ' (StreamStartToken,
|
||||||
|
# BlockMappingStartToken, KeyToken, ScalarToken(value=key), ValueToken)
|
||||||
|
for _ in range(5):
|
||||||
|
loader.get_token()
|
||||||
|
try:
|
||||||
|
a, b = loader.get_token(), loader.get_token()
|
||||||
|
if (isinstance(a, yaml.ScalarToken) and a.style is None and
|
||||||
|
isinstance(b, yaml.BlockEndToken) and a.value == string):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
except yaml.scanner.ScannerError:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def _has_quoted_quotes(token):
|
||||||
|
return ((not token.plain) and
|
||||||
|
((token.style == "'" and '"' in token.value) or
|
||||||
|
(token.style == '"' and "'" in token.value)))
|
||||||
|
|
||||||
|
|
||||||
|
def check(conf, token, prev, next, nextnext, context):
|
||||||
|
if not (isinstance(token, yaml.tokens.ScalarToken) and
|
||||||
|
isinstance(prev, (yaml.BlockEntryToken, yaml.FlowEntryToken,
|
||||||
|
yaml.FlowSequenceStartToken, yaml.TagToken,
|
||||||
|
yaml.ValueToken))):
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
# Ignore explicit types, e.g. !!str testtest or !!int 42
|
||||||
|
if (prev and isinstance(prev, yaml.tokens.TagToken) and
|
||||||
|
prev.value[0] == '!!'):
|
||||||
|
return
|
||||||
|
|
||||||
|
# Ignore numbers, booleans, etc.
|
||||||
|
resolver = yaml.resolver.Resolver()
|
||||||
|
tag = resolver.resolve(yaml.nodes.ScalarNode, token.value, (True, False))
|
||||||
|
if token.plain and tag != DEFAULT_SCALAR_TAG:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Ignore multi-line strings
|
||||||
|
if not token.plain and token.style in ("|", ">"):
|
||||||
|
return
|
||||||
|
|
||||||
|
quote_type = conf['quote-type']
|
||||||
|
|
||||||
|
msg = None
|
||||||
|
if conf['required'] is True:
|
||||||
|
|
||||||
|
# Quotes are mandatory and need to match config
|
||||||
|
if (token.style is None or
|
||||||
|
not (_quote_match(quote_type, token.style) or
|
||||||
|
(conf['allow-quoted-quotes'] and _has_quoted_quotes(token)))):
|
||||||
|
msg = "string value is not quoted with %s quotes" % quote_type
|
||||||
|
|
||||||
|
elif conf['required'] is False:
|
||||||
|
|
||||||
|
# Quotes are not mandatory but when used need to match config
|
||||||
|
if (token.style and
|
||||||
|
not _quote_match(quote_type, token.style) and
|
||||||
|
not (conf['allow-quoted-quotes'] and
|
||||||
|
_has_quoted_quotes(token))):
|
||||||
|
msg = "string value is not quoted with %s quotes" % quote_type
|
||||||
|
|
||||||
|
elif not token.style:
|
||||||
|
is_extra_required = any(re.search(r, token.value)
|
||||||
|
for r in conf['extra-required'])
|
||||||
|
if is_extra_required:
|
||||||
|
msg = "string value is not quoted"
|
||||||
|
|
||||||
|
elif conf['required'] == 'only-when-needed':
|
||||||
|
|
||||||
|
# Quotes are not strictly needed here
|
||||||
|
if (token.style and tag == DEFAULT_SCALAR_TAG and token.value and
|
||||||
|
not _quotes_are_needed(token.value)):
|
||||||
|
is_extra_required = any(re.search(r, token.value)
|
||||||
|
for r in conf['extra-required'])
|
||||||
|
is_extra_allowed = any(re.search(r, token.value)
|
||||||
|
for r in conf['extra-allowed'])
|
||||||
|
if not (is_extra_required or is_extra_allowed):
|
||||||
|
msg = "string value is redundantly quoted with %s quotes" % (
|
||||||
|
quote_type)
|
||||||
|
|
||||||
|
# But when used need to match config
|
||||||
|
elif (token.style and
|
||||||
|
not _quote_match(quote_type, token.style) and
|
||||||
|
not (conf['allow-quoted-quotes'] and _has_quoted_quotes(token))):
|
||||||
|
msg = "string value is not quoted with %s quotes" % quote_type
|
||||||
|
|
||||||
|
elif not token.style:
|
||||||
|
is_extra_required = len(conf['extra-required']) and any(
|
||||||
|
re.search(r, token.value) for r in conf['extra-required'])
|
||||||
|
if is_extra_required:
|
||||||
|
msg = "string value is not quoted"
|
||||||
|
|
||||||
|
if msg is not None:
|
||||||
|
yield LintProblem(
|
||||||
|
token.start_mark.line + 1,
|
||||||
|
token.start_mark.column + 1,
|
||||||
|
msg)
|
Loading…
Reference in New Issue