Giter Club home page Giter Club logo

lint's People

Contributors

glyphack avatar jpeach avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

lint's Issues

pkg/analysis/importalias: Panic with stdlib import alias

What steps did you take and what happened:

package a

import (
	wrong_alias "fmt"
	alias_os "os"
)
panic: runtime error: index out of range [-1]

goroutine 2325 [running]:
github.com/projectcontour/lint/pkg/analysis/importalias.getAliasFix(0xc0058f7a90, 0x0, 0x0, 0xc0058f7a90, 0x0)
        /home/ldez/sources/go/src/github.com/projectcontour/lint/pkg/analysis/importalias/analyzer.go:160 +0x1ca
github.com/projectcontour/lint/pkg/analysis/importalias.run.func1(0x73bde0, 0xc0062546f0)
        /home/ldez/sources/go/src/github.com/projectcontour/lint/pkg/analysis/importalias/analyzer.go:96 +0x3f3
golang.org/x/tools/go/ast/inspector.(*Inspector).Preorder(0xc009fba5e8, 0xc0048beb48, 0x1, 0x1, 0xc0048beb38)
        /home/ldez/sources/go/pkg/mod/golang.org/x/[email protected]/go/ast/inspector/inspector.go:77 +0xa2
github.com/projectcontour/lint/pkg/analysis/importalias.run(0xc0058d8f70, 0xc0058d8f70, 0x0, 0x0, 0x0)
        /home/ldez/sources/go/src/github.com/projectcontour/lint/pkg/analysis/importalias/analyzer.go:41 +0xcd
golang.org/x/tools/go/analysis/internal/checker.(*action).execOnce(0xc0023c7180)
        /home/ldez/sources/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:691 +0x85f
sync.(*Once).doSlow(0xc0023c7180, 0xc000176790)
        /home/ldez/.gvm/gos/go1.16/src/sync/once.go:68 +0xec
sync.(*Once).Do(...)
        /home/ldez/.gvm/gos/go1.16/src/sync/once.go:59
golang.org/x/tools/go/analysis/internal/checker.(*action).exec(0xc0023c7180)
        /home/ldez/sources/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:579 +0x65
golang.org/x/tools/go/analysis/internal/checker.execAll.func1(0xc0023c7180)
        /home/ldez/sources/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:567 +0x34
created by golang.org/x/tools/go/analysis/internal/checker.execAll
        /home/ldez/sources/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:573 +0x125

What did you expect to happen:

Don't panic

Wrong version extraction for some packages

What steps did you take and what happened:
[A clear and concise description of what the bug is.]
I ran linter on contour project And got this:

internal/featuretests/tlsprotocolversion_test.go:20:2: version "auth" not specified in alias "envoy_api_v2_auth" for import path "github/com/envoyproxy/gocontrolplane/envoy/api/v2/auth"
internal/featuretests/tlsprotocolversion_test.go:21:2: version "listener" not specified in alias "envoy_api_v2_listener" for import path "github/com/envoyproxy/gocontrolplane/envoy/api/v2/listener"

What did you expect to happen:
package is couting listener as version, but it's not it should be v2.

Fixing the import alias leaves orphaned symbols

After running with the -fix option, the linter rewrites the import paths,

diff --git internal/k8s/log.go internal/k8s/log.go
index 8a6974fc..73899219 100644
--- internal/k8s/log.go
+++ internal/k8s/log.go
@@ -24,7 +24,7 @@ import (
        "strings"

        "github.com/sirupsen/logrus"
-       klog "k8s.io/klog/v2"
+       klog_v2 "k8s.io/klog/v2"
 )

 type klogParams struct {

But all the symbols that are used from that package are still using the old import path. It's left to the maintainer to update each file that gets it import paths fixed.

This is OK for the CI use case since the goal there is to give automated style feedback to contributors (it's not too onerous for them to fix it by hand). It's a bit more onerous to get the existing codebase up to standard, but that's a one time cost.

So we could rewrite all the symbols, but if it's a lot of extra AST work, it might not be worth the effort.

Add fix option

Please describe the problem you have
We can use multicheker to have -fix flag.

Release automation

Please describe the problem you have
Since this package is intended to be used as a golangci lint plugin it would be nice to have some sort of release automation like this:

  • after every tag a pipeline triggers and build the .so package file and upload it somewhere.

pkg/analysis/importalias: Panic with anonymous import alias

What steps did you take and what happened:

package a

import (
	_ "embed"
)
panic: runtime error: index out of range [-1]

goroutine 1838 [running]:
github.com/projectcontour/lint/pkg/analysis/importalias.getAliasFix(0xc0097dc8a0, 0x0, 0x0, 0xc0097dc8a0, 0x0)
        /home/ldez/sources/go/src/github.com/projectcontour/lint/pkg/analysis/importalias/analyzer.go:160 +0x1ca
github.com/projectcontour/lint/pkg/analysis/importalias.run.func1(0x73bde0, 0xc0097df950)
        /home/ldez/sources/go/src/github.com/projectcontour/lint/pkg/analysis/importalias/analyzer.go:96 +0x3f3
golang.org/x/tools/go/ast/inspector.(*Inspector).Preorder(0xc0097c0b70, 0xc000216b48, 0x1, 0x1, 0xc000216b38)
        /home/ldez/sources/go/pkg/mod/golang.org/x/[email protected]/go/ast/inspector/inspector.go:77 +0xa2
github.com/projectcontour/lint/pkg/analysis/importalias.run(0xc0097ad6c0, 0xc0097ad6c0, 0x0, 0x0, 0x0)
        /home/ldez/sources/go/src/github.com/projectcontour/lint/pkg/analysis/importalias/analyzer.go:41 +0xcd
golang.org/x/tools/go/analysis/internal/checker.(*action).execOnce(0xc0097648c0)
        /home/ldez/sources/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:691 +0x85f
sync.(*Once).doSlow(0xc0097648c0, 0xc000176790)
        /home/ldez/.gvm/gos/go1.16/src/sync/once.go:68 +0xec
sync.(*Once).Do(...)
        /home/ldez/.gvm/gos/go1.16/src/sync/once.go:59
golang.org/x/tools/go/analysis/internal/checker.(*action).exec(0xc0097648c0)
        /home/ldez/sources/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:579 +0x65
golang.org/x/tools/go/analysis/internal/checker.execAll.func1(0xc0097648c0)
        /home/ldez/sources/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:567 +0x34
created by golang.org/x/tools/go/analysis/internal/checker.execAll
        /home/ldez/sources/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:573 +0x125

What did you expect to happen:

Don't panic

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.