|
|
@ -87,6 +87,7 @@ Use this rule to set a limit to lines length.
|
|
|
|
http://localhost/very/very/very/very/very/very/very/very/long/url
|
|
|
|
http://localhost/very/very/very/very/very/very/very/very/long/url
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import yaml
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
|
|
|
|
from yamllint.linter import LintProblem
|
|
|
|
from yamllint.linter import LintProblem
|
|
|
@ -99,6 +100,18 @@ CONF = {'max': int,
|
|
|
|
'allow-non-breakable-inline-mappings': bool}
|
|
|
|
'allow-non-breakable-inline-mappings': bool}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_inline_mapping(line):
|
|
|
|
|
|
|
|
loader = yaml.SafeLoader(line.content)
|
|
|
|
|
|
|
|
while loader.peek_token():
|
|
|
|
|
|
|
|
if isinstance(loader.get_token(), yaml.BlockMappingStartToken):
|
|
|
|
|
|
|
|
while loader.peek_token():
|
|
|
|
|
|
|
|
if isinstance(loader.get_token(), yaml.ValueToken):
|
|
|
|
|
|
|
|
t = loader.get_token()
|
|
|
|
|
|
|
|
if isinstance(t, yaml.ScalarToken):
|
|
|
|
|
|
|
|
return ' ' not in line.content[t.start_mark.column:]
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check(conf, line):
|
|
|
|
def check(conf, line):
|
|
|
|
if line.end - line.start > conf['max']:
|
|
|
|
if line.end - line.start > conf['max']:
|
|
|
|
conf['allow-non-breakable-words'] |= \
|
|
|
|
conf['allow-non-breakable-words'] |= \
|
|
|
@ -115,11 +128,9 @@ def check(conf, line):
|
|
|
|
if line.buffer.find(' ', start, line.end) == -1:
|
|
|
|
if line.buffer.find(' ', start, line.end) == -1:
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
if conf['allow-non-breakable-inline-mappings']:
|
|
|
|
if (conf['allow-non-breakable-inline-mappings'] and
|
|
|
|
line_yaml = yaml.safe_load(line.content)
|
|
|
|
check_inline_mapping(line)):
|
|
|
|
if (isinstance(line_yaml, dict) and
|
|
|
|
return
|
|
|
|
' ' not in line_yaml.popitem()[1]):
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
yield LintProblem(line.line_no, conf['max'] + 1,
|
|
|
|
yield LintProblem(line.line_no, conf['max'] + 1,
|
|
|
|
'line too long (%d > %d characters)' %
|
|
|
|
'line too long (%d > %d characters)' %
|
|
|
|