Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: support more formats in license header tool #374

Merged
merged 4 commits into from
Sep 3, 2024
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
10 changes: 10 additions & 0 deletions cmd/dev/headers/comments/formats.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ var doubleSlashComments = Format{
endToken: "",
}

// comment format that is surrounded by /* */
var slashStarComments = Format{
startToken: "/* ",
endToken: " */",
}

// comment format that starts with pound symbols
var poundComments = Format{
startToken: "# ",
Expand All @@ -93,14 +99,18 @@ var commentFormats = map[FileType]Format{
"go": doubleSlashComments,
"java": doubleSlashComments,
"js": doubleSlashComments,
"jsx": doubleSlashComments,
"md": htmlComments,
"php": doubleSlashComments,
"py": poundComments,
"rb": poundComments,
"rs": doubleSlashComments,
"ts": doubleSlashComments,
"tsx": doubleSlashComments,
"vue": htmlComments,
"yml": poundComments,
"html": htmlComments,
"css": slashStarComments,
}

func GetFormat(path string) (Format, bool) {
Expand Down
16 changes: 16 additions & 0 deletions cmd/dev/headers/comments/formats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,19 @@ hello: world`, "\n")
_, have := htmlComments.SplitHeaderFromContent(give, regexp.MustCompile(`Copyright © \d{4} Ory Corp Inc.`))
assert.Equal(t, want, have)
}

func TestSlashStarComments(t *testing.T) {
t.Parallel()
tests := map[string]string{
"Hello": "/* Hello */",
"Hello\n": "/* Hello */\n",
"Hello\nWorld": "/* Hello */\n/* World */",
"Hello\nWorld\n": "/* Hello */\n/* World */\n",
}
for give, want := range tests {
t.Run(fmt.Sprintf("%s -> %s", give, want), func(t *testing.T) {
have := slashStarComments.renderBlock(give)
assert.Equal(t, want, have)
})
}
}
2 changes: 1 addition & 1 deletion cmd/dev/newsletter/.snapshots/TestRenderMarkdownLong.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions view/mail-body.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<!-- Copyright © 2024 Ory Corp -->
<!-- SPDX-License-Identifier: Apache-2.0 -->

<!DOCTYPE html>
<!-- Set the language of your main document. This helps screenreaders use the proper language profile, pronunciation, and accent. -->
<html lang='en'>
Expand Down
Loading