mgechev / revive

🔥 ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint
https://revive.run
MIT License
4.69k stars 269 forks source link

duplicate-imports linter broken? #983

Closed xrstf closed 2 months ago

xrstf commented 2 months ago

Describe the bug I am trying to detect that a package was imported twice in the same file, but using different aliases:

https://github.com/xrstf/prow/blob/b64d12364f91802cfefda3f6e6b79f8d181f2e5f/pkg/plank/controller_test.go#L34-L35 should in my opinion cause a linter error. But when I run revive directly or via golangci-lint, no error is reporting for the duplicate import.

To Reproduce

  1. I downloaded revive 1.3.7 from GitHub.
  2. I navigated into my Prow fork and did cd pkg/plank; revive .

Expected behavior I expected an error like k8s.io/api/core/v1 is imported multiple times in controller_test.go.. Instead I got

reconciler.go:901:28: error strings should not be capitalized or end with punctuation or a newline
controller_test.go:17:1: should have a package comment
error.go:42:1: exported function IsTerminalError should have comment or be unexported
reconciler.go:574:12: if block ends with a break statement, so drop this else and outdent its block
reconciler.go:591:12: if block ends with a break statement, so drop this else and outdent its block
reconciler_test.go:253:34: parameter 'opts' seems to be unused, consider removing or renaming it as _
reconciler_test.go:580:30: parameter 'ctx' seems to be unused, consider removing or renaming it as _
reconciler_test.go:580:51: parameter 'path' seems to be unused, consider removing or renaming it as _
reconciler_test.go:580:64: parameter 'opts' seems to be unused, consider removing or renaming it as _
reconciler_test.go:648:82: parameter 'action' seems to be unused, consider removing or renaming it as _
reconciler_test.go:659:80: parameter 'action' seems to be unused, consider removing or renaming it as _
reconciler_test.go:665:90: parameter 'action' seems to be unused, consider removing or renaming it as _
reconciler.go:181:20: parameter 'ctx' seems to be unused, consider removing or renaming it as _
reconciler.go:60:7: exported const ControllerName should have comment or be unexported
reconciler.go:97:1: exported function Add should have comment or be unexported
reconciler.go:267:6: exported type ClusterStatus should have comment or be unexported
reconciler.go:270:2: exported const ClusterStatusReachable should have comment (or a comment on this block) or be unexported
controller_test.go:309:39: parameter 'r' seems to be unused, consider removing or renaming it as _

Desktop (please complete the following information):

chavacava commented 2 months ago

Hi @xrstf thanks for reporting the issue.

Entuazism commented 2 months ago

Hi! Seems like it`s not a bug. There is just not duplicated-imports rule in default revive configuration https://github.com/mgechev/revive/blob/master/defaults.toml

For enabling this rule just add [rule.duplicated-imports] in config and run

revive -config config.toml .
xrstf commented 2 months ago

Thank you, that was indeed the issue. With the config you provided, revive prints the duplicate imports :-)