This is an automated email from the ASF dual-hosted git repository.
wu-sheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-eyes.git
The following commit(s) were added to refs/heads/main by this push:
new eddd8f1 fix: don't treat mid-file #! strings as Python shebangs (#279)
eddd8f1 is described below
commit eddd8f193e5c1739a76dad4074f50ede635a19fe
Author: Cristian <[email protected]>
AuthorDate: Tue Jul 28 20:47:38 2026 -0700
fix: don't treat mid-file #! strings as Python shebangs (#279)
---
assets/styles.yaml | 6 +--
pkg/header/fix_test.go | 142 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 145 insertions(+), 3 deletions(-)
diff --git a/assets/styles.yaml b/assets/styles.yaml
index 13b80e2..d62f46a 100644
--- a/assets/styles.yaml
+++ b/assets/styles.yaml
@@ -21,7 +21,7 @@
end: '//'
- id: Hashtag
- after: '(?m)^*#!.+$'
+ after: '(?m)\A#!.+$'
start: '#'
middle: '#'
end: '#'
@@ -109,14 +109,14 @@
- id: PythonStyle
# (interpreter binary and encoding comment) | (only interpreter binary) |
(only encoding comment)
- after: '(?m)(^*#!.+$\n^[ \t\f]*#.*?coding[:=][
\t]*([-_.a-zA-Z0-9]+).*$)|(^*#!.+$)|(^[ \t\f]*#.*?coding[:=][
\t]*([-_.a-zA-Z0-9]+).*$)'
+ after: '(?m)(\A#!.+$\n^[ \t\f]*#.*?coding[:=][
\t]*([-_.a-zA-Z0-9]+).*$)|(\A#!.+$)|(\A[ \t\f]*#.*?coding[:=][
\t]*([-_.a-zA-Z0-9]+).*$)'
start: '#'
middle: '#'
end: '#'
- id: PythonDocStringStyle
# (interpreter binary and encoding comment) | (only interpreter binary) |
(only encoding comment)
- after: '(?m)(^*#!.+$\n^[ \t\f]*#.*?coding[:=][
\t]*([-_.a-zA-Z0-9]+).*$)|(^*#!.+$)|(^[ \t\f]*#.*?coding[:=][
\t]*([-_.a-zA-Z0-9]+).*$)'
+ after: '(?m)(\A#!.+$\n^[ \t\f]*#.*?coding[:=][
\t]*([-_.a-zA-Z0-9]+).*$)|(\A#!.+$)|(\A[ \t\f]*#.*?coding[:=][
\t]*([-_.a-zA-Z0-9]+).*$)'
start: '"""'
middle: ~
end: '"""'
diff --git a/pkg/header/fix_test.go b/pkg/header/fix_test.go
index f969ce4..c877944 100644
--- a/pkg/header/fix_test.go
+++ b/pkg/header/fix_test.go
@@ -131,6 +131,126 @@ if __name__ == '__main__':
# http://www.apache.org/licenses/LICENSE-2.0
# Apache License 2.0
+if __name__ == '__main__':
+ print('Hello World')
+`},
+ {
+ name: "Python with shebang-like string mid file",
+ style: comments.FileCommentStyle("test.py"),
+ content: `def some_function():
+ print(
+ """#!/usr/bin/env python3
+ print("Hello, World!")
+ """)
+`,
+ licenseHeader: getLicenseHeader("test.py", t.Error),
+ expectedContent: `# Apache License 2.0
+# http://www.apache.org/licenses/LICENSE-2.0
+# Apache License 2.0
+
+def some_function():
+ print(
+ """#!/usr/bin/env python3
+ print("Hello, World!")
+ """)
+`},
+ {
+ name: "Python with shebang and shebang-like string mid
file",
+ style: comments.FileCommentStyle("test.py"),
+ content: `#!/usr/bin/env python3
+def some_function():
+ print(
+ """#!/usr/bin/env python3
+ print("Hello, World!")
+ """)
+`,
+ licenseHeader: getLicenseHeader("test.py", t.Error),
+ expectedContent: `#!/usr/bin/env python3
+# Apache License 2.0
+# http://www.apache.org/licenses/LICENSE-2.0
+# Apache License 2.0
+
+def some_function():
+ print(
+ """#!/usr/bin/env python3
+ print("Hello, World!")
+ """)
+`},
+ {
+ name: "Python with column-0 shebang-like string mid
file",
+ style: comments.FileCommentStyle("test.py"),
+ content: `x = """
+#!/usr/bin/env python3
+hello
+"""
+`,
+ licenseHeader: getLicenseHeader("test.py", t.Error),
+ expectedContent: `# Apache License 2.0
+# http://www.apache.org/licenses/LICENSE-2.0
+# Apache License 2.0
+
+x = """
+#!/usr/bin/env python3
+hello
+"""
+`},
+ {
+ name: "Shell with column-0 shebang-like string mid
file",
+ style: comments.FileCommentStyle("test.sh"),
+ content: `foo() {
+ cat <<EOF
+#!/bin/bash is just text
+EOF
+}
+`,
+ licenseHeader: getLicenseHeader("test.sh", t.Error),
+ expectedContent: `# Apache License 2.0
+# http://www.apache.org/licenses/LICENSE-2.0
+# Apache License 2.0
+
+foo() {
+ cat <<EOF
+#!/bin/bash is just text
+EOF
+}
+`},
+ {
+ name: "Bash with shebang-like string mid file",
+ style: comments.FileCommentStyle("test.sh"),
+ content: `generate_script() {
+ SCRIPT='#!/bin/bash
+echo "Hello, World!"'
+ echo "$SCRIPT"
+}
+`,
+ licenseHeader: getLicenseHeader("test.sh", t.Error),
+ expectedContent: `# Apache License 2.0
+# http://www.apache.org/licenses/LICENSE-2.0
+# Apache License 2.0
+
+generate_script() {
+ SCRIPT='#!/bin/bash
+echo "Hello, World!"'
+ echo "$SCRIPT"
+}
+`},
+ {
+ name: "Python with encoding mid file",
+ style: comments.FileCommentStyle("test.py"),
+ content: `x = 1
+
+# -*- coding: utf-8 -*-
+if __name__ == '__main__':
+ print('Hello World')
+`,
+ licenseHeader: getLicenseHeader("test.py", t.Error),
+ expectedContent: `# Apache License 2.0
+# http://www.apache.org/licenses/LICENSE-2.0
+# Apache License 2.0
+
+x = 1
+
+# -*- coding: utf-8 -*-
if __name__ == '__main__':
print('Hello World')
`},
@@ -404,6 +524,28 @@ end
class Example
end
+`,
+ }, {
+ name: "Ruby with shebang-like string mid file",
+ style: comments.FileCommentStyle("test.rb"),
+ content: `class Example
+ SCRIPT = <<~RUBY
+ #!/usr/bin/env ruby
+ puts "Hello, World!"
+ RUBY
+end
+`,
+ licenseHeader: getLicenseHeader("test.rb", t.Error),
+ expectedContent: `# Apache License 2.0
+# http://www.apache.org/licenses/LICENSE-2.0
+# Apache License 2.0
+
+class Example
+ SCRIPT = <<~RUBY
+ #!/usr/bin/env ruby
+ puts "Hello, World!"
+ RUBY
+end
`,
}, {
name: "Ruby",