-
-
Notifications
You must be signed in to change notification settings - Fork 783
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
UnderscoresInNumericLiterals acceptableDecimalLength is off by one #3972
Conversation
I think we should care and not introduce a breaking change like that. I agree that the fallback config property is missing some functionality. I was looking into it and ended up with something like @Configuration("Length under which decimal base 10 literals are not required to have underscores")
@Deprecated("Use `acceptableLength` instead. Make sure to read the documentation as the logic has changed.")
private val acceptableDecimalLength: Int by config(5)
@Configuration("Maximum number of digits that a number can have and not use underscores")
private val acceptableLength: Int by configWithFallback(::acceptableDecimalLength, 4) I know that @chao2zhang was asking about something like this from the beginning but at the time I could not get this to work. In the implementation of the config property I get the message: |
That api doesn't allow me to convert from one value to the other, I mean, do the - 1 |
🤔 You could do |
Good point! That have sense. |
private val acceptableDecimalLength: Int by config(DEFAULT_ACCEPTABLE_DECIMAL_LENGTH) | ||
@Configuration("Length under which base 10 numbers are not required to have underscores") | ||
@Deprecated("Use acceptableLength instead.") | ||
private val acceptableDecimalLength: Int by config(5) { it - 1 } |
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.
With the current implementation of the configWithFallback
this will not work. This relies on #3982 in order to work.
It have multiple meanings: base 10 decimal point first digit after the "decimal point" ... https://en.wikipedia.org/wiki/Decimal_(disambiguation)
c812cd8
to
1f5ab4a
Compare
Rebased and now it uses the new version of |
Codecov Report
@@ Coverage Diff @@
## main #3972 +/- ##
=========================================
Coverage 83.48% 83.48%
Complexity 3195 3195
=========================================
Files 461 461
Lines 9112 9113 +1
Branches 1774 1774
=========================================
+ Hits 7607 7608 +1
Misses 571 571
Partials 934 934
Continue to review full report at Codecov.
|
Please regenerate the default config to use the the property name. Should we also update the test to use the new config property and keep only one or two with the deprecated value? |
1f5ab4a
to
699f54e
Compare
And not only the default config. The deprecation list too! We merged the PR just in time 😂.
You are right! Done :) |
699f54e
to
c392001
Compare
.../src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnderscoresInNumericLiteralsSpec.kt
Outdated
Show resolved
Hide resolved
.../src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnderscoresInNumericLiteralsSpec.kt
Outdated
Show resolved
Hide resolved
.../src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnderscoresInNumericLiteralsSpec.kt
Outdated
Show resolved
Hide resolved
.../src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnderscoresInNumericLiteralsSpec.kt
Outdated
Show resolved
Hide resolved
c392001
to
27117e6
Compare
This rule was using the word "decimal" everywhere. It's correct to call a base 10 number "decimal" but it is saying the same thing twice. And the problem with "decimal" is that it have a lot of meanings so it can be missleading. For that reason I changed the documentation a bit removing the word "decimal" (first commit).
After that the only point where "decimal" was used is in the configuration so to avoid the breaking change and because it also improves "readability" I renamed "acceptableDecimalLength" to "acceptableLenght". All this rule is about base 10 numbers so there's is no need to point that out in the configuration too.
But this is a Draft an it's not a ready to merge PR because I found a missing feature in our new configuration system:
We can't use the value of
acceptableDecimalLength
as the value ofacceptableLenght
because it would be off by one. Should we care about this? We were talking about adding a "breaking change" to fix this so, maybe, we should not care.Fix #3860