-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add nolintlint linter #740
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
Closed
Closed
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6be564b
Add nolintlint linter
ashanbrown 74bc1ec
Remove debug code
ashanbrown b3c1ebc
Add comments to explain nolintlint options
ashanbrown 55f45a8
Renegerate README.md with comments
ashanbrown 10ccf1b
Remove indirect dependencies and rerun vendor
ashanbrown 7a7c07b
Run go mod vendor using go 1.13
ashanbrown f3d7d4a
Add comment to explain exception
ashanbrown 00c5c92
Merge remote-tracking branch 'upstream/master' into asb/nolintlint
ashanbrown 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
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,65 @@ | ||
package golinters | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"go/ast" | ||
|
||
"github.com/ashanbrown/nolintlint/v2/nolintlint" | ||
|
||
"github.com/golangci/golangci-lint/pkg/lint/linter" | ||
"github.com/golangci/golangci-lint/pkg/result" | ||
) | ||
|
||
type NoLintLint struct{} | ||
|
||
func (NoLintLint) Name() string { | ||
return "nolintlint" | ||
} | ||
|
||
func (NoLintLint) Desc() string { | ||
return "Reports ill-formed or insufficient nolint directives" | ||
} | ||
|
||
func (l NoLintLint) Run(ctx context.Context, lintCtx *linter.Context) (results []result.Issue, err error) { | ||
var needs nolintlint.Needs | ||
settings := lintCtx.Settings().NoLintLint | ||
if settings.Explain { | ||
needs |= nolintlint.NeedsExplanation | ||
} | ||
if settings.Machine { | ||
needs |= nolintlint.NeedsMachine | ||
} | ||
if settings.Specific { | ||
needs |= nolintlint.NeedsSpecific | ||
} | ||
lnt, err := nolintlint.NewLinter( | ||
nolintlint.OptionNeeds(needs), | ||
nolintlint.OptionExcludes(settings.Exclude), | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, pkg := range lintCtx.Packages { | ||
files, fset, err := getASTFilesForGoPkg(lintCtx, pkg) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not load files: %s", err) | ||
} | ||
nodes := make([]ast.Node, 0, len(files)) | ||
for _, n := range files { | ||
nodes = append(nodes, n) | ||
} | ||
issues, err := lnt.Run(fset, nodes...) | ||
if err != nil { | ||
return nil, fmt.Errorf("linter failed to run: %s", err) | ||
} | ||
for _, i := range issues { | ||
results = append(results, result.Issue{ | ||
FromLinter: l.Name(), | ||
Text: i.Details(), | ||
Pos: i.Position(), | ||
}) | ||
} | ||
} | ||
return results, nil | ||
} |
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,15 @@ | ||
//args: -Enolintlint | ||
//config: linters-settings.nolintlint.explain=true | ||
//config: linters-settings.nolintlint.specific=true | ||
//config: linters-settings.nolintlint.machine=true | ||
package testdata | ||
|
||
import "fmt" | ||
|
||
func Foo() { | ||
fmt.Println("not specific") //nolint // ERROR "directive `.*` should mention specific linter such as `//nolint:my-linter`" | ||
fmt.Println("not machine readable") // nolint // ERROR "directive `.*` should be written as `//nolint`" | ||
fmt.Println("bad syntax") //nolint: deadcode // ERROR "directive `.*` should match `//nolint\[:<comma-separated-linters>\] \[// <explanation>\]`" | ||
fmt.Println("bad syntax") //nolint:deadcode lll // ERROR "directive `.*` should match `//nolint\[:<comma-separated-linters>\] \[// <explanation>\]`" | ||
fmt.Println("extra spaces") // nolint:deadcode // because // ERROR "directive `.*` should not have more than one leading space" | ||
} |
13 changes: 13 additions & 0 deletions
13
vendor/github.com/ashanbrown/nolintlint/v2/LICENSE
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
vendor/github.com/ashanbrown/nolintlint/v2/nolintlint/config_options.go
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.
Can you make these changes to
README.tmpl.md
and regenerate theREADME.md
from that?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.
My understanding is that this is automatically generated already from somewhere else. I just ran make README.md to create it, so I think this is right but please let me know if there is some other file I should be changing.
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.
You are right, @ashanbrown, it is expected for
README.md
to be re-generated after theREADME.tmpl.md
change. The CI checks specifically for that, forbidding outdatedREADME.md
.So it should be OK.