Skip to content

Commit

Permalink
feat: Add ignore file support (#1638)
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Lewis <[email protected]>
  • Loading branch information
ianlewis authored Feb 28, 2025
1 parent 95d3b0b commit 8c41753
Show file tree
Hide file tree
Showing 6 changed files with 435 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pre-submit.units.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ jobs:
with:
go-version-file: "go.mod"
- env:
GOLANGCI_LINT_VERSION: "1.61.0"
GOLANGCI_LINT_CHECKSUM: "77cb0af99379d9a21d5dc8c38364d060e864a01bd2f3e30b5e8cc550c3a54111"
GOLANGCI_LINT_VERSION: "1.64.5"
GOLANGCI_LINT_CHECKSUM: "e6bd399a0479c5fd846dcf9f3990d20448b4f0d1e5027d82348eab9f80f7ac71"
run: |
set -euo pipefail
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes 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

### Changed

- `todos` now parses `.gitignore` and `.todosignore` files and ignores those
files. ([#125](https://github.com/ianlewis/todos/issues/125)).

## [0.11.0] - 2025-02-12

### Fixed in 0.11.0
Expand Down
9 changes: 9 additions & 0 deletions internal/cmd/todos/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const (

const defaultCharset = "UTF-8"

var defaultIgnoreFilenames = []string{".gitignore", ".todosignore"}

var (
// ErrFlagParse is a flag parsing error.
ErrFlagParse = errors.New("parsing flags")
Expand Down Expand Up @@ -117,6 +119,11 @@ func newTODOsApp() *cli.App {
Usage: "exclude hidden files and directories",
DisableDefaultText: true,
},
&cli.StringSliceFlag{
Name: "ignore-file-name",
Usage: "name of files with ignore patterns (.gitignore format)",
Value: cli.NewStringSlice(defaultIgnoreFilenames...),
},
&cli.BoolFlag{
Name: "include-vcs",
Usage: "include version control directories (.git, .hg, .svn)",
Expand Down Expand Up @@ -387,6 +394,8 @@ func walkerOptionsFromContext(c *cli.Context) (*walker.Options, error) {
o.IncludeVCS = c.Bool("include-vcs")
o.IncludeVendored = c.Bool("include-vendored")

o.IgnoreFileNames = c.StringSlice("ignore-file-name")

// Filters
for _, label := range c.StringSlice("label") {
g, err := glob.Compile(label)
Expand Down
110 changes: 74 additions & 36 deletions internal/cmd/todos/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,10 @@ func Test_walkerOptionsFromContext(t *testing.T) {
Config: &todos.Config{
Types: todos.DefaultTypes,
},
Charset: defaultCharset,
IncludeHidden: true,
Paths: []string{"."},
Charset: defaultCharset,
IgnoreFileNames: defaultIgnoreFilenames,
IncludeHidden: true,
Paths: []string{"."},
},
},
"output github": {
Expand All @@ -389,9 +390,10 @@ func Test_walkerOptionsFromContext(t *testing.T) {
Config: &todos.Config{
Types: todos.DefaultTypes,
},
Charset: defaultCharset,
IncludeHidden: true,
Paths: []string{"."},
Charset: defaultCharset,
IgnoreFileNames: defaultIgnoreFilenames,
IncludeHidden: true,
Paths: []string{"."},
},
},
"invalid output": {
Expand All @@ -404,9 +406,34 @@ func Test_walkerOptionsFromContext(t *testing.T) {
Config: &todos.Config{
Types: []string{"TODO", "FIXME"},
},
Charset: defaultCharset,
IncludeHidden: true,
Paths: []string{"."},
Charset: defaultCharset,
IgnoreFileNames: defaultIgnoreFilenames,
IncludeHidden: true,
Paths: []string{"."},
},
},
"ignore filename": {
args: []string{"--ignore-file-name=todo.ignore"},
expected: &walker.Options{
Config: &todos.Config{
Types: todos.DefaultTypes,
},
Charset: defaultCharset,
IgnoreFileNames: []string{"todo.ignore"},
IncludeHidden: true,
Paths: []string{"."},
},
},
"ignore filename multiple": {
args: []string{"--ignore-file-name=todo.ignore", "--ignore-file-name=.todo.ignore"},
expected: &walker.Options{
Config: &todos.Config{
Types: todos.DefaultTypes,
},
Charset: defaultCharset,
IgnoreFileNames: []string{"todo.ignore", ".todo.ignore"},
IncludeHidden: true,
Paths: []string{"."},
},
},
"exclude-hidden": {
Expand All @@ -415,9 +442,10 @@ func Test_walkerOptionsFromContext(t *testing.T) {
Config: &todos.Config{
Types: todos.DefaultTypes,
},
Charset: defaultCharset,
IncludeHidden: false,
Paths: []string{"."},
Charset: defaultCharset,
IgnoreFileNames: defaultIgnoreFilenames,
IncludeHidden: false,
Paths: []string{"."},
},
},
"include-vcs": {
Expand All @@ -426,10 +454,11 @@ func Test_walkerOptionsFromContext(t *testing.T) {
Config: &todos.Config{
Types: todos.DefaultTypes,
},
Charset: defaultCharset,
IncludeHidden: true,
IncludeVCS: true,
Paths: []string{"."},
Charset: defaultCharset,
IgnoreFileNames: defaultIgnoreFilenames,
IncludeHidden: true,
IncludeVCS: true,
Paths: []string{"."},
},
},
"include-vendored": {
Expand All @@ -439,6 +468,7 @@ func Test_walkerOptionsFromContext(t *testing.T) {
Types: todos.DefaultTypes,
},
Charset: defaultCharset,
IgnoreFileNames: defaultIgnoreFilenames,
IncludeHidden: true,
IncludeVendored: true,
Paths: []string{"."},
Expand All @@ -450,9 +480,10 @@ func Test_walkerOptionsFromContext(t *testing.T) {
Config: &todos.Config{
Types: todos.DefaultTypes,
},
Charset: defaultCharset,
IncludeHidden: true,
Paths: []string{"/path/to/code"},
Charset: defaultCharset,
IgnoreFileNames: defaultIgnoreFilenames,
IncludeHidden: true,
Paths: []string{"/path/to/code"},
},
},
"multiple-paths": {
Expand All @@ -461,9 +492,10 @@ func Test_walkerOptionsFromContext(t *testing.T) {
Config: &todos.Config{
Types: todos.DefaultTypes,
},
Charset: defaultCharset,
IncludeHidden: true,
Paths: []string{"/path/to/code", "/other/path"},
Charset: defaultCharset,
IgnoreFileNames: defaultIgnoreFilenames,
IncludeHidden: true,
Paths: []string{"/path/to/code", "/other/path"},
},
},
"exclude-multiple": {
Expand All @@ -472,10 +504,11 @@ func Test_walkerOptionsFromContext(t *testing.T) {
Config: &todos.Config{
Types: todos.DefaultTypes,
},
Charset: defaultCharset,
IncludeHidden: true,
ExcludeGlobs: []glob.Glob{glob.MustCompile("exclude.*"), glob.MustCompile("foo")},
Paths: []string{"."},
Charset: defaultCharset,
IgnoreFileNames: defaultIgnoreFilenames,
IncludeHidden: true,
ExcludeGlobs: []glob.Glob{glob.MustCompile("exclude.*"), glob.MustCompile("foo")},
Paths: []string{"."},
},
},
"exclude-dir-multiple": {
Expand All @@ -485,6 +518,7 @@ func Test_walkerOptionsFromContext(t *testing.T) {
Types: todos.DefaultTypes,
},
Charset: defaultCharset,
IgnoreFileNames: defaultIgnoreFilenames,
IncludeHidden: true,
ExcludeDirGlobs: []glob.Glob{glob.MustCompile("exclude?"), glob.MustCompile("foo")},
Paths: []string{"."},
Expand All @@ -497,6 +531,7 @@ func Test_walkerOptionsFromContext(t *testing.T) {
Types: todos.DefaultTypes,
},
Charset: defaultCharset,
IgnoreFileNames: defaultIgnoreFilenames,
IncludeHidden: true,
ExcludeDirGlobs: []glob.Glob{glob.MustCompile("exclude")},
Paths: []string{"."},
Expand All @@ -508,9 +543,10 @@ func Test_walkerOptionsFromContext(t *testing.T) {
Config: &todos.Config{
Types: todos.DefaultTypes,
},
Charset: "UTF-16",
IncludeHidden: true,
Paths: []string{"."},
Charset: "UTF-16",
IgnoreFileNames: defaultIgnoreFilenames,
IncludeHidden: true,
Paths: []string{"."},
},
},
"detect charset": {
Expand All @@ -519,9 +555,10 @@ func Test_walkerOptionsFromContext(t *testing.T) {
Config: &todos.Config{
Types: todos.DefaultTypes,
},
Charset: "detect",
IncludeHidden: true,
Paths: []string{"."},
Charset: "detect",
IgnoreFileNames: defaultIgnoreFilenames,
IncludeHidden: true,
Paths: []string{"."},
},
},
"invalid charset": {
Expand All @@ -534,10 +571,11 @@ func Test_walkerOptionsFromContext(t *testing.T) {
Config: &todos.Config{
Types: todos.DefaultTypes,
},
LabelGlobs: []glob.Glob{glob.MustCompile("foo"), glob.MustCompile("bar-*")},
Charset: defaultCharset,
IncludeHidden: true,
Paths: []string{"."},
LabelGlobs: []glob.Glob{glob.MustCompile("foo"), glob.MustCompile("bar-*")},
Charset: defaultCharset,
IgnoreFileNames: defaultIgnoreFilenames,
IncludeHidden: true,
Paths: []string{"."},
},
},
}
Expand Down
Loading

0 comments on commit 8c41753

Please sign in to comment.