-
Notifications
You must be signed in to change notification settings - Fork 492
Ignore /vendor/
by default when linting
#325
Conversation
A typical usage for a project is: golint ./... Scanning all vendored packages creates noise, takes time and is usually not useful. Add -vendor flag that controls inclusion of vendor dirs during ... expansion. Note: this changes default behavior as the default value for the flag is false. This is debatable. The rationale for false is: - go tool at tip ignores vendor during fmt and test - people generally don't want to change vendored packages, especially for style
golint/golint.go
Outdated
@@ -22,6 +22,7 @@ import ( | |||
var ( | |||
minConfidence = flag.Float64("min_confidence", 0.8, "minimum confidence of a problem to print it") | |||
setExitStatus = flag.Bool("set_exit_status", false, "set exit status to 1 if any issues are found") | |||
checkVendor = flag.Bool("vendor", false, "include packages in vendor dirs when expanding ...") |
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.
I don't agree with this. cmd/go
doesn't have a flag, and there is no reason why golint
would need one.
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.
Right. As discussed in #303 we should mimic go fmt behavior (no flag).
|
I think it should. I did it on ab1f5ee. You guys can review it beforehand. I don't have any Window machine so I'll try to find one from my colleagues and check the path later. (I'd be thankful if anyone can do that for me!) |
Just test it.
I don't have any windows machine either. But you can check what allPackagesInFS returns, and if it is a path, then use filepath.Join/Separator. |
If I understand this correctly, the paths name := prefix + filepath.ToSlash(path) So I don't think there'll be a problem with the path on Windows. |
Hi guys! Any chance to have this merged soon? |
@lukyth yes, you are right, all paths are reduced to the same form
Yes, it does.
@dvyukov I've tested this pull request on |
Not actively involved in the development of lint, however I am facing this issue. Any idea when this will be merged ? |
Any update ? |
golint/golint.go
Outdated
for _, arg := range flag.Args() { | ||
if strings.HasSuffix(arg, "/...") && isDir(arg[:len(arg)-len("/...")]) { | ||
for _, arg := range flag.Args() { | ||
basePath := arg[:len(arg)-len("/...")] |
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.
There's no guarantee that arg has "/..." as a suffix, nor even that it has length at least four, so this operation will panic for shorter names such as "fmt". Use this pattern to remove an optional suffix:
if y := strings.TrimSuffix(x, "/..."); y != x { ... }
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.
Thanks! I've fixed it according to your suggestion (0dcd199). Could you please check it out again?
This comment has been minimized.
This comment has been minimized.
Ideally, we would just use "golint ./..." to check all our our source files for lint error. However, this does not work because it will include all packages in the vendor directory. The pull request at: golang/lint#325 fixes this issue, so we will use it until the PR has been merged.
LGTM I wanted to make sure this handled the weird edge cases with With a directory structure like:
Also, we are using this patch in our project (added here), and it's working great! |
Just tested the same repository on Windows Server 2016, everything worked perfectly! |
This PR (HEAD: 0dcd199) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/#/c/lint/+/96085 to see it. Tip: You can toggle comments from me using the |
Message from Gobot Gobot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/96085. |
Message from Joe Richey: Patch Set 1: Code-Review+1 See previous comments: Tested with Debian Testing and Windows Server 2016. It seems to properly handle edge cases with vendor expansion. Please don’t reply on this GitHub thread. Visit golang.org/cl/96085. |
Using workaround until golang/lint#325 is merged
Message from Wèi Cōngruì: Patch Set 1: Please take a look. Please don’t reply on this GitHub thread. Visit golang.org/cl/96085. |
Message from Alan Donovan: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/96085. |
Message from Andrew Bonventre: Patch Set 1: Given the long back and forth with this small change, can we please add a test for the matching logic, here? Please don’t reply on this GitHub thread. Visit golang.org/cl/96085. |
Just curious:
|
Any update on this change? |
Still nothing? This has been dragging on for 2 years... Is there any reason not to merge this in that is holding this up? |
There is a comment from Aug last year on gerrit stating:
https://go-review.googlesource.com/c/lint/+/96085#message-a9272499b523bdd8cf26297ee78d071ab8584fb8 So I guess that is what is missing for this PR. |
+1 to completing this, it would've been useful for me today |
+1 to completing this |
This PR is being closed because golang.org/cl/96085 has been abandoned. Thank you for submitting this patch! As proposed[1], we are freezing and deprecating golint. There's no drop-in replacement to golint per se, but you should find that Staticcheck[2] works well in encouraging good Go code, much like golint did in the past, since it also includes style checks. There's always gofmt and "go vet" too, of course. If you would like to contribute further, I'd encourage you to engage Staticcheck's issue tracker[3] or look at vet's open issues[4], as they are both actively maintained. If you have an idea that doesn't fit into either of those tools, you could look at other Go linters[5], or write your own - these days it's fairly straightforward with go/analysis[6]. To help avoid confusion, I'm closing all CLs before we freeze the repository. If you have any feedback, you can leave a comment on the proposal thread where it was decided to deprecate golint - though note that the proposal has been accepted for nearly a year. Thanks! [1] golang/go#38968 |
I'd like to continue from #303. All credits go to @dvyukov's work.
This PR will ignore
/vendor/
by default when linting. Butgolint ./vendor/...
will still lint thatvendor
directory normally.This'll fix #320 and fix #151.