line_length: Allow mapping values with long unbreakable lines

This commit is contained in:
Allan Lewis 2016-09-12 15:40:27 +01:00
parent 5b98cd2053
commit d017631aff
2 changed files with 11 additions and 0 deletions

View File

@ -84,6 +84,8 @@ class LineLengthTestCase(RuleTestCase):
'another:\n'
' - https://localhost/very/very/long/url\n'
'...\n', conf)
self.check('---\n'
'long_line: http://localhost/very/very/long/url\n', conf)
conf = 'line-length: {max: 20, allow-non-breakable-words: no}'
self.check('---\n' + 30 * 'A' + '\n', conf, problem=(2, 21))
@ -106,3 +108,6 @@ class LineLengthTestCase(RuleTestCase):
'another:\n'
' - https://localhost/very/very/long/url\n'
'...\n', conf, problem=(5, 21))
self.check('---\n'
'long_line: http://localhost/very/very/long/url\n'
'...\n', conf, problem=(2, 21))

View File

@ -72,6 +72,7 @@ Use this rule to set a limit to lines length.
http://localhost/very/very/very/very/very/very/very/very/long/url
"""
import yaml
from yamllint.linter import LintProblem
@ -96,6 +97,11 @@ def check(conf, line):
if line.buffer.find(' ', start, line.end) == -1:
return
line_yaml = yaml.safe_load(line.content)
if (isinstance(line_yaml, dict) and
' ' not in line_yaml.popitem()[1]):
return
yield LintProblem(line.line_no, conf['max'] + 1,
'line too long (%d > %d characters)' %
(line.end - line.start, conf['max']))