From 2124612c6af9f6a44730beb04f9a6fabd05f7e2e Mon Sep 17 00:00:00 2001 From: Alexandre Friquet Date: Mon, 16 Mar 2026 16:15:46 +0100 Subject: [PATCH 1/4] Add support for Ruby files. --- assets/languages.yaml | 3 ++ pkg/header/fix_test.go | 37 +++++++++++++++++++ .../include_test/with_license/testcase.rb | 20 ++++++++++ .../include_test/without_license/testcase.rb | 4 ++ 4 files changed, 64 insertions(+) create mode 100644 test/testdata/include_test/with_license/testcase.rb create mode 100644 test/testdata/include_test/without_license/testcase.rb diff --git a/assets/languages.yaml b/assets/languages.yaml index c634ae2e..c7fff6d9 100644 --- a/assets/languages.yaml +++ b/assets/languages.yaml @@ -4973,6 +4973,8 @@ Ruby: - ".irbrc" - ".pryrc" - ".simplecov" + - ".ruby-version" + - ".rspec" - Appraisals - Berksfile - Brewfile @@ -4994,6 +4996,7 @@ Ruby: - Vagrantfile - buildfile language_id: 326 + comment_style_id: Hashtag Rust: type: programming color: "#dea584" diff --git a/pkg/header/fix_test.go b/pkg/header/fix_test.go index 0947cdc3..2af38b8d 100644 --- a/pkg/header/fix_test.go +++ b/pkg/header/fix_test.go @@ -56,6 +56,13 @@ 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 `, }, } @@ -362,6 +369,36 @@ 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 `, }, } 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 00000000..56f213c6 --- /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/without_license/testcase.rb b/test/testdata/include_test/without_license/testcase.rb new file mode 100644 index 00000000..a129e108 --- /dev/null +++ b/test/testdata/include_test/without_license/testcase.rb @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby + +class HelloWorld +end From 3a9b58bb7a53deb58101f9348d1f29198b1e5eeb Mon Sep 17 00:00:00 2001 From: Alexandre Friquet Date: Mon, 16 Mar 2026 16:17:56 +0100 Subject: [PATCH 2/4] Add support for ERB files. --- assets/languages.yaml | 2 ++ assets/styles.yaml | 5 ++++ pkg/header/fix_test.go | 29 +++++++++++++++++++ .../include_test/with_license/testcase.erb | 20 +++++++++++++ .../include_test/without_license/testcase.erb | 2 ++ 5 files changed, 58 insertions(+) create mode 100644 test/testdata/include_test/with_license/testcase.erb create mode 100644 test/testdata/include_test/without_license/testcase.erb diff --git a/assets/languages.yaml b/assets/languages.yaml index c7fff6d9..a69039b3 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 diff --git a/assets/styles.yaml b/assets/styles.yaml index 85dc501b..bb0c60d3 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> diff --git a/pkg/header/fix_test.go b/pkg/header/fix_test.go index 2af38b8d..e12b9f63 100644 --- a/pkg/header/fix_test.go +++ b/pkg/header/fix_test.go @@ -63,6 +63,17 @@ func TestFix(t *testing.T) { 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 +%> + `, }, } @@ -399,6 +410,24 @@ end class Example end +`, + }, { + name: "ERB", + style: comments.FileCommentStyle("test.erb"), + content: ` + <%= @content %> + +`, + licenseHeader: getLicenseHeader("test.erb", t.Error), + expectedContent: `<% +# Apache License 2.0 +# http://www.apache.org/licenses/LICENSE-2.0 +# Apache License 2.0 +%> + + + <%= @content %> + `, }, } 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 00000000..a61c3ae4 --- /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. +%> + + 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 00000000..90531a4b --- /dev/null +++ b/test/testdata/include_test/without_license/testcase.erb @@ -0,0 +1,2 @@ + + From b706198d6fc0fb70240848b5f1945e5d17de8aff Mon Sep 17 00:00:00 2001 From: Alexandre Friquet Date: Mon, 16 Mar 2026 16:22:17 +0100 Subject: [PATCH 3/4] Add support for Slim files. --- assets/languages.yaml | 1 + assets/styles.yaml | 5 +++ pkg/header/fix_test.go | 38 +++++++++++++++++++ pkg/license/norm.go | 1 + .../include_test/with_license/testcase.slim | 19 ++++++++++ .../without_license/testcase.slim | 2 + 6 files changed, 66 insertions(+) create mode 100644 test/testdata/include_test/with_license/testcase.slim create mode 100644 test/testdata/include_test/without_license/testcase.slim diff --git a/assets/languages.yaml b/assets/languages.yaml index a69039b3..a6a9b2b5 100644 --- a/assets/languages.yaml +++ b/assets/languages.yaml @@ -5384,6 +5384,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 bb0c60d3..13b80e2e 100644 --- a/assets/styles.yaml +++ b/assets/styles.yaml @@ -120,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 e12b9f63..f969ce44 100644 --- a/pkg/header/fix_test.go +++ b/pkg/header/fix_test.go @@ -74,6 +74,14 @@ func TestFix(t *testing.T) { # Apache License 2.0 %> +`, + }, + { + filename: "test.slim", + comments: `/ Apache License 2.0 +/ http://www.apache.org/licenses/LICENSE-2.0 +/ Apache License 2.0 + `, }, } @@ -428,6 +436,36 @@ end <%= @content %> +`, + }, { + 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 350d8caf..5a7dac97 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* 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 00000000..aba56a2f --- /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.slim b/test/testdata/include_test/without_license/testcase.slim new file mode 100644 index 00000000..95529f69 --- /dev/null +++ b/test/testdata/include_test/without_license/testcase.slim @@ -0,0 +1,2 @@ +doctype html +html From ed66f2fff562cfb0cf53e948a60cac549b7e1846 Mon Sep 17 00:00:00 2001 From: Alexandre Friquet Date: Thu, 19 Mar 2026 11:42:46 +0100 Subject: [PATCH 4/4] Remove .ruby-version because of a one-line file. --- assets/languages.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/assets/languages.yaml b/assets/languages.yaml index a6a9b2b5..27c96634 100644 --- a/assets/languages.yaml +++ b/assets/languages.yaml @@ -4975,7 +4975,6 @@ Ruby: - ".irbrc" - ".pryrc" - ".simplecov" - - ".ruby-version" - ".rspec" - Appraisals - Berksfile