From e53ea093e24c718baf17eeebdbebc3b612adb906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= <69143962+pmalek-sumo@users.noreply.github.com> Date: Wed, 24 Mar 2021 18:04:48 +0100 Subject: [PATCH] line_length: skip all hash signs starting comment --- tests/rules/test_line_length.py | 21 +++++++++++++++++++++ yamllint/rules/line_length.py | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/rules/test_line_length.py b/tests/rules/test_line_length.py index d63afb34..245fe4d0 100644 --- a/tests/rules/test_line_length.py +++ b/tests/rules/test_line_length.py @@ -116,6 +116,27 @@ def test_non_breakable_word(self): 'long_line: http://localhost/very/very/long/url\n' '...\n', conf, problem=(2, 21)) + conf = 'line-length: {max: 20, allow-non-breakable-words: true}' + self.check('---\n' + '# http://www.verylongurlurlurlurlurlurlurlurl.com\n' + 'key:\n' + ' subkey: value\n', conf) + self.check('---\n' + '## http://www.verylongurlurlurlurlurlurlurlurl.com\n' + 'key:\n' + ' subkey: value\n', conf) + self.check('---\n' + '# # http://www.verylongurlurlurlurlurlurlurlurl.com\n' + 'key:\n' + ' subkey: value\n', conf, + problem=(2, 21)) + self.check('---\n' + '#A http://www.verylongurlurlurlurlurlurlurlurl.com\n' + 'key:\n' + ' subkey: value\n', conf, + problem1=(2, 2, 'comments'), + problem2=(2, 21, 'line-length')) + conf = ('line-length: {max: 20, allow-non-breakable-words: true}\n' 'trailing-spaces: disable') self.check('---\n' diff --git a/yamllint/rules/line_length.py b/yamllint/rules/line_length.py index 04312408..cfc328ce 100644 --- a/yamllint/rules/line_length.py +++ b/yamllint/rules/line_length.py @@ -140,7 +140,11 @@ def check(conf, line): start += 1 if start != line.end: - if line.buffer[start] in ('#', '-'): + if line.buffer[start] == '#': + while line.buffer[start] == '#': + start += 1 + start += 1 + elif line.buffer[start] == '-': start += 2 if line.buffer.find(' ', start, line.end) == -1: