[lint] Ignore `/vendor/` by default when linting

284 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Feb 21, 2018, 5:54:48 PM2/21/18
to Ian Lance Taylor, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot has uploaded this change for review.

View Change

Ignore `/vendor/` by default when linting

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.

Change-Id: I44a85ca633d2f9fd7083c6844a702b650b269325
GitHub-Last-Rev: 0dcd199f6e2c9e5fb738b78bfa2170de4c78a25f
GitHub-Pull-Request: golang/lint#325
---
M golint/golint.go
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/golint/golint.go b/golint/golint.go
index d8360ad..0088274 100644
--- a/golint/golint.go
+++ b/golint/golint.go
@@ -48,9 +48,12 @@
var dirsRun, filesRun, pkgsRun int
var args []string
for _, arg := range flag.Args() {
- if strings.HasSuffix(arg, "/...") && isDir(arg[:len(arg)-len("/...")]) {
+ if trimmedArg := strings.TrimSuffix(arg, "/..."); trimmedArg != arg && isDir(trimmedArg) {
dirsRun = 1
for _, dirname := range allPackagesInFS(arg) {
+ if strings.Contains(dirname[len(trimmedArg):], "/vendor/") {
+ continue
+ }
args = append(args, dirname)
}
} else if isDir(arg) {

To view, visit change 96085. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: lint
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I44a85ca633d2f9fd7083c6844a702b650b269325
Gerrit-Change-Number: 96085
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>

Gobot Gobot (Gerrit)

unread,
Feb 21, 2018, 5:54:52 PM2/21/18
to Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

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.

View Change

    To view, visit change 96085. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: lint
    Gerrit-Branch: master
    Gerrit-MessageType: comment
    Gerrit-Change-Id: I44a85ca633d2f9fd7083c6844a702b650b269325
    Gerrit-Change-Number: 96085
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Gobot Gobot <go...@golang.org>
    Gerrit-Comment-Date: Wed, 21 Feb 2018 22:54:50 +0000
    Gerrit-HasComments: No
    Gerrit-HasLabels: No

    Joe Richey (Gerrit)

    unread,
    Feb 21, 2018, 6:21:43 PM2/21/18
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Gobot Gobot, golang-co...@googlegroups.com

    See previous comments:
    https://github.com/golang/lint/pull/325#issuecomment-364845741
    https://github.com/golang/lint/pull/325#issuecomment-365101260

    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

    Patch set 1:Code-Review +1

    View Change

      To view, visit change 96085. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: lint
      Gerrit-Branch: master
      Gerrit-MessageType: comment
      Gerrit-Change-Id: I44a85ca633d2f9fd7083c6844a702b650b269325
      Gerrit-Change-Number: 96085
      Gerrit-PatchSet: 1
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Joe Richey <joer...@google.com>
      Gerrit-CC: Gobot Gobot <go...@golang.org>
      Gerrit-Comment-Date: Wed, 21 Feb 2018 23:21:41 +0000
      Gerrit-HasComments: No
      Gerrit-HasLabels: Yes

      Wèi Cōngruì (Gerrit)

      unread,
      Apr 25, 2018, 12:09:16 AM4/25/18
      to Gerrit Bot, goph...@pubsubhelper.golang.org, Dmitry Vyukov, Daniel Martí, Brad Fitzpatrick, Joe Richey, Gobot Gobot, golang-co...@googlegroups.com

      Please take a look.

      View Change

        To view, visit change 96085. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: lint
        Gerrit-Branch: master
        Gerrit-Change-Id: I44a85ca633d2f9fd7083c6844a702b650b269325
        Gerrit-Change-Number: 96085
        Gerrit-PatchSet: 1
        Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
        Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-Reviewer: Daniel Martí <mv...@mvdan.cc>
        Gerrit-Reviewer: Dmitry Vyukov <dvy...@google.com>
        Gerrit-Reviewer: Joe Richey <joer...@google.com>
        Gerrit-CC: Gobot Gobot <go...@golang.org>
        Gerrit-CC: Wèi Cōngruì <crvv...@gmail.com>
        Gerrit-Comment-Date: Wed, 25 Apr 2018 04:09:09 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: No
        Gerrit-MessageType: comment

        Alan Donovan (Gerrit)

        unread,
        Apr 27, 2018, 5:09:30 PM4/27/18
        to Gerrit Bot, goph...@pubsubhelper.golang.org, Dmitry Vyukov, Daniel Martí, Brad Fitzpatrick, Wèi Cōngruì, Joe Richey, Gobot Gobot, golang-co...@googlegroups.com

        View Change

        1 comment:

        • File golint/golint.go:

          • Patch Set #1, Line 54: if strings.Contains(dirname[len(trimmedArg):], "/vendor/") {

            If arg is a relative path that starts with "vendor/", this check won't match it.
            Usually this pattern requires two checks, Contains("/x/") || HasPrefix("x/").

        To view, visit change 96085. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: lint
        Gerrit-Branch: master
        Gerrit-Change-Id: I44a85ca633d2f9fd7083c6844a702b650b269325
        Gerrit-Change-Number: 96085
        Gerrit-PatchSet: 1
        Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
        Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-Reviewer: Daniel Martí <mv...@mvdan.cc>
        Gerrit-Reviewer: Dmitry Vyukov <dvy...@google.com>
        Gerrit-Reviewer: Joe Richey <joer...@google.com>
        Gerrit-CC: Alan Donovan <adon...@google.com>
        Gerrit-CC: Gobot Gobot <go...@golang.org>
        Gerrit-CC: Wèi Cōngruì <crvv...@gmail.com>
        Gerrit-Comment-Date: Fri, 27 Apr 2018 21:09:28 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        Gerrit-MessageType: comment

        Andrew Bonventre (Gerrit)

        unread,
        Apr 27, 2018, 5:35:07 PM4/27/18
        to Gerrit Bot, goph...@pubsubhelper.golang.org, Alan Donovan, Dmitry Vyukov, Daniel Martí, Brad Fitzpatrick, Wèi Cōngruì, Joe Richey, Gobot Gobot, golang-co...@googlegroups.com

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

        View Change

          To view, visit change 96085. To unsubscribe, or for help writing mail filters, visit settings.

          Gerrit-Project: lint
          Gerrit-Branch: master
          Gerrit-Change-Id: I44a85ca633d2f9fd7083c6844a702b650b269325
          Gerrit-Change-Number: 96085
          Gerrit-PatchSet: 1
          Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
          Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
          Gerrit-Reviewer: Daniel Martí <mv...@mvdan.cc>
          Gerrit-Reviewer: Dmitry Vyukov <dvy...@google.com>
          Gerrit-Reviewer: Joe Richey <joer...@google.com>
          Gerrit-CC: Alan Donovan <adon...@google.com>
          Gerrit-CC: Andrew Bonventre <andy...@golang.org>
          Gerrit-CC: Gobot Gobot <go...@golang.org>
          Gerrit-CC: Wèi Cōngruì <crvv...@gmail.com>
          Gerrit-Comment-Date: Fri, 27 Apr 2018 21:35:05 +0000

          Daniel Martí (Gerrit)

          unread,
          May 8, 2021, 4:27:48 PM5/8/21
          to Gerrit Bot, goph...@pubsubhelper.golang.org, Andrew Bonventre, Dmitry Vyukov, Brad Fitzpatrick, Wèi Cōngruì, Joe Richey, Go Bot, golang-co...@googlegroups.com

          Daniel Martí abandoned this change.

          View Change

          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] https://github.com/golang/go/issues/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

          To view, visit change 96085. To unsubscribe, or for help writing mail filters, visit settings.

          Gerrit-Project: lint
          Gerrit-Branch: master
          Gerrit-Change-Id: I44a85ca633d2f9fd7083c6844a702b650b269325
          Gerrit-Change-Number: 96085
          Gerrit-PatchSet: 1
          Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
          Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
          Gerrit-Reviewer: Daniel Martí <mv...@mvdan.cc>
          Gerrit-Reviewer: Dmitry Vyukov <dvy...@google.com>
          Gerrit-Reviewer: Joe Richey <joer...@google.com>
          Gerrit-CC: Alan Donovan <al...@alandonovan.net>
          Gerrit-CC: Andrew Bonventre <andy...@golang.org>
          Gerrit-CC: Go Bot <go...@golang.org>
          Gerrit-CC: Wèi Cōngruì <crvv...@gmail.com>
          Gerrit-MessageType: abandon
          Reply all
          Reply to author
          Forward
          0 new messages