Skip to content

Commit 8c41753

Browse files
authored
feat: Add ignore file support (#1638)
Signed-off-by: Ian Lewis <ian@ianlewis.org>
1 parent 95d3b0b commit 8c41753

6 files changed

Lines changed: 435 additions & 43 deletions

File tree

.github/workflows/pre-submit.units.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ jobs:
175175
with:
176176
go-version-file: "go.mod"
177177
- env:
178-
GOLANGCI_LINT_VERSION: "1.61.0"
179-
GOLANGCI_LINT_CHECKSUM: "77cb0af99379d9a21d5dc8c38364d060e864a01bd2f3e30b5e8cc550c3a54111"
178+
GOLANGCI_LINT_VERSION: "1.64.5"
179+
GOLANGCI_LINT_CHECKSUM: "e6bd399a0479c5fd846dcf9f3990d20448b4f0d1e5027d82348eab9f80f7ac71"
180180
run: |
181181
set -euo pipefail
182182

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
### Changed
11+
12+
- `todos` now parses `.gitignore` and `.todosignore` files and ignores those
13+
files. ([#125](https://github.com/ianlewis/todos/issues/125)).
14+
815
## [0.11.0] - 2025-02-12
916

1017
### Fixed in 0.11.0

internal/cmd/todos/app.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ const (
5050

5151
const defaultCharset = "UTF-8"
5252

53+
var defaultIgnoreFilenames = []string{".gitignore", ".todosignore"}
54+
5355
var (
5456
// ErrFlagParse is a flag parsing error.
5557
ErrFlagParse = errors.New("parsing flags")
@@ -117,6 +119,11 @@ func newTODOsApp() *cli.App {
117119
Usage: "exclude hidden files and directories",
118120
DisableDefaultText: true,
119121
},
122+
&cli.StringSliceFlag{
123+
Name: "ignore-file-name",
124+
Usage: "name of files with ignore patterns (.gitignore format)",
125+
Value: cli.NewStringSlice(defaultIgnoreFilenames...),
126+
},
120127
&cli.BoolFlag{
121128
Name: "include-vcs",
122129
Usage: "include version control directories (.git, .hg, .svn)",
@@ -387,6 +394,8 @@ func walkerOptionsFromContext(c *cli.Context) (*walker.Options, error) {
387394
o.IncludeVCS = c.Bool("include-vcs")
388395
o.IncludeVendored = c.Bool("include-vendored")
389396

397+
o.IgnoreFileNames = c.StringSlice("ignore-file-name")
398+
390399
// Filters
391400
for _, label := range c.StringSlice("label") {
392401
g, err := glob.Compile(label)

internal/cmd/todos/app_test.go

Lines changed: 74 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,10 @@ func Test_walkerOptionsFromContext(t *testing.T) {
377377
Config: &todos.Config{
378378
Types: todos.DefaultTypes,
379379
},
380-
Charset: defaultCharset,
381-
IncludeHidden: true,
382-
Paths: []string{"."},
380+
Charset: defaultCharset,
381+
IgnoreFileNames: defaultIgnoreFilenames,
382+
IncludeHidden: true,
383+
Paths: []string{"."},
383384
},
384385
},
385386
"output github": {
@@ -389,9 +390,10 @@ func Test_walkerOptionsFromContext(t *testing.T) {
389390
Config: &todos.Config{
390391
Types: todos.DefaultTypes,
391392
},
392-
Charset: defaultCharset,
393-
IncludeHidden: true,
394-
Paths: []string{"."},
393+
Charset: defaultCharset,
394+
IgnoreFileNames: defaultIgnoreFilenames,
395+
IncludeHidden: true,
396+
Paths: []string{"."},
395397
},
396398
},
397399
"invalid output": {
@@ -404,9 +406,34 @@ func Test_walkerOptionsFromContext(t *testing.T) {
404406
Config: &todos.Config{
405407
Types: []string{"TODO", "FIXME"},
406408
},
407-
Charset: defaultCharset,
408-
IncludeHidden: true,
409-
Paths: []string{"."},
409+
Charset: defaultCharset,
410+
IgnoreFileNames: defaultIgnoreFilenames,
411+
IncludeHidden: true,
412+
Paths: []string{"."},
413+
},
414+
},
415+
"ignore filename": {
416+
args: []string{"--ignore-file-name=todo.ignore"},
417+
expected: &walker.Options{
418+
Config: &todos.Config{
419+
Types: todos.DefaultTypes,
420+
},
421+
Charset: defaultCharset,
422+
IgnoreFileNames: []string{"todo.ignore"},
423+
IncludeHidden: true,
424+
Paths: []string{"."},
425+
},
426+
},
427+
"ignore filename multiple": {
428+
args: []string{"--ignore-file-name=todo.ignore", "--ignore-file-name=.todo.ignore"},
429+
expected: &walker.Options{
430+
Config: &todos.Config{
431+
Types: todos.DefaultTypes,
432+
},
433+
Charset: defaultCharset,
434+
IgnoreFileNames: []string{"todo.ignore", ".todo.ignore"},
435+
IncludeHidden: true,
436+
Paths: []string{"."},
410437
},
411438
},
412439
"exclude-hidden": {
@@ -415,9 +442,10 @@ func Test_walkerOptionsFromContext(t *testing.T) {
415442
Config: &todos.Config{
416443
Types: todos.DefaultTypes,
417444
},
418-
Charset: defaultCharset,
419-
IncludeHidden: false,
420-
Paths: []string{"."},
445+
Charset: defaultCharset,
446+
IgnoreFileNames: defaultIgnoreFilenames,
447+
IncludeHidden: false,
448+
Paths: []string{"."},
421449
},
422450
},
423451
"include-vcs": {
@@ -426,10 +454,11 @@ func Test_walkerOptionsFromContext(t *testing.T) {
426454
Config: &todos.Config{
427455
Types: todos.DefaultTypes,
428456
},
429-
Charset: defaultCharset,
430-
IncludeHidden: true,
431-
IncludeVCS: true,
432-
Paths: []string{"."},
457+
Charset: defaultCharset,
458+
IgnoreFileNames: defaultIgnoreFilenames,
459+
IncludeHidden: true,
460+
IncludeVCS: true,
461+
Paths: []string{"."},
433462
},
434463
},
435464
"include-vendored": {
@@ -439,6 +468,7 @@ func Test_walkerOptionsFromContext(t *testing.T) {
439468
Types: todos.DefaultTypes,
440469
},
441470
Charset: defaultCharset,
471+
IgnoreFileNames: defaultIgnoreFilenames,
442472
IncludeHidden: true,
443473
IncludeVendored: true,
444474
Paths: []string{"."},
@@ -450,9 +480,10 @@ func Test_walkerOptionsFromContext(t *testing.T) {
450480
Config: &todos.Config{
451481
Types: todos.DefaultTypes,
452482
},
453-
Charset: defaultCharset,
454-
IncludeHidden: true,
455-
Paths: []string{"/path/to/code"},
483+
Charset: defaultCharset,
484+
IgnoreFileNames: defaultIgnoreFilenames,
485+
IncludeHidden: true,
486+
Paths: []string{"/path/to/code"},
456487
},
457488
},
458489
"multiple-paths": {
@@ -461,9 +492,10 @@ func Test_walkerOptionsFromContext(t *testing.T) {
461492
Config: &todos.Config{
462493
Types: todos.DefaultTypes,
463494
},
464-
Charset: defaultCharset,
465-
IncludeHidden: true,
466-
Paths: []string{"/path/to/code", "/other/path"},
495+
Charset: defaultCharset,
496+
IgnoreFileNames: defaultIgnoreFilenames,
497+
IncludeHidden: true,
498+
Paths: []string{"/path/to/code", "/other/path"},
467499
},
468500
},
469501
"exclude-multiple": {
@@ -472,10 +504,11 @@ func Test_walkerOptionsFromContext(t *testing.T) {
472504
Config: &todos.Config{
473505
Types: todos.DefaultTypes,
474506
},
475-
Charset: defaultCharset,
476-
IncludeHidden: true,
477-
ExcludeGlobs: []glob.Glob{glob.MustCompile("exclude.*"), glob.MustCompile("foo")},
478-
Paths: []string{"."},
507+
Charset: defaultCharset,
508+
IgnoreFileNames: defaultIgnoreFilenames,
509+
IncludeHidden: true,
510+
ExcludeGlobs: []glob.Glob{glob.MustCompile("exclude.*"), glob.MustCompile("foo")},
511+
Paths: []string{"."},
479512
},
480513
},
481514
"exclude-dir-multiple": {
@@ -485,6 +518,7 @@ func Test_walkerOptionsFromContext(t *testing.T) {
485518
Types: todos.DefaultTypes,
486519
},
487520
Charset: defaultCharset,
521+
IgnoreFileNames: defaultIgnoreFilenames,
488522
IncludeHidden: true,
489523
ExcludeDirGlobs: []glob.Glob{glob.MustCompile("exclude?"), glob.MustCompile("foo")},
490524
Paths: []string{"."},
@@ -497,6 +531,7 @@ func Test_walkerOptionsFromContext(t *testing.T) {
497531
Types: todos.DefaultTypes,
498532
},
499533
Charset: defaultCharset,
534+
IgnoreFileNames: defaultIgnoreFilenames,
500535
IncludeHidden: true,
501536
ExcludeDirGlobs: []glob.Glob{glob.MustCompile("exclude")},
502537
Paths: []string{"."},
@@ -508,9 +543,10 @@ func Test_walkerOptionsFromContext(t *testing.T) {
508543
Config: &todos.Config{
509544
Types: todos.DefaultTypes,
510545
},
511-
Charset: "UTF-16",
512-
IncludeHidden: true,
513-
Paths: []string{"."},
546+
Charset: "UTF-16",
547+
IgnoreFileNames: defaultIgnoreFilenames,
548+
IncludeHidden: true,
549+
Paths: []string{"."},
514550
},
515551
},
516552
"detect charset": {
@@ -519,9 +555,10 @@ func Test_walkerOptionsFromContext(t *testing.T) {
519555
Config: &todos.Config{
520556
Types: todos.DefaultTypes,
521557
},
522-
Charset: "detect",
523-
IncludeHidden: true,
524-
Paths: []string{"."},
558+
Charset: "detect",
559+
IgnoreFileNames: defaultIgnoreFilenames,
560+
IncludeHidden: true,
561+
Paths: []string{"."},
525562
},
526563
},
527564
"invalid charset": {
@@ -534,10 +571,11 @@ func Test_walkerOptionsFromContext(t *testing.T) {
534571
Config: &todos.Config{
535572
Types: todos.DefaultTypes,
536573
},
537-
LabelGlobs: []glob.Glob{glob.MustCompile("foo"), glob.MustCompile("bar-*")},
538-
Charset: defaultCharset,
539-
IncludeHidden: true,
540-
Paths: []string{"."},
574+
LabelGlobs: []glob.Glob{glob.MustCompile("foo"), glob.MustCompile("bar-*")},
575+
Charset: defaultCharset,
576+
IgnoreFileNames: defaultIgnoreFilenames,
577+
IncludeHidden: true,
578+
Paths: []string{"."},
541579
},
542580
},
543581
}

0 commit comments

Comments
 (0)