Skip to content

Commit

Permalink
chore: support more formats in license header tool (#374)
Browse files Browse the repository at this point in the history
Co-authored-by: Patrik <zepatrik@users.noreply.github.com>
  • Loading branch information
jonas-jonas and zepatrik committed Sep 3, 2024
1 parent 37115e8 commit b215681
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
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

0 comments on commit b215681

Please sign in to comment.