From 98db9d7da6f6c8d77f65c0547e087a52580bf514 Mon Sep 17 00:00:00 2001 From: Nathan Byrd Date: Tue, 27 Jul 2021 18:10:08 -0500 Subject: [PATCH] Support .ignore and clean up tests/documentation (#114) * 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 --- README.md | 4 ++-- cmd/root.go | 2 +- pkg/ignore/ignore.go | 1 + pkg/ignore/ignore_test.go | 24 ++++++++++++++++++++++++ pkg/ignore/testdata/.ignore | 1 + pkg/ignore/testdata/.notignored | 1 + pkg/ignore/testdata/.wokeignore | 1 + 7 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 pkg/ignore/testdata/.ignore create mode 100644 pkg/ignore/testdata/.notignored create mode 100644 pkg/ignore/testdata/.wokeignore diff --git a/README.md b/README.md index 3a2cef5e..060d9e29 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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` diff --git a/cmd/root.go b/cmd/root.go index 601a2c5c..db5a462a 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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)) } diff --git a/pkg/ignore/ignore.go b/pkg/ignore/ignore.go index 6d3b73d5..c0ca3cd8 100644 --- a/pkg/ignore/ignore.go +++ b/pkg/ignore/ignore.go @@ -18,6 +18,7 @@ type Ignore struct { var defaultIgnoreFiles = []string{ ".gitignore", + ".ignore", ".wokeignore", ".git/info/exclude", } diff --git a/pkg/ignore/ignore_test.go b/pkg/ignore/ignore_test.go index eb9d1fd5..36d021b5 100644 --- a/pkg/ignore/ignore_test.go +++ b/pkg/ignore/ignore_test.go @@ -1,6 +1,7 @@ package ignore import ( + "os" "runtime" "testing" @@ -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) diff --git a/pkg/ignore/testdata/.ignore b/pkg/ignore/testdata/.ignore new file mode 100644 index 00000000..1caa4714 --- /dev/null +++ b/pkg/ignore/testdata/.ignore @@ -0,0 +1 @@ +*.IGNORE diff --git a/pkg/ignore/testdata/.notignored b/pkg/ignore/testdata/.notignored new file mode 100644 index 00000000..aa39ea77 --- /dev/null +++ b/pkg/ignore/testdata/.notignored @@ -0,0 +1 @@ +*.NOTIGNORED diff --git a/pkg/ignore/testdata/.wokeignore b/pkg/ignore/testdata/.wokeignore new file mode 100644 index 00000000..f0ab2a94 --- /dev/null +++ b/pkg/ignore/testdata/.wokeignore @@ -0,0 +1 @@ +*.WOKEIGNORE