Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da3788e95a | ||
|
|
fb400dc64b | ||
|
|
92324ae730 | ||
|
|
7359785ea0 | ||
|
|
579a975b70 | ||
|
|
f3d9196aa0 | ||
|
|
881d301883 | ||
|
|
b62b424dd4 |
@@ -1,6 +1,20 @@
|
|||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
1.19.0 (2019-11-19)
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
- Allow disabling all checks for a file with ``# yamllint disable-file``
|
||||||
|
|
||||||
|
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)
|
1.17.0 (2019-08-12)
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
If ``-c`` is not provided, yamllint will look for a configuration file in the
|
||||||
following locations (by order of preference):
|
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``
|
- ``$XDG_CONFIG_HOME/yamllint/config``
|
||||||
- ``~/.config/yamllint/config``
|
- ``~/.config/yamllint/config``
|
||||||
|
|
||||||
@@ -124,8 +125,9 @@ configuration option. The default is:
|
|||||||
.. code-block:: yaml
|
.. code-block:: yaml
|
||||||
|
|
||||||
yaml-files:
|
yaml-files:
|
||||||
- '*.yaml'
|
- '*.yaml'
|
||||||
- '*.yml'
|
- '*.yml'
|
||||||
|
- '.yamllint'
|
||||||
|
|
||||||
The same rules as for ignoring paths apply (``.gitignore``-style path pattern,
|
The same rules as for ignoring paths apply (``.gitignore``-style path pattern,
|
||||||
see below).
|
see below).
|
||||||
|
|||||||
@@ -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:
|
If you need to disable multiple rules, it is allowed to chain rules like this:
|
||||||
``# yamllint disable rule:hyphens rule:commas rule:indentation``.
|
``# 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
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ Here is an example, to add in your .pre-commit-config.yaml
|
|||||||
.. code:: 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
|
- repo: https://github.com/adrienverge/yamllint.git
|
||||||
sha: v1.8.1
|
rev: v1.17.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: yamllint
|
- id: yamllint
|
||||||
|
args: [-c=/path/to/.yamllint]
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ class OctalValuesTestCase(RuleTestCase):
|
|||||||
self.check('user-city: 0o10', conf)
|
self.check('user-city: 0o10', conf)
|
||||||
|
|
||||||
def test_implicit_octal_values(self):
|
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'
|
'new-line-at-end-of-file: disable\n'
|
||||||
'document-start: disable\n')
|
'document-start: disable\n')
|
||||||
self.check('user-city: 010', conf, problem=(1, 15))
|
self.check('user-city: 010', conf, problem=(1, 15))
|
||||||
@@ -50,7 +52,9 @@ class OctalValuesTestCase(RuleTestCase):
|
|||||||
' - 0e3\n', conf)
|
' - 0e3\n', conf)
|
||||||
|
|
||||||
def test_explicit_octal_values(self):
|
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'
|
'new-line-at-end-of-file: disable\n'
|
||||||
'document-start: disable\n')
|
'document-start: disable\n')
|
||||||
self.check('user-city: 0o10', conf, problem=(1, 16))
|
self.check('user-city: 0o10', conf, problem=(1, 16))
|
||||||
|
|||||||
@@ -448,11 +448,13 @@ class IgnorePathConfigTestCase(unittest.TestCase):
|
|||||||
out = sys.stdout.getvalue()
|
out = sys.stdout.getvalue()
|
||||||
out = '\n'.join(sorted(out.splitlines()))
|
out = '\n'.join(sorted(out.splitlines()))
|
||||||
|
|
||||||
|
docstart = '[warning] missing document start "---" (document-start)'
|
||||||
keydup = '[error] duplication of key "key" in mapping (key-duplicates)'
|
keydup = '[error] duplication of key "key" in mapping (key-duplicates)'
|
||||||
trailing = '[error] trailing spaces (trailing-spaces)'
|
trailing = '[error] trailing spaces (trailing-spaces)'
|
||||||
hyphen = '[error] too many spaces after hyphen (hyphens)'
|
hyphen = '[error] too many spaces after hyphen (hyphens)'
|
||||||
|
|
||||||
self.assertEqual(out, '\n'.join((
|
self.assertEqual(out, '\n'.join((
|
||||||
|
'./.yamllint:1:1: ' + docstart,
|
||||||
'./bin/file.lint-me-anyway.yaml:3:3: ' + keydup,
|
'./bin/file.lint-me-anyway.yaml:3:3: ' + keydup,
|
||||||
'./bin/file.lint-me-anyway.yaml:4:17: ' + trailing,
|
'./bin/file.lint-me-anyway.yaml:4:17: ' + trailing,
|
||||||
'./bin/file.lint-me-anyway.yaml:5:5: ' + hyphen,
|
'./bin/file.lint-me-anyway.yaml:5:5: ' + hyphen,
|
||||||
|
|||||||
@@ -302,3 +302,104 @@ class YamllintDirectivesTestCase(RuleTestCase):
|
|||||||
' c: [x]\n',
|
' c: [x]\n',
|
||||||
conf,
|
conf,
|
||||||
problem=(6, 2, 'comments-indentation'))
|
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)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ indentation, etc."""
|
|||||||
|
|
||||||
|
|
||||||
APP_NAME = 'yamllint'
|
APP_NAME = 'yamllint'
|
||||||
APP_VERSION = '1.17.0'
|
APP_VERSION = '1.19.0'
|
||||||
APP_DESCRIPTION = __doc__
|
APP_DESCRIPTION = __doc__
|
||||||
|
|
||||||
__author__ = u'Adrien Vergé'
|
__author__ = u'Adrien Vergé'
|
||||||
|
|||||||
@@ -154,6 +154,10 @@ def run(argv=None):
|
|||||||
conf = YamlLintConfig(file=args.config_file)
|
conf = YamlLintConfig(file=args.config_file)
|
||||||
elif os.path.isfile('.yamllint'):
|
elif os.path.isfile('.yamllint'):
|
||||||
conf = YamlLintConfig(file='.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):
|
elif os.path.isfile(user_global_config):
|
||||||
conf = YamlLintConfig(file=user_global_config)
|
conf = YamlLintConfig(file=user_global_config)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
yaml-files:
|
yaml-files:
|
||||||
- '*.yaml'
|
- '*.yaml'
|
||||||
- '*.yml'
|
- '*.yml'
|
||||||
|
- '.yamllint'
|
||||||
|
|
||||||
rules:
|
rules:
|
||||||
braces: enable
|
braces: enable
|
||||||
@@ -17,7 +18,7 @@ rules:
|
|||||||
document-start:
|
document-start:
|
||||||
level: warning
|
level: warning
|
||||||
empty-lines: enable
|
empty-lines: enable
|
||||||
empty-values: enable
|
empty-values: disable
|
||||||
hyphens: enable
|
hyphens: enable
|
||||||
indentation: enable
|
indentation: enable
|
||||||
key-duplicates: enable
|
key-duplicates: enable
|
||||||
@@ -25,7 +26,7 @@ rules:
|
|||||||
line-length: enable
|
line-length: enable
|
||||||
new-line-at-end-of-file: enable
|
new-line-at-end-of-file: enable
|
||||||
new-lines: enable
|
new-lines: enable
|
||||||
octal-values: enable
|
octal-values: disable
|
||||||
quoted-strings: disable
|
quoted-strings: disable
|
||||||
trailing-spaces: enable
|
trailing-spaces: enable
|
||||||
truthy:
|
truthy:
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class YamlLintConfig(object):
|
|||||||
self.ignore = None
|
self.ignore = None
|
||||||
|
|
||||||
self.yaml_files = pathspec.PathSpec.from_lines(
|
self.yaml_files = pathspec.PathSpec.from_lines(
|
||||||
'gitwildmatch', ['*.yaml', '*.yml'])
|
'gitwildmatch', ['*.yaml', '*.yml', '.yamllint'])
|
||||||
|
|
||||||
if file is not None:
|
if file is not None:
|
||||||
with open(file) as f:
|
with open(file) as f:
|
||||||
|
|||||||
@@ -189,6 +189,10 @@ def _run(buffer, conf, filepath):
|
|||||||
assert hasattr(buffer, '__getitem__'), \
|
assert hasattr(buffer, '__getitem__'), \
|
||||||
'_run() argument must be a buffer, not a stream'
|
'_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
|
# If the document contains a syntax error, save it and yield it at the
|
||||||
# right line
|
# right line
|
||||||
syntax_error = get_syntax_error(buffer)
|
syntax_error = get_syntax_error(buffer)
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ ID = 'empty-values'
|
|||||||
TYPE = 'token'
|
TYPE = 'token'
|
||||||
CONF = {'forbid-in-block-mappings': bool,
|
CONF = {'forbid-in-block-mappings': bool,
|
||||||
'forbid-in-flow-mappings': bool}
|
'forbid-in-flow-mappings': bool}
|
||||||
DEFAULT = {'forbid-in-block-mappings': False,
|
DEFAULT = {'forbid-in-block-mappings': True,
|
||||||
'forbid-in-flow-mappings': False}
|
'forbid-in-flow-mappings': True}
|
||||||
|
|
||||||
|
|
||||||
def check(conf, token, prev, next, nextnext, context):
|
def check(conf, token, prev, next, nextnext, context):
|
||||||
|
|||||||
@@ -66,8 +66,8 @@ ID = 'octal-values'
|
|||||||
TYPE = 'token'
|
TYPE = 'token'
|
||||||
CONF = {'forbid-implicit-octal': bool,
|
CONF = {'forbid-implicit-octal': bool,
|
||||||
'forbid-explicit-octal': bool}
|
'forbid-explicit-octal': bool}
|
||||||
DEFAULT = {'forbid-implicit-octal': False,
|
DEFAULT = {'forbid-implicit-octal': True,
|
||||||
'forbid-explicit-octal': False}
|
'forbid-explicit-octal': True}
|
||||||
|
|
||||||
|
|
||||||
def check(conf, token, prev, next, nextnext, context):
|
def check(conf, token, prev, next, nextnext, context):
|
||||||
|
|||||||
Reference in New Issue
Block a user