comments: Fix ignore-shebangs option on corner cases
This commit is contained in:
@@ -84,28 +84,43 @@ class CommentsTestCase(RuleTestCase):
|
|||||||
conf = ('comments:\n'
|
conf = ('comments:\n'
|
||||||
' require-starting-space: true\n'
|
' require-starting-space: true\n'
|
||||||
' ignore-shebangs: false\n'
|
' ignore-shebangs: false\n'
|
||||||
'comments-indentation: disable\n')
|
'comments-indentation: disable\n'
|
||||||
|
'document-start: disable\n')
|
||||||
self.check('#!/bin/env my-interpreter\n',
|
self.check('#!/bin/env my-interpreter\n',
|
||||||
conf, problem1=(1, 2))
|
conf, problem1=(1, 2))
|
||||||
|
self.check('# comment\n'
|
||||||
|
'#!/bin/env my-interpreter\n', conf,
|
||||||
|
problem1=(2, 2))
|
||||||
self.check('#!/bin/env my-interpreter\n'
|
self.check('#!/bin/env my-interpreter\n'
|
||||||
'---\n'
|
'---\n'
|
||||||
'#comment\n'
|
'#comment\n'
|
||||||
'#!/bin/env my-interpreter\n'
|
'#!/bin/env my-interpreter\n'
|
||||||
'', conf,
|
'', conf,
|
||||||
problem1=(1, 2), problem2=(3, 2), problem3=(4, 2))
|
problem1=(1, 2), problem2=(3, 2), problem3=(4, 2))
|
||||||
|
self.check('#! not a shebang\n',
|
||||||
|
conf, problem1=(1, 2))
|
||||||
|
self.check('key: #!/not/a/shebang\n',
|
||||||
|
conf, problem1=(1, 8))
|
||||||
|
|
||||||
def test_ignore_shebang(self):
|
def test_ignore_shebang(self):
|
||||||
conf = ('comments:\n'
|
conf = ('comments:\n'
|
||||||
' require-starting-space: true\n'
|
' require-starting-space: true\n'
|
||||||
' ignore-shebangs: true\n'
|
' ignore-shebangs: true\n'
|
||||||
'comments-indentation: disable\n')
|
'comments-indentation: disable\n'
|
||||||
|
'document-start: disable\n')
|
||||||
self.check('#!/bin/env my-interpreter\n', conf)
|
self.check('#!/bin/env my-interpreter\n', conf)
|
||||||
|
self.check('# comment\n'
|
||||||
|
'#!/bin/env my-interpreter\n', conf,
|
||||||
|
problem1=(2, 2))
|
||||||
self.check('#!/bin/env my-interpreter\n'
|
self.check('#!/bin/env my-interpreter\n'
|
||||||
'---\n'
|
'---\n'
|
||||||
'#comment\n'
|
'#comment\n'
|
||||||
'#!/bin/env my-interpreter\n'
|
'#!/bin/env my-interpreter\n', conf,
|
||||||
'', conf,
|
|
||||||
problem2=(3, 2), problem3=(4, 2))
|
problem2=(3, 2), problem3=(4, 2))
|
||||||
|
self.check('#! not a shebang\n',
|
||||||
|
conf, problem1=(1, 2))
|
||||||
|
self.check('key: #!/not/a/shebang\n',
|
||||||
|
conf, problem1=(1, 8))
|
||||||
|
|
||||||
def test_spaces_from_content(self):
|
def test_spaces_from_content(self):
|
||||||
conf = ('comments:\n'
|
conf = ('comments:\n'
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ Use this rule to control the position and formatting of comments.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
from yamllint.linter import LintProblem
|
from yamllint.linter import LintProblem
|
||||||
|
|
||||||
|
|
||||||
@@ -92,7 +94,8 @@ def check(conf, comment):
|
|||||||
if text_start < len(comment.buffer):
|
if text_start < len(comment.buffer):
|
||||||
if (conf['ignore-shebangs'] and
|
if (conf['ignore-shebangs'] and
|
||||||
comment.line_no == 1 and
|
comment.line_no == 1 and
|
||||||
comment.buffer[text_start] == '!'):
|
comment.column_no == 1 and
|
||||||
|
re.match(r'^!\S', comment.buffer[text_start:])):
|
||||||
return
|
return
|
||||||
elif comment.buffer[text_start] not in (' ', '\n', '\0'):
|
elif comment.buffer[text_start] not in (' ', '\n', '\0'):
|
||||||
column = comment.column_no + text_start - comment.pointer
|
column = comment.column_no + text_start - comment.pointer
|
||||||
|
|||||||
Reference in New Issue
Block a user