-
-
Notifications
You must be signed in to change notification settings - Fork 767
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
Rule: UnusedPrivateMember #641
Rule: UnusedPrivateMember #641
Conversation
} | ||
} | ||
|
||
class Test { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hanging fruit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, was testing with this one 🙃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate this changes. However, this rule needs a symbol table to function correctly for all cases.
Cool, this is a useful rule! Do you want to support parameters too? Unused private functions you can also find with the same reference counting. I have implemented a UnusedPrivateMembers rule for java. Here is the test code:
Also you should check the refences in all possible conditional statements:
|
8c46ed9
to
60c414e
Compare
60c414e
to
30c0c00
Compare
it("reports an unused member") { | ||
val code = """ | ||
class Test { | ||
private val unused = "This is not used" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation seems to be off. This seems to be using spaces over tabs.
super.visitNamedFunction(function) | ||
|
||
function.valueParameterList?.parameters?.forEach { | ||
val name = it.name ?: throw IllegalStateException("Value parameter should have a name.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't you do just !!
? That will throw for you. If the intention is to have a custom message, then I think the exception type should better to be NullPointerException
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any cases where a parameter has no name?
I think it is just for anonymous objects that it can be null.
How about using safeName
or nameAsSafeName
(dont remember how it is called)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about nameAsSafeName
. Will change it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please provide some test cases with local methods and loops. Thanks :)
Cool great so far!
Great idea @arturbosch I added some extra handling to catch unused loop parameters. |
Resolves #8
This should cover unused private properties. Public properties are ignored as they might be used from other files.