Skip to content

Commit

Permalink
feat: Emacs support (#798)
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Lewis <ianmlewis@gmail.com>
  • Loading branch information
Ian Lewis authored Sep 23, 2023
1 parent a28afc6 commit 1dbea2a
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 2 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Support for [Emacs Lisp](https://www.gnu.org/software/emacs/) was added.

## [0.6.0] - 2023-09-23

### Added in 0.6.0
Expand Down Expand Up @@ -135,7 +141,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Initial release of `todos` CLI application.
- Simple support for scanning directories for TODO/FIXME/BUG/HACK/XXX comments.

[unreleased]: https://github.com/ianlewis/todos/compare/v0.6.0...HEAD
[Unreleased]: https://github.com/ianlewis/todos/compare/v0.6.0...HEAD
[0.0.1]: https://github.com/ianlewis/todos/releases/tag/v0.0.1
[0.1.0]: https://github.com/ianlewis/todos/releases/tag/v0.1.0
[0.2.0]: https://github.com/ianlewis/todos/releases/tag/v0.2.0
Expand Down
4 changes: 3 additions & 1 deletion SUPPORTED_LANGUAGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Supported Languages

34 languages are currently supported.
36 languages are currently supported.

| File type | Supported comments |
| ------------- | ------------------ |
Expand All @@ -11,9 +11,11 @@
| Clojure | `;` |
| CoffeeScript | `#`, `### ###` |
| Dockerfile | `#` |
| Emacs Lisp | `;` |
| Erlang | `%` |
| Go | `//`, `/* */` |
| Go Module | `//` |
| Groovy | `//`, `/* */` |
| HTML | `<!-- --!>` |
| Haskell | `--`, `{- -}` |
| JSON | `//`, `#`, `/* */` |
Expand Down
16 changes: 16 additions & 0 deletions internal/scanner/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ Dockerfile:
- start: "'"
end: "'"
escape: backslash
Emacs Lisp:
line_comment_start: [";"]
strings:
- start: '"'
end: '"'
escape: backslash
Erlang:
line_comment_start: ["%"]
strings:
Expand Down Expand Up @@ -387,6 +393,16 @@ Unix Assembly:
- start: "'"
end: "'"
escape: none
# TODO(#460): Support Vim Script
# Vim Script:
# line_comment_start: ['"']
# strings:
# - start: '"'
# end: '"'
# escape: backslash
# - start: "'"
# end: "'"
# escape: backslash
XML:
multiline_comment:
start: "<!--"
Expand Down
148 changes: 148 additions & 0 deletions internal/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,82 @@ var scannerTestCases = []*struct {
},
},

// Emacs Lisp
{
name: "line_comments.el",
src: `; file comment
;; TODO is a function.
(defun TODO () "Hello") ; Random comment
;;; extra comment ;;;`,
config: "Emacs Lisp",
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.el",
src: `; module comment
; TODO is a function
(defun TODO () "; Random comment")
`,
config: "Emacs Lisp",
comments: []struct {
text string
line int
}{
{
text: "; module comment",
line: 1,
},
{
text: "; TODO is a function",
line: 3,
},
},
},
{
name: "escaped_string.el",
src: `; module comment
; TODO is a function
(defun TODO () "\"; Random comment")
`,
config: "Emacs Lisp",
comments: []struct {
text string
line int
}{
{
text: "; module comment",
line: 1,
},
{
text: "; TODO is a function",
line: 3,
},
},
},

// Erlang
{
name: "line_comments.erl",
Expand Down Expand Up @@ -1496,6 +1572,64 @@ var scannerTestCases = []*struct {
},
},
},

// TODO(#460): Support Vim Script
// {
// name: "line_comments.vim",
// src: `" file comment

// " TODO is a function.
// function TODO()
// return "Hello" " Random comment
// endfunction
// " extra comment`,
// config: "Vim Script",
// comments: []struct {
// text string
// line int
// }{
// {
// text: "\" file comment",
// line: 1,
// },
// {
// text: "\" TODO is a function.",
// line: 3,
// },
// {
// text: "\" Random comment",
// line: 5,
// },
// {
// text: "\" extra comment",
// line: 7,
// },
// },
// },
// {
// name: "escaped_string.vim",
// src: `" module comment

// " TODO is a function
// function TODO()
// return "\" Random comment"
// endfunction
// `,
// config: "Vim Script",
// comments: []struct {
// text string
// line int
// }{
// {
// text: "\" module comment",
// line: 1,
// },
// {
// text: "\" TODO is a function",
// line: 3,
// },
// },
// },
}

func TestCommentScanner(t *testing.T) {
Expand Down Expand Up @@ -1553,6 +1687,20 @@ var loaderTestCases = []struct {
expectedConfig string
err error
}{
// Emacs Lisp
{
name: "line_comments.el",
charset: "ISO-8859-1",
scanCharset: "ISO-8859-1",
src: []byte(`; file comment
;; TODO is a function.
(defun TODO () "Hello") ; Random comment
;;; extra comment ;;;`),
expectedConfig: "Emacs Lisp",
},

// Go
{
name: "ascii.go",
charset: "ISO-8859-1",
Expand Down

0 comments on commit 1dbea2a

Please sign in to comment.