When I run the linter locally I see following errors:
$ make lint
golangci-lint run --enable-all --disable=godox --max-same-issues=0 --max-issues-per-linter=0 --build-tags aws,packet,e2e,disruptive-e2e,prometheus --new-from-rev=$(git merge-base $(cat .git/resource/base_sha 2>/dev/null || echo "master") HEAD) --modules-download-mode=vendor --timeout=5m ./...
WARN [runner] Can't run linter goanalysis_metalinter: ST1008: failed prerequisites: [email protected]/kinvolk/lokomotive/pkg/backend
WARN [runner] Can't run linter unused: buildssa: analysis skipped: errors in package: [/home/surajd/work/lokomotive/pkg/backend/backend.go:18:2: could not import fmt (/usr/local/go/src/fmt/errors.go:7:8: could not import errors (/usr/local/go/src/errors/wrap.go:8:2: could not import internal/reflectlite (/usr/local/go/src/internal/reflectlite/value.go:8:2: could not import runtime (/usr/local/go/src/runtime/alg.go:8:2: could not import internal/cpu (-: could not load export data: cannot import "internal/cpu" (unknown iexport format version 1), export data is newer version - update tool))))) /home/surajd/work/lokomotive/pkg/backend/backend.go:20:2: could not import github.com/hashicorp/hcl/v2 (/home/surajd/work/lokomotive/vendor/github.com/hashicorp/hcl/v2/diagnostic.go:4:2: could not import fmt (/usr/local/go/src/fmt/errors.go:7:8: could not import errors (/usr/local/go/src/errors/wrap.go:8:2: could not import internal/reflectlite (/usr/local/go/src/internal/reflectlite/value.go:8:2: could not import runtime (/usr/local/go/src/runtime/alg.go:8:2: could not import internal/cpu (-: could not load export data: cannot import "internal/cpu" (unknown iexport format version 1), export data is newer version - update tool)))))) /home/surajd/work/lokomotive/pkg/backend/backend.go:26:14: undeclared name: hcl /home/surajd/work/lokomotive/pkg/backend/backend.go:26:25: undeclared name: hcl /home/surajd/work/lokomotive/pkg/backend/backend.go:26:42: undeclared name: hcl /home/surajd/work/lokomotive/pkg/backend/backend.go:20:2: "github.com/hashicorp/hcl/v2" imported but not used]
ERRO Running error: buildssa: analysis skipped: errors in package: [/home/surajd/work/lokomotive/pkg/backend/backend.go:18:2: could not import fmt (/usr/local/go/src/fmt/errors.go:7:8: could not import errors (/usr/local/go/src/errors/wrap.go:8:2: could not import internal/reflectlite (/usr/local/go/src/internal/reflectlite/value.go:8:2: could not import runtime (/usr/local/go/src/runtime/alg.go:8:2: could not import internal/cpu (-: could not load export data: cannot import "internal/cpu" (unknown iexport format version 1), export data is newer version - update tool))))) /home/surajd/work/lokomotive/pkg/backend/backend.go:20:2: could not import github.com/hashicorp/hcl/v2 (/home/surajd/work/lokomotive/vendor/github.com/hashicorp/hcl/v2/diagnostic.go:4:2: could not import fmt (/usr/local/go/src/fmt/errors.go:7:8: could not import errors (/usr/local/go/src/errors/wrap.go:8:2: could not import internal/reflectlite (/usr/local/go/src/internal/reflectlite/value.go:8:2: could not import runtime (/usr/local/go/src/runtime/alg.go:8:2: could not import internal/cpu (-: could not load export data: cannot import "internal/cpu" (unknown iexport format version 1), export data is newer version - update tool)))))) /home/surajd/work/lokomotive/pkg/backend/backend.go:26:14: undeclared name: hcl /home/surajd/work/lokomotive/pkg/backend/backend.go:26:25: undeclared name: hcl /home/surajd/work/lokomotive/pkg/backend/backend.go:26:42: undeclared name: hcl /home/surajd/work/lokomotive/pkg/backend/backend.go:20:2: "github.com/hashicorp/hcl/v2" imported but not used]
make: *** [Makefile:50: lint] Error 3
but when the same is run in the CI I can see following output:
Running linter (if available)
golangci-lint run --enable-all --disable=godox --max-same-issues=0 --max-issues-per-linter=0 --build-tags aws,packet,e2e,disruptive-e2e,prometheus --new-from-rev=$(git merge-base $(cat .git/resource/base_sha 2>/dev/null || echo "master") HEAD) --modules-download-mode=vendor --timeout=5m ./...
test/monitoring/control-plane_test.go:86:26: Using the variable on range scope `tc` in function literal (scopelint)
t.Logf("querying %q", tc.query)
^
test/monitoring/control-plane_test.go:92:47: Using the variable on range scope `tc` in function literal (scopelint)
results, warnings, err := v1api.Query(ctx, tc.query, time.Now())
^
test/monitoring/control-plane_test.go:100:82: Using the variable on range scope `tc` in function literal (scopelint)
t.Logf("found %d results for %s", len(strings.Split(results.String(), "\n")), tc.query)
^
test/monitoring/control-plane_test.go:33: Function 'TestPrometheusMetrics' is too long (69 > 60) (funlen)
func TestPrometheusMetrics(t *testing.T) {
test/components/util/util.go:251:2: assignments should only be cuddled with other assignments (wsl)
p.portForwarder = forwarder
^
test/components/util/util.go:257:3: expressions should not be cuddled with blocks (wsl)
t.Logf("output of port forwarder:\n%s\n", out.String())
^
The CI output seems correct. On what code you run the linter @surajssd ?
EDIT: also, what version of linter do you run? golangci-lint --version?
$ golangci-lint --version
golangci-lint has version 1.23.3 built from 2241adf on 2020-02-04T05:01:09Z
and for the code I was trying to run the command was my PR ~#75~ #38
@surajssd can you try updating to latest release https://github.com/golangci/golangci-lint/releases/tag/v1.23.8 ?
Now I don't see any errors.
But does the linter propery reports code issue then?
But does the linter propery reports code issue then?
No
Maybe you hit https://github.com/golangci/golangci-lint/issues/948 ?
@surajssd is your master branch up to date when you run the linter?
@surajssd is your master branch up to date when you run the linter?
Yes
Again this issue hit me, I didn't get any error locally on the commit: b38987570026d13f408fa689dad30bc036ae5434 in PR #120
$ make lint
...
testing: warning: no tests to run
PASS
coverage: [no statements]
ok github.com/kinvolk/lokomotive/test/components/rook (cached) coverage: [no statements] [no tests to run]
? github.com/kinvolk/lokomotive/test/components/util [no test files]
testing: warning: no tests to run
PASS
coverage: [no statements]
ok github.com/kinvolk/lokomotive/test/monitoring (cached) coverage: [no statements] [no tests to run]
golangci-lint run --enable-all --disable=godox,gochecknoglobals --max-same-issues=0 --max-issues-per-linter=0 --build-tags aws,packet,e2e,disruptive-e2e,poste2e --new-from-rev=$(git merge-base $(cat .git/resource/base_sha 2>/dev/null || echo "master") HEAD) --modules-download-mode=vendor --timeout=5m --exclude-use-default=false ./...
WARN [runner/goanalysis_metalinter/goanalysis] Failed to get persisted facts: failed to get data from low-level cache by key fact_deprecated/facts for package errors: read 0/175 bytes from /home/hummer/.cache/golangci-lint/71/714aa2daba719432a6313d3d3c2dcf438aae41872664fc78497b378fd5504670-a with error EOF
So this works fine on the CI(as in it enumerates all the errors) but again fails locally.
I also have the latest golangci-lint installed:
$ golangci-lint version
golangci-lint has version 1.24.0 built from 6fd4383 on 2020-03-15T11:38:02Z
Can you run git config --get diff.noprefix in lokomotive repository? It must be false to ensure --new-from-rev flag works as expected.
git config --get diff.noprefix was true and setting it to false worked. :grimacing:
Closing this then!