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

numeric-separators-style: Add onlyIfContainsSeparator option #916

Merged
merged 17 commits into from Jan 19, 2021
Merged

numeric-separators-style: Add onlyIfContainsSeparator option #916

merged 17 commits into from Jan 19, 2021

Conversation

noftaly
Copy link
Contributor

@noftaly noftaly commented Dec 5, 2020

Added an option for each literal type, named checkOnlyIfSeparator.
As explained in the docs, it:
Check if the group sizes are valid only if there are groups, separated with an _.

Example:

const foo = 100000; // Pass, because there are no groups, so no check was performed.
const bar = 1_000_000; // Pass, because the group sizes are correct.
const baz = 10_0_000_0; // Fail, because there are groups, but they are incorrect.

This option is disabled by default.

Closes #868

@fisker
Copy link
Collaborator

fisker commented Dec 5, 2020

I'm not sure if we should add this option, but you didn't test 12_34.5678e1234.5678, should we ignore all, or just part?

@noftaly
Copy link
Contributor Author

noftaly commented Dec 5, 2020

Considering it has a separator, I think the entire number should be checked, to be more consistent. Do you want me to add a test for more "complicated" numbers? I did not do any because the option short-circuits the whole check so it will never get to the decimal and exponential part.

I'm not sure if we should add this option

No problem, I did not know if I should wait for a "help-wanted" label, so I just did it anyway 😄 Don't hesitate to close the PR if you don't think it should be added.

@sindresorhus
Copy link
Owner

sindresorhus commented Jan 11, 2021

While I wouldn't personally use this option, I can see how it would be useful if you want to enforce "correctness", but not style. We could use it in, for example, the unopinionated preset (#896).

docs/rules/numeric-separators-style.md Outdated Show resolved Hide resolved
docs/rules/numeric-separators-style.md Show resolved Hide resolved
@sindresorhus
Copy link
Owner

Considering it has a separator, I think the entire number should be checked, to be more consistent.

👍

noftaly and others added 2 commits January 11, 2021 13:14
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
@sindresorhus
Copy link
Owner

@fisker Are you ok with merging this?

@fisker
Copy link
Collaborator

fisker commented Jan 18, 2021

Yes, I'm fine with this, but I think the option can have a better name, like onlyIfSeparatorExists or onlyIfSeparatorPresents?

And do we want a top level one to easier set for all?

Also, need more tests on different options, and seperator in different position of 1234.5678e1234

@sindresorhus
Copy link
Owner

onlyIfSeparatorExists

👍

@sindresorhus
Copy link
Owner

Alternatively: onlyIfContainsSeparator

@sindresorhus
Copy link
Owner

And do we want a top level one to easier set for all?

👍

@noftaly
Copy link
Contributor Author

noftaly commented Jan 18, 2021

And do we want a top level one to easier set for all?

Just to be sure, do you want only one at the top level, or one for each types and a "master" setting at the top level that overrides other settings if set?

@fisker
Copy link
Collaborator

fisker commented Jan 18, 2021

Both, if top one is set, all default to it.

@noftaly
Copy link
Contributor Author

noftaly commented Jan 18, 2021

Both, if top one is set, all default to it.

Doesn't it add too many complexity and redundancy? I thought of doing that too but I think it might confuse the user and clutter the options...

@fisker
Copy link
Collaborator

fisker commented Jan 18, 2021

{
  onlyIfContainsSeparator: false, // default, can  be  omitted
  binary: {
    onlyIfContainsSeparator: true
  }
}
{
  onlyIfContainsSeparator: true,
  binary: {
    onlyIfContainsSeparator: false
  }
}

Pretty clear to me, think this way you can set onlyIfContainsSeparator at top level, but can be override on each.

@noftaly
Copy link
Contributor Author

noftaly commented Jan 18, 2021

Okay, I'll do that then 👍🏼

@noftaly
Copy link
Contributor Author

noftaly commented Jan 18, 2021

Just curious about the actions, why do the lint errors appear in the build job and not in the lint job? (cf my last failing commit)

@fisker
Copy link
Collaborator

fisker commented Jan 18, 2021

lint is not really lint, maybe we need rename it, it's run rules on codebase, 😄

@fisker fisker self-assigned this Jan 19, 2021
@fisker
Copy link
Collaborator

fisker commented Jan 19, 2021

I changed the logic a little bit, ebf5aee, I think this is more reasonable.

@fisker fisker mentioned this pull request Jan 19, 2021
@sindresorhus sindresorhus merged commit 8d32574 into sindresorhus:master Jan 19, 2021
@fisker fisker changed the title numeric-separators-style: Add checkOnlyIfSeparator option numeric-separators-style: Add onlyIfContainsSeparator option Jan 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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