-
-
Notifications
You must be signed in to change notification settings - Fork 794
Define FunctionSignature #4176
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
Define FunctionSignature #4176
Conversation
dfda9f0
to
6db005f
Compare
6db005f
to
bde99ef
Compare
Codecov Report
@@ Coverage Diff @@
## main #4176 +/- ##
============================================
- Coverage 84.26% 84.25% -0.01%
+ Complexity 3245 3238 -7
============================================
Files 468 469 +1
Lines 10178 10199 +21
Branches 1787 1792 +5
============================================
+ Hits 8576 8593 +17
Misses 658 658
- Partials 944 948 +4
Continue to review full report at Codecov.
|
functions[5] to false, // fun compare(hello: String, world: Int) | ||
), | ||
) | ||
} |
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.
This is a matrix of cases. Given a list of MethodSignatures and a list of function declarations I want to say if it should match or no. And then check all those cases and see that it's correct.
Do you know any better way to write this and no make it a maintainance hell?
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.
What I can think of is to give each functions
element a specify name, such as ToStringNoArg
, ToStringOneArg
, ToStringTwoArgs
, CompareNoArg
, CompareOneArg
, and CompareTwoArgs
.
This does prevent magic numbers being used, but the maintenance cost is still there.
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 had that. The problem is that the readability is a bit worst:
ToStringNoArg to false, // fun toString()
ToStringOneArg to false, // fun toString(hello: String)
ToStringTwoArgs to false, // fun toString(hello: String, world: Int)
CompareNoArg to false, // fun compare()
CompareOneArg to false, // fun compare(hello: String)
CompareTwoArgs to false, // fun compare(hello: String, world: Int)
vs
functions[0] to false, // fun toString()
functions[1] to false, // fun toString(hello: String)
functions[2] to false, // fun toString(hello: String, world: Int)
functions[3] to false, // fun compare()
functions[4] to false, // fun compare(hello: String)
functions[5] to false, // fun compare(hello: String, world: Int)
The second one keeps the columns aligned so it's a bit easier to read and modify. Usually I don't care about alignment and I would vote against comments that are far too easy to get outdated but in this case I'm not that sure. Do you think the first is better?
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 like the former one. The second has the horizontal alignment but I agree with "Clean code" that it shouldn't matter - Once we have more than 10 items, we do not get columns fully aligned anymore.
Additionally, I don't think the comments become necessary in the former case.
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 like FunctionSignature
. If we want to emphasize its core functionality, we can call it FunctionMatcher
.
detekt-psi-utils/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/MethodSignature.kt
Outdated
Show resolved
Hide resolved
functions[5] to false, // fun compare(hello: String, world: Int) | ||
), | ||
) | ||
} |
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.
What I can think of is to give each functions
element a specify name, such as ToStringNoArg
, ToStringOneArg
, ToStringTwoArgs
, CompareNoArg
, CompareOneArg
, and CompareTwoArgs
.
This does prevent magic numbers being used, but the maintenance cost is still there.
detekt-tooling/src/main/kotlin/io/github/detekt/tooling/api/FunctionSignature.kt
Outdated
Show resolved
Hide resolved
detekt-tooling/src/main/kotlin/io/github/detekt/tooling/api/FunctionSignature.kt
Outdated
Show resolved
Hide resolved
f71d8a5
to
800d094
Compare
detekt-test/src/main/kotlin/io/gitlab/arturbosch/detekt/test/RuleExtensions.kt
Outdated
Show resolved
Hide resolved
800d094
to
5631bf0
Compare
This class is a helper that I need to implement #4148. I moved it outside that PR becase the code is complex and have entity by itself.
I'm not very happy with all the naming that I'm using so any suggestion there is that regard is more than welcome.