numeric-separators-style: option to accept numbers without grouping
See original GitHub issueI’m a big fan of the new numeric-separators-style
rule from #833. Great idea!
I’d like to enable the numeric-separators-style
rule to catch incorrect groupings without requiring that all numbers use separators. For example:
const foo = 1234; // Pass: No separators
const bar = 1_234; // Pass: Correct grouping
const baz = 12_34; // Fail: Incorrect grouping
I couldn’t find a way to achieve this. Configuring minimum
between 0 and 4, foo
and baz
fail. With minimum
5 or above, bar
and baz
fail.
Is this an feature that you might consider? If so, how to configure?
An idea: Additional options for each number type:
Name | Description |
---|---|
requireLeft |
Require separators to the left of the decimal point for numbers with at least minimum digits to the left. (Current behavior: true ) |
requireRight |
Require separators to the right of the decimal point for numbers with at least minimum digits to the right. (Current behavior: true ) |
forbidLeft |
Forbid separators to the left of the decimal point for numbers with less than minimum digits to the left. (Current behavior: true ) |
forbidRight |
Forbid separators to the right of the decimal point for numbers with less than minimum digits to the right. (Current behavior: true ) |
The desired example behavior could then be accomplished with requireLeft: false
(to never require grouping) or something like minimum: 7, forbidLeft: false
to require grouping 7-digits or more, but allow grouping fewer.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
java - How to format numbers with no grouping separator
Show activity on this post. String result = String. valueOf(number); returns your number as a string with no formatting.
Read more >Change the character used to separate thousands or decimals
Change the character used to separate thousands or decimals · Click File > Options. · On the Advanced tab, under Editing options, clear...
Read more >JavaScript Numeric Separator Using Underscores (_)
The numeric separator allows you to create a visual separation between groups of digits by using underscores ( _ ) as separators.
Read more >Underscores in Numeric Literals
For instance, if your code contains numbers with many digits, you can use an underscore character to separate digits in groups of three,...
Read more >Decimal separator - Wikipedia
Three ways to group the number ten thousand with digit group separators. 1) Space, the internationally recommended thousands separator. 2) Period (or full...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Why not, but I think we should not add a ton of options for only one single rule, and keep the configuration clear… I’ll let the core team discuss on that 😄
Yes sorry for the confusion, I was speaking about the
minimum
option. I will edit my comment to avoid confusing other peoples 🙂Because sometimes it’s desirable to catch incorrect/misleading grouping, but not to force minor style details everywhere? Regardless of the rationale, this rule already has the
minimumDigits
configuration option to support it. Part of the problem is thatminimumDigits: 4
would makeconst foo = 1_234;
invalid.P.S. @noftaly I had
minimum
andminimumDigits
confused. You had the right name all along. My bad.