From bb567ba3953561436619bb4ca9466a64ecea236f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Alet?= <85658105+tamere-allo-peter@users.noreply.github.com> Date: Mon, 20 Dec 2021 08:02:56 +1100 Subject: [PATCH] comments: Allow whitespace after the shebang marker Basically, any character is now allowed after the shebang marker. Closes #428. Whitespace after the #! marker on shebang lines is authorized and optional, as explained on Wikipedia's entry for shebang line as can be seen from the extracts below : > White space after #! is optional and > It has been claimed[20] that some old versions of Unix expect the > normal shebang to be followed by a space and a slash (#! /), but this > appears to be untrue;[21] rather, blanks after the shebang have > traditionally been allowed, and sometimes documented with a space --- tests/rules/test_comments.py | 5 ++--- yamllint/rules/comments.py | 4 +--- 2 files changed, 3 insertions(+), 6 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..02eddad 100644 --- a/yamllint/rules/comments.py +++ b/yamllint/rules/comments.py @@ -74,8 +74,6 @@ Use this rule to control the position and formatting of comments. """ -import re - from yamllint.linter import LintProblem @@ -105,7 +103,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] == '!'): 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.