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

Implements #643 - MagicNumber ignores default values in ctor properties #644

Merged
merged 3 commits into from
Jan 1, 2018
Merged

Conversation

schalkms
Copy link
Member

@schalkms schalkms commented Dec 25, 2017

Implements #643

@@ -142,6 +146,11 @@ class MagicNumber(config: Config = Config.empty) : Rule(config) {
private fun KtConstantExpression.isPartOfFunctionReturnConstant() =
parent is KtNamedFunction || (parent is KtReturnExpression && parent.parent.children.size == 1)

private fun KtConstantExpression.isPartOfConstructor(): Boolean {
val isInConstructor = parent.parent.parent is KtPrimaryConstructor || parent.parent.parent is KtSecondaryConstructor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extract parent.parent.parent and give it a name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any suggestions?
great-grandparent does not improve the readability much I think.

@@ -142,6 +146,11 @@ class MagicNumber(config: Config = Config.empty) : Rule(config) {
private fun KtConstantExpression.isPartOfFunctionReturnConstant() =
parent is KtNamedFunction || (parent is KtReturnExpression && parent.parent.children.size == 1)

private fun KtConstantExpression.isPartOfConstructor(): Boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isPartOfConstructor sounds like this would also ignore instances where the constructor is called with a magic number: SomeClass(10) which is not the case, I guess.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. I’ll have a look later on today. Shouldn’t detekt already have such a test case?

@arturbosch arturbosch merged commit ea83a08 into detekt:master Jan 1, 2018
@arturbosch arturbosch added this to the RC6-1 milestone Jan 1, 2018
@schalkms schalkms deleted the #643 branch January 2, 2018 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants