Skip to content
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

Configure linter for unused methods #292

Closed
ahmetb opened this issue Jul 22, 2019 · 9 comments
Closed

Configure linter for unused methods #292

ahmetb opened this issue Jul 22, 2019 · 9 comments
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. priority/P3 P3 issues or PRs

Comments

@ahmetb
Copy link
Member

ahmetb commented Jul 22, 2019

Every now and then, we do major refactoring that leaves unused methods behind.

It would be great to have a linter that can notify us about unused methods,
variables, constants. I suspect this is probably easier to configure with "unexported" methods,
variables etc. However, if there's a way to do this with "exported" methods,
variables etc, we should do it because now anything in this repository (sigs.k8s.io/krew/...)
is expected to be used in this repository. So if something is not referenced,
ideally it should be cleaned up.

/label good-first-issue
/priority P3
/kind cleanup

@k8s-ci-robot k8s-ci-robot added priority/P3 P3 issues or PRs kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Jul 22, 2019
@corneliusweig
Copy link
Contributor

Hmm.. I just tried configuring the unused linter for golangci-lint with

diff --git a/.golangci.yml b/.golangci.yml
index ff0bbe9..3a53d8c 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -5,6 +5,9 @@ linters-settings:
     # it's a comma-separated list of prefixes
     local-prefixes: sigs.k8s.io/krew
 
+  unused:
+    check-exported: false
+
 # options for analysis running
 run:
   # which dirs to skip: they won't be analyzed;

That setting reports a lot of false positives, which makes it impossible to use in the CI. Btw, the unused linter is active by default. However, it does not consider functions as unused, if they are used in tests. So if all tests are deleted, the unused function from #290 is correctly reported. So it seems that our current meta-linter cannot handle this as desired.

@ahmetb
Copy link
Member Author

ahmetb commented Jul 22, 2019

So if all tests are deleted,

haha that's a bummer. :D They should totally have a flag to ignore usage in tests.

@ahmetb ahmetb added good-first-issue good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. and removed good-first-issue labels Jul 22, 2019
@ferhatelmas
Copy link
Contributor

For a quick win, how about enabling deadcode and varcheck with tests flag?

@ahmetb
Copy link
Member Author

ahmetb commented Aug 26, 2019

Please try out. I'm not sure if/how much it helps.

ferhatelmas added a commit to ferhatelmas/krew that referenced this issue Aug 26, 2019
@ferhatelmas
Copy link
Contributor

Not very useful at the moment but there might be beneficial cases.

k8s-ci-robot pushed a commit that referenced this issue Aug 26, 2019
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 24, 2019
@ahmetb
Copy link
Member Author

ahmetb commented Nov 24, 2019

/close

@k8s-ci-robot
Copy link
Contributor

@ahmetb: Closing this issue.

In response to this:

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ferhatelmas
Copy link
Contributor

#291 would be useful because packages under internal can only be used in the same repo. Otherwise, they are exported, linter won't complain to prevent false positive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. priority/P3 P3 issues or PRs
Projects
None yet
Development

No branches or pull requests

5 participants