Skip to content

Commit

Permalink
line_length: skip all hash signs starting comment
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek-sumo authored Mar 24, 2021
1 parent 5d8ef2e commit e53ea09
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
21 changes: 21 additions & 0 deletions tests/rules/test_line_length.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 5 additions & 1 deletion yamllint/rules/line_length.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e53ea09

Please sign in to comment.