Skip to content

Fix handling of imports with multiple slashes #4

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

Merged
merged 2 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func inspect(pass *analysis.Pass, node ast.Node, checkRE *regexp.Regexp, state *
if err != nil {
return true
}
if idx := strings.IndexByte(n, '/'); idx != -1 {
if idx := strings.LastIndexByte(n, '/'); idx != -1 {
n = n[idx+1:]
}
state.imports[n] = struct{}{}
Expand Down
4 changes: 4 additions & 0 deletions internal/analyzer/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func TestAnalyzer(t *testing.T) {
dir: "custompattern",
pattern: `.*`,
},
{
dir: "defaultclient",
pattern: `^(DefaultClient|DefaultTransport)$`,
},
}

wd, err := os.Getwd()
Expand Down
20 changes: 20 additions & 0 deletions testdata/defaultclient/src/a/a.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package a

import (
"io"
"net/http"

"config"
)

var DefaultClient = &http.Client{}

func reassignPattern() {
io.EOF = nil

config.DefaultClient = nil // want "reassigning variable"
DefaultClient = nil

http.DefaultClient = nil // want "reassigning variable"
http.DefaultTransport = nil // want "reassigning variable"
}
5 changes: 5 additions & 0 deletions testdata/defaultclient/src/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package config

import "net/http"

var DefaultClient = &http.Client{}
3 changes: 3 additions & 0 deletions testdata/defaults/src/a/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import cc "c"
import (
"d"
"d/e"
"d/e/f"
)

var st = struct {
Expand All @@ -26,6 +27,8 @@ func foo() {

e.ErrE = nil // want "reassigning variable"

f.ErrF = nil // want "reassigning variable"

io.EOF = nil // want "reassigning variable"

st.ErrSt = errors.New("foo")
Expand Down
7 changes: 7 additions & 0 deletions testdata/defaults/src/d/e/f/f.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package f

import "errors"

var (
ErrF = errors.New("f")
)