Skip to content

Commit

Permalink
Support .ignore and clean up tests/documentation (#114)
Browse files Browse the repository at this point in the history
* Added .ignore and tests for default ignore files

* Updated documentation for .ignore and others

* Fixed lint error

* Changed test to use assert and Cleanup

* Clean up whitespace

* Changed to assert.NoError
  • Loading branch information
cognitivegears authored Jul 27, 2021
1 parent e033c82 commit 98db9d7
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Flags:
--debug Enable debug logging
--exit-1-on-failure Exit with exit code 1 on failures
-h, --help help for woke
--no-ignore Ignored files in .gitignore/.wokeignore and inline ignores are processed
--no-ignore Ignored files in .gitignore, .ignore, .wokeignore, .git/info/exclude, and inline ignores are processed
-o, --output string Output type [text,simple,github-actions,json] (default "text")
--stdin Read from stdin
-v, --version version for woke
Expand Down Expand Up @@ -271,7 +271,7 @@ ignore_files:
- globs/too/*
```
`woke` will also automatically ignore anything listed in `.gitignore` and `.git/info/exclude`.
`woke` will also automatically ignore anything listed in `.gitignore`, `.ignore`, and `.git/info/exclude`.

#### `.wokeignore`

Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func init() {
rootCmd.PersistentFlags().BoolVar(&exitOneOnFailure, "exit-1-on-failure", false, "Exit with exit code 1 on failures")
rootCmd.PersistentFlags().BoolVar(&stdin, "stdin", false, "Read from stdin")
rootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "Enable debug logging")
rootCmd.PersistentFlags().BoolVar(&noIgnore, "no-ignore", false, "Ignored files in .gitignore/.wokeignore and inline ignores are processed")
rootCmd.PersistentFlags().BoolVar(&noIgnore, "no-ignore", false, "Ignored files in .gitignore, .ignore, .wokeignore, .git/info/exclude, and inline ignores are processed")
rootCmd.PersistentFlags().StringVarP(&outputName, "output", "o", printer.OutFormatText, fmt.Sprintf("Output type [%s]", printer.OutFormatsString))
}

Expand Down
1 change: 1 addition & 0 deletions pkg/ignore/ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Ignore struct {

var defaultIgnoreFiles = []string{
".gitignore",
".ignore",
".wokeignore",
".git/info/exclude",
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/ignore/ignore_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ignore

import (
"os"
"runtime"
"testing"

Expand All @@ -27,6 +28,29 @@ func TestIgnore_Match(t *testing.T) {
}
}

// Test all default ignore files, except for .git/info/exclude, since
// that uses a .git directory that we cannot check in.
func TestIgnoreDefaultIgoreFiles_Match(t *testing.T) {
// Temporarily change into testdata directojry for this test
// since paths are relative
err := os.Chdir("testdata")
assert.NoError(t, err)
t.Cleanup(func() {
err = os.Chdir("..")
assert.NoError(t, err)
})

i := NewIgnore([]string{"*.FROMARGUMENT"})
assert.NotNil(t, i)

assert.False(t, i.Match("notfoo"))
assert.True(t, i.Match("test.FROMARGUMENT")) // From .gitignore
assert.True(t, i.Match("test.DS_Store")) // From .gitignore
assert.True(t, i.Match("test.IGNORE")) // From .ignore
assert.True(t, i.Match("test.WOKEIGNORE")) // From .wokeignore
assert.False(t, i.Match("test.NOTIGNORED")) // From .notincluded - making sure only default are included
}

func TestReadIgnoreFile(t *testing.T) {
ignoreLines := readIgnoreFile("testdata/.gitignore")
assert.Equal(t, []string{"*.DS_Store"}, ignoreLines)
Expand Down
1 change: 1 addition & 0 deletions pkg/ignore/testdata/.ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.IGNORE
1 change: 1 addition & 0 deletions pkg/ignore/testdata/.notignored
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.NOTIGNORED
1 change: 1 addition & 0 deletions pkg/ignore/testdata/.wokeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.WOKEIGNORE

0 comments on commit 98db9d7

Please sign in to comment.