-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
misspell: add extra-words #4401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
95dbd8d
misspell: add extra-words
ldez e1baa5a
Apply suggestions from code review
ldez 2ebe8a9
review: dedicated error for empty fields
ldez 96eea0e
review: unit tests
ldez 73f18d7
tests: more tests
ldez 64b11b9
feat: better error message
ldez ca4bb50
feat: refactor
ldez 5e4dffc
review
ldez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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", | ||
}, | ||
} | ||
ldez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 hidden or 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" | ||
ldez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
correction: "if" | ||
- typo: "cancelation" | ||
correction: "cancellation" |
This file contains hidden or 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 | ||
ldez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//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\\`" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.