Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: Add GraphQL support #1624

Merged
merged 1 commit into from
Feb 11, 2025
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1613](https://github.com/ianlewis/todos/issues/1613)).
- Support was added for [Markdown](https://en.wikipedia.org/wiki/Markdown)
([#1608](https://github.com/ianlewis/todos/issues/1608)).
- Support was added for [GraphQL](https://graphql.org/)
([#1609](https://github.com/ianlewis/todos/issues/1609)).

## [0.10.0] - 2024-10-31

Expand Down
3 changes: 2 additions & 1 deletion SUPPORTED_LANGUAGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Supported Languages

51 languages are currently supported.
52 languages are currently supported.

| File type | Extension | Supported comments |
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- |
Expand All @@ -20,6 +20,7 @@
| Fortran Free Form | `.f90`, `.f03`, `.f08`, `.f95` | `!` |
| Go | `.go` | `//`, `/* */` |
| Go Module | | `//` |
| GraphQL | `.graphql`, `.gql`, `.graphqls` | `#`, `""" """` |
| Groovy | `.groovy`, `.grt`, `.gtpl`, `.gvy` | `//`, `/* */` |
| HCL | `.hcl`, `.nomad`, `.tf`, `.tfvars`, `.workflow` | `#`, `//` |
| HTML | `.html`, `.hta`, `.htm`, `.html.hl`, `.inc`, `.xht`, `.xhtml` | `<!-- -->` |
Expand Down
25 changes: 16 additions & 9 deletions internal/scanner/languages.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ var (
AtLineStart: false,
},
}

tripleDoubleQuoteComments = []MultilineCommentConfig{
{
Start: []rune("\"\"\""),
End: []rune("\"\"\""),
AtLineStart: false,
},
}
)

var LanguagesConfig = map[string]*Config{
Expand Down Expand Up @@ -263,6 +271,11 @@ var LanguagesConfig = map[string]*Config{
},
),
},
"GraphQL": {
LineComments: hashLineComments,
MultilineComments: tripleDoubleQuoteComments,
Strings: doubleQuoteString,
},
"Groovy": {
LineComments: cLineComments,
MultilineComments: cBlockComments,
Expand Down Expand Up @@ -483,15 +496,9 @@ var LanguagesConfig = map[string]*Config{
Strings: cStrings,
},
"Python": {
LineComments: hashLineComments,
MultilineComments: []MultilineCommentConfig{
{
Start: []rune("\"\"\""),
End: []rune("\"\"\""),
AtLineStart: false,
},
},
Strings: cStrings,
LineComments: hashLineComments,
MultilineComments: tripleDoubleQuoteComments,
Strings: cStrings,
},
"R": {
LineComments: hashLineComments,
Expand Down
48 changes: 48 additions & 0 deletions internal/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,54 @@ var scannerTestCases = []*struct {
},
},

// GraphQL
{
name: "multi_line.graphql",
src: `"""
Author of questions and answers in a website
"""
type Author {
# ... username is the author name , this is an example of a dropped comment
username: String! @id
"""
The questions submitted by this author
"""
questions: [Question] @hasInverse(field: author)
"""
The answers submitted by this author
"""
answers: [Answer] @hasInverse(field: author)
}`,
config: "GraphQL",
comments: []struct {
text string
line int
}{
{
text: `"""
Author of questions and answers in a website
"""`,
line: 1,
},
{
text: "# ... username is the author name , this is an example of a dropped comment",
line: 5,
},
{
text: `"""
The questions submitted by this author
"""`,
line: 7,
},
{
text: `"""
The answers submitted by this author
"""`,
line: 11,
},
},
},

// Groovy
{
name: "line_comments.groovy",
Expand Down