-
-
Notifications
You must be signed in to change notification settings - Fork 778
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: Allow numbers with non standard groupings #4280
UnderscoresInNumericLiterals: Allow numbers with non standard groupings #4280
Conversation
Codecov Report
@@ Coverage Diff @@
## main #4280 +/- ##
============================================
- Coverage 84.27% 84.24% -0.03%
- Complexity 3249 3263 +14
============================================
Files 471 472 +1
Lines 10261 10315 +54
Branches 1805 1821 +16
============================================
+ Hits 8647 8690 +43
- Misses 664 666 +2
- Partials 950 959 +9
Continue to review full report at Codecov.
|
What do you think about adding a flag |
I like that, as it keeps the default behavior the same. |
I don't love it but for backward compatibility this is most likely our best choice. |
9cc086a
to
a286526
Compare
...tyle/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnderscoresInNumericLiterals.kt
Outdated
Show resolved
Hide resolved
companion object { | ||
private val UNDERSCORE_NUMBER_REGEX = Regex("[0-9]{1,3}(_[0-9]{3})*") | ||
private val HAS_ONLY_STANDARD_GROUPING = """\d{1,3}(?:_\d{3})*""".toRegex() |
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 does the elvis operator here?
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 only marks a non-capture group. I could remove it, if it is confusing.
If you do not need the group to capture its match, you can optimize this regular expression into Set(?:Value)?. The question mark and the colon after the opening parenthesis are the syntax that creates a non-capturing group.
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 that keeping the regex as simple as possible is better (if it doesn't affects the performance). But to be honest my comment was pure curiosity.
…/rules/style/UnderscoresInNumericLiterals.kt Co-authored-by: Brais Gabín <braisgabin@gmail.com>
fixes #4276
I am somewhat unsure how to handle this. In my opinion this rule should have never reported a violation for groups other than three but changing this now will is a breaking change.