Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions assets/languages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -4973,6 +4975,7 @@ Ruby:
- ".irbrc"
- ".pryrc"
- ".simplecov"
- ".rspec"
- Appraisals
- Berksfile
- Brewfile
Expand All @@ -4994,6 +4997,7 @@ Ruby:
- Vagrantfile
- buildfile
language_id: 326
comment_style_id: Hashtag
Rust:
type: programming
color: "#dea584"
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions assets/styles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
middle: ' ~'
end: '-->'

- id: AngleBracketPercentHashtag
start: '<%'
middle: '#'
end: '%>'

# tag::SlashAsterisk[]
- id: SlashAsterisk
start: '/*' # <1>
Expand Down Expand Up @@ -115,3 +120,8 @@
start: '"""'
middle: ~
end: '"""'

- id: Slash
start: '/'
middle: '/'
end: '/'
104 changes: 104 additions & 0 deletions pkg/header/fix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

`,
},
}
Expand Down Expand Up @@ -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
`,
},
}
Expand Down
1 change: 1 addition & 0 deletions pkg/license/norm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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*--+>`), // -->
Expand Down
20 changes: 20 additions & 0 deletions test/testdata/include_test/with_license/testcase.erb
Original file line number Diff line number Diff line change
@@ -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>
20 changes: 20 additions & 0 deletions test/testdata/include_test/with_license/testcase.rb
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions test/testdata/include_test/with_license/testcase.slim
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/testdata/include_test/without_license/testcase.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<html>
</html>
4 changes: 4 additions & 0 deletions test/testdata/include_test/without_license/testcase.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby

class HelloWorld
end
2 changes: 2 additions & 0 deletions test/testdata/include_test/without_license/testcase.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
doctype html
html
Loading