From 4bfd6d2684b3ee86d0c750ac087b5cc634745a1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Alet?= Date: Sat, 11 Dec 2021 18:35:56 +1100 Subject: [PATCH] fix: allow whitespace after the shebang marker. Closes #428. --- tests/rules/test_comments.py | 5 ++--- yamllint/rules/comments.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/rules/test_comments.py b/tests/rules/test_comments.py index 2c3f399..7a7bc8a 100644 --- a/tests/rules/test_comments.py +++ b/tests/rules/test_comments.py @@ -97,7 +97,7 @@ class CommentsTestCase(RuleTestCase): '#!/bin/env my-interpreter\n' '', conf, problem1=(1, 2), problem2=(3, 2), problem3=(4, 2)) - self.check('#! not a shebang\n', + self.check('#! is a valid shebang too\n', conf, problem1=(1, 2)) self.check('key: #!/not/a/shebang\n', conf, problem1=(1, 8)) @@ -117,8 +117,7 @@ class CommentsTestCase(RuleTestCase): '#comment\n' '#!/bin/env my-interpreter\n', conf, problem2=(3, 2), problem3=(4, 2)) - self.check('#! not a shebang\n', - conf, problem1=(1, 2)) + self.check('#! is a valid shebang too\n', conf) self.check('key: #!/not/a/shebang\n', conf, problem1=(1, 8)) diff --git a/yamllint/rules/comments.py b/yamllint/rules/comments.py index 70ae250..c815ff3 100644 --- a/yamllint/rules/comments.py +++ b/yamllint/rules/comments.py @@ -105,7 +105,7 @@ def check(conf, comment): if (conf['ignore-shebangs'] and comment.line_no == 1 and comment.column_no == 1 and - re.match(r'^!\S', comment.buffer[text_start:])): + comment.buffer[text_start:].startswith('!')): return # We can test for both \r and \r\n just by checking first char # \r itself is a valid newline on some older OS.