Skip to content
This repository has been archived by the owner on May 9, 2021. It is now read-only.

Ignore /vendor/ by default when linting #325

Closed
wants to merge 5 commits into from

Conversation

lukyth
Copy link

@lukyth lukyth commented Sep 4, 2017

I'd like to continue from #303. All credits go to @dvyukov's work.

This PR will ignore /vendor/ by default when linting. But golint ./vendor/... will still lint that vendor directory normally.

This'll fix #320 and fix #151.

dvyukov and others added 2 commits June 14, 2017 14:52
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 ...")
Copy link
Member

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.

Copy link
Member

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).

@lukyth
Copy link
Author

lukyth commented Sep 12, 2017

@mvdan @dvyukov I removed the flag and made the command ignore vendor/. Do I understand this correctly?

@dvyukov
Copy link
Member

dvyukov commented Sep 12, 2017

golint ./vendor/... should still verify all vendor packages. Does it?
Does allPackagesInFS return package names or paths? If paths, then / will be \ on windows.

@lukyth
Copy link
Author

lukyth commented Sep 12, 2017

golint ./vendor/... should still verify all vendor packages. Does it?

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!)

@dvyukov
Copy link
Member

dvyukov commented Sep 12, 2017

I think it should.

Just test it.

I don't have any Window machine so I'll try to find one from my colleagues and check the path later.

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.

@lukyth
Copy link
Author

lukyth commented Sep 14, 2017

If I understand this correctly, the paths allPackageInFs returns will have its separator replaced with / by this line of code.

name := prefix + filepath.ToSlash(path)

So I don't think there'll be a problem with the path on Windows.

@gonzaloserrano
Copy link

Hi guys! Any chance to have this merged soon?

@vvelikodny
Copy link

vvelikodny commented Dec 14, 2017

If I understand this correctly, the paths allPackageInFs returns will have its separator replaced with this line of code.

name := prefix + filepath.ToSlash(path)

So I don't think there'll be a problem with the path on Windows 7 & macOS High Sierra.

@lukyth yes, you are right, all paths are reduced to the same form ./dir1/dir2...

golint ./vendor/... should still verify all vendor packages. Does it?

Yes, it does.

Just test it.

@dvyukov I've tested this pull request on Windows 7 & macOS High Sierra. Everything works well. Guys, let's merge it.

@muudyguy
Copy link

muudyguy commented Jan 22, 2018

Not actively involved in the development of lint, however I am facing this issue. Any idea when this will be merged ?

@remicaumette
Copy link

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("/...")]
Copy link
Contributor

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 { ... }

Copy link
Author

@lukyth lukyth Jan 23, 2018

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?

@dreampuf

This comment has been minimized.

josephlr added a commit to google/fscrypt that referenced this pull request Feb 12, 2018
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.
@josephlr
Copy link
Member

LGTM

I wanted to make sure this handled the weird edge cases with /... expansion. I tested it with this repository, and it had the same matching behavior as go fmt.

With a directory structure like:

.
├── cmd
│   └── vendor
│       ├── foo.go
│       └── bar
│           └── bar.go
└── vendor
    └── baz
        └── baz.go
  • ./... matched cmd/vendor/foo.go
  • ./cmd/... matched cmd/vendor/foo.go
  • ./cmd/vendor matched cmd/vendor/foo.go
  • ./cmd/vendor/... matched cmd/vendor/foo.go and cmd/vendor/bar/bar.go
  • ./vendor/... matched vendor/baz/baz.go

Also, we are using this patch in our project (added here), and it's working great!

@josephlr
Copy link
Member

Just tested the same repository on Windows Server 2016, everything worked perfectly!

@gopherbot
Copy link

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 comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

Message from Gobot Gobot:

Patch Set 1:

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
Within the next week or so, a maintainer will review your change and provide
feedback. See https://golang.org/doc/contribute.html#review for more info and
tips to get your patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.

During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11, it means that this CL will be reviewed as part of the next development
cycle. See https://golang.org/s/release for more details.


Please don’t reply on this GitHub thread. Visit golang.org/cl/96085.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Joe Richey:

Patch Set 1: Code-Review+1

See previous comments:
#325 (comment)
#325 (comment)

Tested with Debian Testing and Windows Server 2016. It seems to properly handle edge cases with vendor expansion.
Edge Cases: https://golang.org/cmd/go/#hdr-Description_of_package_lists
Test Repo: https://github.com/josephlr/golint-325


Please don’t reply on this GitHub thread. Visit golang.org/cl/96085.
After addressing review feedback, remember to publish your drafts!

nstapelbroek added a commit to nstapelbroek/gatekeeper that referenced this pull request Mar 4, 2018
Using workaround until golang/lint#325 is merged
@gopherbot
Copy link

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.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Alan Donovan:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/96085.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

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.
After addressing review feedback, remember to publish your drafts!

@cfiderer
Copy link

cfiderer commented Jul 18, 2018

Just curious:

  • Why do you diverge from the go import handling in golint at all?
  • Is it just a missing test for this non-standard behavior that blocks the merge?
  • How did golint make it into golang.org/x/ with this behavior?
  • Isn't it time to add a test that verifies the correct handling of vendor folders?

@marcusljx
Copy link

Any update on this change?

@davewichers
Copy link

Still nothing? This has been dragging on for 2 years... Is there any reason not to merge this in that is holding this up?

@jackbravo
Copy link

There is a comment from Aug last year on gerrit stating:

Given the long back and forth with this small change, can we please add a test for the matching logic, here?

https://go-review.googlesource.com/c/lint/+/96085#message-a9272499b523bdd8cf26297ee78d071ab8584fb8

So I guess that is what is missing for this PR.

@dfreilich
Copy link

+1 to completing this, it would've been useful for me today

@v1sion
Copy link

v1sion commented Oct 30, 2020

+1 to completing this

@gopherbot
Copy link

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
[2] https://staticcheck.io/
[3] https://github.com/dominikh/go-tools/issues
[4] https://github.com/golang/go/issues?q=is%3Aissue+is%3Aopen+cmd%2Fvet+in%3Atitle
[5] https://github.com/golangci/awesome-go-linters
[6] https://pkg.go.dev/golang.org/x/tools/go/analysis

@gopherbot gopherbot closed this May 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

exclude vendor dir from matching ... add support for GO15VENDOREXPERIMENT