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 8e837be Add support for Ruby, ERB and slim (#266)
8e837be is described below
commit 8e837beb243c264ffcd5ea3abd3d5d8975cd0077
Author: Alexandre Friquet <[email protected]>
AuthorDate: Thu Jun 11 14:33:41 2026 +0200
Add support for Ruby, ERB and slim (#266)
---
assets/languages.yaml | 5 +
assets/styles.yaml | 10 ++
pkg/header/fix_test.go | 104 +++++++++++++++++++++
pkg/license/norm.go | 1 +
.../include_test/with_license/testcase.erb | 20 ++++
.../testdata/include_test/with_license/testcase.rb | 20 ++++
.../include_test/with_license/testcase.slim | 19 ++++
.../include_test/without_license/testcase.erb | 2 +
.../include_test/without_license/testcase.rb | 4 +
.../include_test/without_license/testcase.slim | 2 +
10 files changed, 187 insertions(+)
diff --git a/assets/languages.yaml b/assets/languages.yaml
index c634ae2..27c9663 100644
--- a/assets/languages.yaml
+++ b/assets/languages.yaml
@@ -2150,6 +2150,7 @@ HTML+ERB:
codemirror_mode: htmlembedded
codemirror_mime_type: application/x-erb
language_id: 150
+ comment_style_id: AngleBracketPercentHashtag
HTML+PHP:
type: markup
tm_scope: text.html.php
@@ -2681,6 +2682,7 @@ JavaScript+ERB:
codemirror_mode: javascript
codemirror_mime_type: application/javascript
language_id: 914318960
+ comment_style_id: AngleBracketPercentHashtag
Jison:
type: programming
group: Yacc
@@ -4973,6 +4975,7 @@ Ruby:
- ".irbrc"
- ".pryrc"
- ".simplecov"
+ - ".rspec"
- Appraisals
- Berksfile
- Brewfile
@@ -4994,6 +4997,7 @@ Ruby:
- Vagrantfile
- buildfile
language_id: 326
+ comment_style_id: Hashtag
Rust:
type: programming
color: "#dea584"
@@ -5379,6 +5383,7 @@ Slim:
codemirror_mode: slim
codemirror_mime_type: text/x-slim
language_id: 350
+ comment_style_id: Slash
SmPL:
type: programming
extensions:
diff --git a/assets/styles.yaml b/assets/styles.yaml
index 85dc501..13b80e2 100644
--- a/assets/styles.yaml
+++ b/assets/styles.yaml
@@ -32,6 +32,11 @@
middle: ' ~'
end: '-->'
+- id: AngleBracketPercentHashtag
+ start: '<%'
+ middle: '#'
+ end: '%>'
+
# tag::SlashAsterisk[]
- id: SlashAsterisk
start: '/*' # <1>
@@ -115,3 +120,8 @@
start: '"""'
middle: ~
end: '"""'
+
+- id: Slash
+ start: '/'
+ middle: '/'
+ end: '/'
diff --git a/pkg/header/fix_test.go b/pkg/header/fix_test.go
index 0947cdc..f969ce4 100644
--- a/pkg/header/fix_test.go
+++ b/pkg/header/fix_test.go
@@ -56,6 +56,32 @@ func TestFix(t *testing.T) {
# http://www.apache.org/licenses/LICENSE-2.0
# Apache License 2.0
+`,
+ },
+ {
+ filename: "test.rb",
+ comments: `# Apache License 2.0
+# http://www.apache.org/licenses/LICENSE-2.0
+# Apache License 2.0
+
+`,
+ },
+ {
+ filename: "test.erb",
+ comments: `<%
+# Apache License 2.0
+# http://www.apache.org/licenses/LICENSE-2.0
+# Apache License 2.0
+%>
+
+`,
+ },
+ {
+ filename: "test.slim",
+ comments: `/ Apache License 2.0
+/ http://www.apache.org/licenses/LICENSE-2.0
+/ Apache License 2.0
+
`,
},
}
@@ -362,6 +388,84 @@ namespace test\test2;
* This is a php docblock
*/
namespace test\test2;
+`,
+ }, {
+ name: "Ruby with shebang",
+ style: comments.FileCommentStyle("test.rb"),
+ content: `#!/usr/bin/env ruby
+class Example
+end
+`,
+ licenseHeader: getLicenseHeader("test.rb", t.Error),
+ expectedContent: `#!/usr/bin/env ruby
+# Apache License 2.0
+# http://www.apache.org/licenses/LICENSE-2.0
+# Apache License 2.0
+
+class Example
+end
+`,
+ }, {
+ name: "Ruby",
+ style: comments.FileCommentStyle("test.rb"),
+ content: `class Example
+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
+end
+`,
+ }, {
+ name: "ERB",
+ style: comments.FileCommentStyle("test.erb"),
+ content: `<html>
+ <body><%= @content %></body>
+</html>
+`,
+ licenseHeader: getLicenseHeader("test.erb", t.Error),
+ expectedContent: `<%
+# Apache License 2.0
+# http://www.apache.org/licenses/LICENSE-2.0
+# Apache License 2.0
+%>
+
+<html>
+ <body><%= @content %></body>
+</html>
+`,
+ }, {
+ name: "Slim with doctype",
+ style: comments.FileCommentStyle("test.slim"),
+ content: `doctype html
+html
+ body
+`,
+ licenseHeader: getLicenseHeader("test.slim", t.Error),
+ expectedContent: `/ Apache License 2.0
+/ http://www.apache.org/licenses/LICENSE-2.0
+/ Apache License 2.0
+
+doctype html
+html
+ body
+`,
+ }, {
+ name: "Slim",
+ style: comments.FileCommentStyle("test.slim"),
+ content: `html
+ body
+`,
+ licenseHeader: getLicenseHeader("test.slim", t.Error),
+ expectedContent: `/ Apache License 2.0
+/ http://www.apache.org/licenses/LICENSE-2.0
+/ Apache License 2.0
+
+html
+ body
`,
},
}
diff --git a/pkg/license/norm.go b/pkg/license/norm.go
index 350d8ca..5a7dac9 100644
--- a/pkg/license/norm.go
+++ b/pkg/license/norm.go
@@ -52,6 +52,7 @@ var (
regexp.MustCompile(`(?m)^\s*/\*+`), // /*
regexp.MustCompile(`(?m)^\s*\*+/`), // */
regexp.MustCompile(`(?m)^\s*\*+`), // *
+ regexp.MustCompile(`(?m)^\s*/`), // / e.g. Slim, must come
after the /* and // patterns
regexp.MustCompile(`(?m)^\s*<!--+`), // <!--
regexp.MustCompile(`(?m)^\s*--+>`), // -->
diff --git a/test/testdata/include_test/with_license/testcase.erb
b/test/testdata/include_test/with_license/testcase.erb
new file mode 100644
index 0000000..a61c3ae
--- /dev/null
+++ b/test/testdata/include_test/with_license/testcase.erb
@@ -0,0 +1,20 @@
+<%
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+%>
+<html>
+</html>
diff --git a/test/testdata/include_test/with_license/testcase.rb
b/test/testdata/include_test/with_license/testcase.rb
new file mode 100644
index 0000000..56f213c
--- /dev/null
+++ b/test/testdata/include_test/with_license/testcase.rb
@@ -0,0 +1,20 @@
+#!/usr/bin/env ruby
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class HelloWorld
+end
diff --git a/test/testdata/include_test/with_license/testcase.slim
b/test/testdata/include_test/with_license/testcase.slim
new file mode 100644
index 0000000..aba56a2
--- /dev/null
+++ b/test/testdata/include_test/with_license/testcase.slim
@@ -0,0 +1,19 @@
+/ Licensed to the Apache Software Foundation (ASF) under one
+/ or more contributor license agreements. See the NOTICE file
+/ distributed with this work for additional information
+/ regarding copyright ownership. The ASF licenses this file
+/ to you under the Apache License, Version 2.0 (the
+/ "License"); you may not use this file except in compliance
+/ with the License. You may obtain a copy of the License at
+/
+/ http://www.apache.org/licenses/LICENSE-2.0
+/
+/ Unless required by applicable law or agreed to in writing,
+/ software distributed under the License is distributed on an
+/ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+/ KIND, either express or implied. See the License for the
+/ specific language governing permissions and limitations
+/ under the License.
+
+doctype html
+html
diff --git a/test/testdata/include_test/without_license/testcase.erb
b/test/testdata/include_test/without_license/testcase.erb
new file mode 100644
index 0000000..90531a4
--- /dev/null
+++ b/test/testdata/include_test/without_license/testcase.erb
@@ -0,0 +1,2 @@
+<html>
+</html>
diff --git a/test/testdata/include_test/without_license/testcase.rb
b/test/testdata/include_test/without_license/testcase.rb
new file mode 100644
index 0000000..a129e10
--- /dev/null
+++ b/test/testdata/include_test/without_license/testcase.rb
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+
+class HelloWorld
+end
diff --git a/test/testdata/include_test/without_license/testcase.slim
b/test/testdata/include_test/without_license/testcase.slim
new file mode 100644
index 0000000..95529f6
--- /dev/null
+++ b/test/testdata/include_test/without_license/testcase.slim
@@ -0,0 +1,2 @@
+doctype html
+html