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
|
|
||
| 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.
What does the elvis operator here?
There was a problem hiding this comment.
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.
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.