|
|
@ -19,8 +19,15 @@ Use this rule to control the position and formatting of comments.
|
|
|
|
|
|
|
|
|
|
|
|
.. rubric:: Options
|
|
|
|
.. rubric:: Options
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# cloud-init expects the first line to be #cloud-config and this conflicts with
|
|
|
|
|
|
|
|
# the rules.comments.require-starting-space directive.
|
|
|
|
|
|
|
|
# See https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.comments
|
|
|
|
|
|
|
|
|
|
|
|
* Use ``require-starting-space`` to require a space character right after the
|
|
|
|
* Use ``require-starting-space`` to require a space character right after the
|
|
|
|
``#``. Set to ``true`` to enable, ``false`` to disable.
|
|
|
|
``#``. Set to ``true`` to enable, ``false`` to disable.
|
|
|
|
|
|
|
|
* Use ``ignore-cloud-init-cloud-config`` to ignore a
|
|
|
|
|
|
|
|
`#cloud-config cloud-init directive <https://cloudinit.readthedocs.io/en/latest/topics/format.html#cloud-config-data>`_ at the beginning of
|
|
|
|
|
|
|
|
the file when ``require-starting-space`` is set.
|
|
|
|
* Use ``ignore-shebangs`` to ignore a
|
|
|
|
* Use ``ignore-shebangs`` to ignore a
|
|
|
|
`shebang <https://en.wikipedia.org/wiki/Shebang_(Unix)>`_ at the beginning of
|
|
|
|
`shebang <https://en.wikipedia.org/wiki/Shebang_(Unix)>`_ at the beginning of
|
|
|
|
the file when ``require-starting-space`` is set.
|
|
|
|
the file when ``require-starting-space`` is set.
|
|
|
@ -82,9 +89,11 @@ from yamllint.linter import LintProblem
|
|
|
|
ID = 'comments'
|
|
|
|
ID = 'comments'
|
|
|
|
TYPE = 'comment'
|
|
|
|
TYPE = 'comment'
|
|
|
|
CONF = {'require-starting-space': bool,
|
|
|
|
CONF = {'require-starting-space': bool,
|
|
|
|
|
|
|
|
'ignore-cloud-init-cloud-config': bool,
|
|
|
|
'ignore-shebangs': bool,
|
|
|
|
'ignore-shebangs': bool,
|
|
|
|
'min-spaces-from-content': int}
|
|
|
|
'min-spaces-from-content': int}
|
|
|
|
DEFAULT = {'require-starting-space': True,
|
|
|
|
DEFAULT = {'require-starting-space': True,
|
|
|
|
|
|
|
|
'ignore-cloud-init-cloud-config': True,
|
|
|
|
'ignore-shebangs': True,
|
|
|
|
'ignore-shebangs': True,
|
|
|
|
'min-spaces-from-content': 2}
|
|
|
|
'min-spaces-from-content': 2}
|
|
|
|
|
|
|
|
|
|
|
@ -107,6 +116,11 @@ def check(conf, comment):
|
|
|
|
comment.column_no == 1 and
|
|
|
|
comment.column_no == 1 and
|
|
|
|
re.match(r'^!\S', comment.buffer[text_start:])):
|
|
|
|
re.match(r'^!\S', comment.buffer[text_start:])):
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
elif (conf['ignore-cloud-init-cloud-config'] and
|
|
|
|
|
|
|
|
comment.line_no == 1 and
|
|
|
|
|
|
|
|
comment.column_no == 1 and
|
|
|
|
|
|
|
|
re.match(r'^cloud-config', comment.buffer[text_start:])):
|
|
|
|
|
|
|
|
return
|
|
|
|
# We can test for both \r and \r\n just by checking first char
|
|
|
|
# We can test for both \r and \r\n just by checking first char
|
|
|
|
# \r itself is a valid newline on some older OS.
|
|
|
|
# \r itself is a valid newline on some older OS.
|
|
|
|
elif comment.buffer[text_start] not in {' ', '\n', '\r', '\x00'}:
|
|
|
|
elif comment.buffer[text_start] not in {' ', '\n', '\r', '\x00'}:
|
|
|
|