diff --git a/tests/rules/test_line_length.py b/tests/rules/test_line_length.py index e2c6bcd..1e00a74 100644 --- a/tests/rules/test_line_length.py +++ b/tests/rules/test_line_length.py @@ -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)) diff --git a/yamllint/rules/line_length.py b/yamllint/rules/line_length.py index 8980267..7985f0e 100644 --- a/yamllint/rules/line_length.py +++ b/yamllint/rules/line_length.py @@ -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']))