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
Added StringLiteralDuplication rule #300
Conversation
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.
Should we also add a regex property to have the possibility to ignore this check on all test files.
increment() | ||
} | ||
|
||
private fun increment() { |
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.
Why not inline this function?
} | ||
} | ||
|
||
private const val DEFAULT_DUPLICATION = 2 |
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 find 2 quite low as a default.
@vanniktech thanks for giving feedback The default value is of course discussable.
I am waiting for feedback. I am also willing to fix the following duplicates after giving feedback.
|
How about passing a list of values that should be ignored and by default default to . and , |
An ignore list sounds good to me. |
@@ -25,6 +26,7 @@ class ComplexityProvider : RuleSetProvider { | |||
LongMethod(config), | |||
LargeClass(config), | |||
ComplexMethod(config), | |||
ConsiderConstantString(config), |
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.
Sorry my bad. ConsiderStringConstant is a better name.
Why ComplexityProvider? I think style suits it 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 disagree. It is basically code duplication. I think multiple occurrences of hard coded strings are making maintenance more difficult and thus the kt file more complex.
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.
Hmm now I'm thinking about that the name StringLiteralDuplication was good though :/ and the description should suggest using a constant.
I like the configuration options! I will wait some more days so we can figure out the threshold value. 2 seems to be too low, but also reasonable ... |
i think some of the |
@arturbosch maybe it's an outdated version now? I'll check it. |
I also did some research concerning this rule. SonarJava also this rule. They have a threshold of 3. However, this threshold comparing it to detekts means setting the threshold for this rule to 2. Furthermore, SonarJava also doesn't detect strings with less than 5 characters. reference: What do you think? @arturbosch @vanniktech @Mauin |
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 think PMD has a default threshold of 5. I still think that 2 is a bit low. Probably we should settle for something between 3 and 5.
I think we should follow the sonarqube way and exclude strings with size < 5 and have a threshold of 3 (2 in detekt). Seems like that sonar uses value >= threshold. Detekt (well I introduced it) uses value > threshold. So 2 seems low, effectlively it is 3. I will open a issue to discuss the which threshold definition we should use. Edit: I think it is now ok to merge this and change the threshold if needed in #313. Sorry for that but @schalkms can you change the name of the rule back to StringLiteralDuplication :/ ? Thanks! Edit2: Oh the option for strings smaller than 5 would be nice! |
* Renamed rule * Excluded strings with less than 5 characters
👍 |
No description provided.