Skip to content
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

Add list of exception patterns to Style/NumericLiterals #10857

Closed
dmke opened this issue Aug 3, 2022 · 0 comments · Fixed by #10873
Closed

Add list of exception patterns to Style/NumericLiterals #10857

dmke opened this issue Aug 3, 2022 · 0 comments · Fixed by #10873
Assignees

Comments

@dmke
Copy link

dmke commented Aug 3, 2022

Is your feature request related to a problem? Please describe.

In a current project, I need to handle identification numbers, which follow the format <2 digit classification> <2 digit region id> <4 digit running number> <1 digit checksum> ("Institutionskennzeichen", "IK number"), for example 112233334

Describe the solution you'd like

I'd like to format them in code as 11_22_3333_4, but the Style/NumericLiterals cop wants me to format them as 112_233_334, which is nonsensical.

I also don't want to lose the warnings for ordinary numbers, where grouping the digits in triplets is desirable.

Describe alternatives you've considered

  • Strict: false (default) takes offense with 11_22_3333_4
  • AllowedNumbers: [...] does not scale
  • Enabled: false is my current workaround

Additional context

It would be nice to define (a list of) allowed patterns, for example:

Style/NumericLiterals:
  AllowedPatterns:     # list of exceptions, like AllowedNumbers
  - xx_xx_xxxx_x       # either using placeholders
  - \d\d_\d\d_\d{4}_\d # or using regexp

I'm not sure if there's precedent for either placeholders or regular expressions in other cops. Maybe there are better alternatives to declare such exceptions.

@dvandersluis dvandersluis self-assigned this Aug 5, 2022
dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Aug 6, 2022
koic added a commit that referenced this issue Aug 6, 2022
…lowed-patterns

[Fix #10857] Add `AllowedPatterns` to `Style/NumericLiterals`.
WJWH pushed a commit to WJWH/rubocop that referenced this issue Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants