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

feat: Groovy support #784

Merged
merged 2 commits into from
Sep 23, 2023
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
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Support for [Clojure](https://clojure.org/),
[CoffeeScript](https://coffeescript.org/), and [TeX](https://tug.org/) were
added.
[CoffeeScript](https://coffeescript.org/),
[Groovy](https://groovy-lang.org/), and [TeX](https://tug.org/) were added.
- Support for an `@` prefix on TODOs was added.

### Fixed
Expand Down
17 changes: 16 additions & 1 deletion internal/scanner/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ Go:
escape: none
Go Module:
# NOTE: See https://go.dev/ref/mod#go-mod-file-lexical
# NOTE: go.sum (Go Checksums) don't support comments.
line_comment_start: ["//"]
strings:
- start: '"'
Expand All @@ -125,7 +126,21 @@ Go Module:
- start: "`"
end: "`"
escape: none
# NOTE: go.sum (Go Checksums) don't support comments.
Groovy:
line_comment_start: ["//"]
multiline_comment:
start: "/*"
end: "*/"
strings:
- start: '"'
end: '"'
escape: backslash
- start: "'"
end: "'"
escape: backslash
- start: "'''"
end: "'''"
escape: backslash
Haskell:
line_comment_start: ["--"]
multiline_comment:
Expand Down
147 changes: 147 additions & 0 deletions internal/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,153 @@ var scannerTestCases = []*struct {
},
},

// Groovy
{
name: "line_comments.groovy",
src: `#!/usr/bin/env groovy
// package comment

// TODO is a function.
def TODO() {
return // Random comment
}`,
config: "Groovy",
comments: []struct {
text string
line int
}{
{
text: "// package comment",
line: 2,
},
{
text: "// TODO is a function.",
line: 4,
},
{
text: "// Random comment",
line: 6,
},
},
},
{
name: "comments_in_string.groovy",
src: `#!/usr/bin/env groovy
// package comment

// TODO is a function.
def TODO() String {
x = "// Random comment"
y = '// Random comment'
return x + y
}`,
config: "Groovy",
comments: []struct {
text string
line int
}{
{
text: "// package comment",
line: 2,
},
{
text: "// TODO is a function.",
line: 4,
},
},
},
{
name: "escaped_string.groovy",
src: `#!/usr/bin/env groovy
// package comment

// TODO is a function.
def TODO() String {
x = "\"// Random comment"
y = '\'// Random comment'
return x + y
}`,
config: "Groovy",
comments: []struct {
text string
line int
}{
{
text: "// package comment",
line: 2,
},
{
text: "// TODO is a function.",
line: 4,
},
},
},
{
name: "multiline_string.groovy",
src: `#!/usr/bin/env groovy
// package comment

z = '''
// TODO is a function.
'''

def TODO() String {
// Random comment
x = "\"// Random comment"
y = '\'// Random comment'
return x + y
}`,
config: "Groovy",
comments: []struct {
text string
line int
}{
{
text: "// package comment",
line: 2,
},
{
text: "// Random comment",
line: 9,
},
},
},
{
name: "multi_line.groovy",
src: `#!/usr/bin/env groovy
// package comment

/*
TODO is a function.
*/
def TODO() String {
return // Random comment
}
/* extra comment */`,
config: "Groovy",
comments: []struct {
text string
line int
}{
{
text: "// package comment",
line: 2,
},
{
text: "/*\n\t\t\tTODO is a function.\n\t\t\t*/",
line: 4,
},
{
text: "// Random comment",
line: 8,
},
{
text: "/* extra comment */",
line: 10,
},
},
},

// PHP
{
name: "line_comments.php",
Expand Down