-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add WSL linter #771
Merged
Merged
Add WSL linter #771
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
08de1f8
Add WSL linter
bombsimon 714604b
Use v1.0.0 tag for wsl
bombsimon 94094ce
Don't add specific test file skip, use mutex to add errors
bombsimon 2b7d1b3
Fix goimports error
bombsimon 7de76ca
Add more tests for WSL, bump WSL version
bombsimon dd32ad4
Fix bad go.sum (go mod tidy)
bombsimon 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 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
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,67 @@ | ||
package golinters | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/bombsimon/wsl" | ||
tpounds marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis" | ||
"github.com/golangci/golangci-lint/pkg/lint/linter" | ||
"github.com/golangci/golangci-lint/pkg/result" | ||
"golang.org/x/tools/go/analysis" | ||
) | ||
|
||
const ( | ||
name = "wsl" | ||
) | ||
|
||
// NewWSL returns a new WSL linter. | ||
func NewWSL() *goanalysis.Linter { | ||
var ( | ||
issues []result.Issue | ||
analyzer = &analysis.Analyzer{ | ||
Name: goanalysis.TheOnlyAnalyzerName, | ||
Doc: goanalysis.TheOnlyanalyzerDoc, | ||
} | ||
) | ||
|
||
return goanalysis.NewLinter( | ||
name, | ||
"Whitespace Linter - Forces you to use empty lines!", | ||
[]*analysis.Analyzer{analyzer}, | ||
nil, | ||
).WithContextSetter(func(lintCtx *linter.Context) { | ||
analyzer.Run = func(pass *analysis.Pass) (interface{}, error) { | ||
var ( | ||
errCfg = lintCtx.Settings().WSL | ||
fileNames []string | ||
) | ||
|
||
for _, f := range pass.Files { | ||
pos := pass.Fset.Position(f.Pos()) | ||
|
||
if errCfg.NoTest && strings.HasSuffix(pos.Filename, "_test.go") { | ||
continue | ||
} | ||
|
||
fileNames = append(fileNames, pos.Filename) | ||
} | ||
|
||
wslErrors, _ := wsl.ProcessFiles(fileNames) | ||
if len(wslErrors) == 0 { | ||
return nil, nil | ||
} | ||
|
||
for _, err := range wslErrors { | ||
tpounds marked this conversation as resolved.
Show resolved
Hide resolved
|
||
issues = append(issues, result.Issue{ | ||
FromLinter: name, | ||
Pos: err.Position, | ||
Text: err.Reason, | ||
}) | ||
} | ||
|
||
return nil, nil | ||
} | ||
}).WithIssuesReporter(func(*linter.Context) []result.Issue { | ||
return issues | ||
}).WithLoadMode(goanalysis.LoadModeSyntax) | ||
} |
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,12 @@ | ||
//args: -Ewsl | ||
//config: linters-settings.wsl.tests=1 | ||
package testdata | ||
|
||
func main() { | ||
var ( | ||
y = 0 | ||
) | ||
if y < 1 { // ERROR "if statements should only be cuddled with assignments" | ||
|
||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exclude-rules
. It's not performance effective, I agree, but it should be done in a general way for all linters, not per-linterThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about that, I'll remove this since the configuration isn't needed!