Skip to content

Commit

Permalink
feat: Clojure support (#734)
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Lewis <ianmlewis@gmail.com>
  • Loading branch information
ianlewis committed Sep 22, 2023
1 parent 82cfc85 commit 87e4789
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Support for CoffeeScript was added.
- Support for [Clojure](https://clojure.org/) and
[CoffeeScript](https://coffeescript.org/) were added.

### Fixed

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ In order for the comments to be more easily parsed keep in mind the following:
- TODOs should have a colon if a message is present so it can be distingished
from normal comments.
- Comments can be on the same line with other code (e.g. `x = f() // TODO: call f`
- Line comment start sequences can be repeated (e.g. `//// TODO: some comment`)
- Only the single line where the TODO occurs is printed for multi-line comments.
- `TODO`,`FIXME`,`BUG`,`HACK`,`XXX`,`COMBAK` are supported by default. You can
change this with the `--todo-types` flag.
Expand Down
6 changes: 6 additions & 0 deletions internal/scanner/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ C#:
- start: "'"
end: "'"
escape: backslash
Clojure:
line_comment_start: [";"]
strings:
- start: '"'
end: '"'
escape: backslash
CoffeeScript:
line_comment_start: ["#"]
multiline_comment:
Expand Down
76 changes: 76 additions & 0 deletions internal/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,82 @@ var scannerTestCases = []*struct {
},
},

// Clojure
{
name: "line_comments.clj",
src: `; file comment
;; TODO is a function.
(defn TODO [] (str "Hello") ) ; Random comment
;;; extra comment ;;;`,
config: "Clojure",
comments: []struct {
text string
line int
}{
{
text: "; file comment",
line: 1,
},
{
text: ";; TODO is a function.",
line: 3,
},
{
text: "; Random comment",
line: 4,
},
{
text: ";;; extra comment ;;;",
line: 5,
},
},
},
{
name: "comments_in_string.clj",
src: `; module comment
; TODO is a function
(defn TODO [] (str "; Random comment") )
`,
config: "Clojure",
comments: []struct {
text string
line int
}{
{
text: "; module comment",
line: 1,
},
{
text: "; TODO is a function",
line: 3,
},
},
},
{
name: "escaped_string.clj",
src: `; module comment
; TODO is a function
(defn TODO [] (str "\"; Random comment") )
`,
config: "Clojure",
comments: []struct {
text string
line int
}{
{
text: "; module comment",
line: 1,
},
{
text: "; TODO is a function",
line: 3,
},
},
},

// CoffeeScript
{
name: "line_comments.coffee",
Expand Down
2 changes: 1 addition & 1 deletion internal/todos/todos.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func NewTODOScanner(s CommentScanner, config *Config) *TODOScanner {
sConfig := s.Config()
var commentStarts []string
for _, lineCommentStart := range sConfig.LineCommentStart {
commentStarts = append(commentStarts, regexp.QuoteMeta(lineCommentStart))
commentStarts = append(commentStarts, "(?:"+regexp.QuoteMeta(lineCommentStart)+")+")
}
commentStartMatch := strings.Join(commentStarts, "|")

Expand Down
23 changes: 23 additions & 0 deletions internal/todos/todos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,29 @@ func TestTODOScanner(t *testing.T) {
},
},
},
"extra_line_comment_prefix.go": {
s: &testScanner{
comments: []*scanner.Comment{
{
Text: "//// TODO: comment",
Line: 1,
},
},
},
config: &Config{
Types: []string{"TODO"},
},
expected: []*TODO{
{
Type: "TODO",
Text: "//// TODO: comment",
Label: "",
Message: "comment",
Line: 1,
CommentLine: 1,
},
},
},
}

for name, tc := range testCases {
Expand Down

0 comments on commit 87e4789

Please sign in to comment.