question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

numeric-separators-style: option to accept numbers without grouping

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
noftalycommented, Oct 17, 2020

I could imagine use cases/style guides which require grouping for numbers that exceed a certain size, so tried to cover that in my proposal.

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 😄

Were you referring to the existing minimum configuration option or proposing a new minimumDigits option to address this issue? Could you clarify how minimumDigits would interact with minimum?

Yes sorry for the confusion, I was speaking about the minimum option. I will edit my comment to avoid confusing other peoples 🙂

0reactions
kevinoidcommented, Oct 18, 2020

To be honest, I don’t see why you want const foo = 1234; pass? That’s the point of this rule.

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 that minimumDigits: 4 would make const foo = 1_234; invalid.

P.S. @noftaly I had minimum and minimumDigits confused. You had the right name all along. My bad.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found