diff --git a/assets/languages.yaml b/assets/languages.yaml index c634ae2e..27c96634 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 85dc501b..13b80e2e 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 0947cdc3..f969ce44 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: ` + <%= @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 %> + +`, + }, { + 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.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/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/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.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 @@ + + 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 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