-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
163 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package golinters | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golangci/misspell" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/golangci/golangci-lint/pkg/config" | ||
) | ||
|
||
func Test_appendExtraWords(t *testing.T) { | ||
extraWords := []config.MisspellExtraWords{ | ||
{ | ||
Typo: "iff", | ||
Correction: "if", | ||
}, | ||
{ | ||
Typo: "canCELation", | ||
Correction: "canceLLaTION", | ||
}, | ||
} | ||
|
||
replacer := &misspell.Replacer{} | ||
|
||
err := appendExtraWords(replacer, extraWords) | ||
require.NoError(t, err) | ||
|
||
expected := []string{"iff", "if", "cancelation", "cancellation"} | ||
|
||
assert.Equal(t, replacer.Replacements, expected) | ||
} | ||
|
||
func Test_appendExtraWords_error(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
extraWords []config.MisspellExtraWords | ||
expected string | ||
}{ | ||
{ | ||
desc: "empty fields", | ||
extraWords: []config.MisspellExtraWords{{ | ||
Typo: "", | ||
Correction: "", | ||
}}, | ||
expected: `typo ("") and correction ("") fields should not be empty`, | ||
}, | ||
{ | ||
desc: "empty typo", | ||
extraWords: []config.MisspellExtraWords{{ | ||
Typo: "", | ||
Correction: "if", | ||
}}, | ||
expected: `typo ("") and correction ("if") fields should not be empty`, | ||
}, | ||
{ | ||
desc: "empty correction", | ||
extraWords: []config.MisspellExtraWords{{ | ||
Typo: "iff", | ||
Correction: "", | ||
}}, | ||
expected: `typo ("iff") and correction ("") fields should not be empty`, | ||
}, | ||
{ | ||
desc: "invalid characters in typo", | ||
extraWords: []config.MisspellExtraWords{{ | ||
Typo: "i'ff", | ||
Correction: "if", | ||
}}, | ||
expected: `the word "i'ff" in the 'typo' field should only contain letters`, | ||
}, | ||
{ | ||
desc: "invalid characters in correction", | ||
extraWords: []config.MisspellExtraWords{{ | ||
Typo: "iff", | ||
Correction: "i'f", | ||
}}, | ||
expected: `the word "i'f" in the 'correction' field should only contain letters`, | ||
}, | ||
} | ||
|
||
for _, test := range testCases { | ||
test := test | ||
t.Run(test.desc, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
replacer := &misspell.Replacer{} | ||
|
||
err := appendExtraWords(replacer, test.extraWords) | ||
require.EqualError(t, err, test.expected) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
linters-settings: | ||
misspell: | ||
extra-words: | ||
- typo: "iff" | ||
correction: "if" | ||
- typo: "cancelation" | ||
correction: "cancellation" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//golangcitest:args -Emisspell | ||
//golangcitest:config_path testdata/configs/misspell_custom.yml | ||
package testdata | ||
|
||
func Misspell() { | ||
// comment with incorrect spelling: occured // want "`occured` is a misspelling of `occurred`" | ||
} | ||
|
||
// the word iff should be reported here // want "\\`iff\\` is a misspelling of \\`if\\`" | ||
// the word cancelation should be reported here // want "\\`cancelation\\` is a misspelling of \\`cancellation\\`" |