-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Rule proposal: no-implicit-coercion using a negative/minus (-
) symbol
#7076
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
Comments
This is a really interesting idea. But this does seem like a niche, but useful check to have to ensure safety. |
It might be worthwhile for the documentation for this rule to show how to configure no-restricted-syntax to ban |
I've created an ESLint plugin with this rule: https://www.npmjs.com/package/eslint-plugin-unary-minus |
Thank you @samestep, looks good! Any reason not to submit it as a PR to the main repo? |
Thanks @tylerlaprade! The only reason was this conversation I had on Discord with @Zamiell yesterday:
Should I submit a PR with this now? How can I do that? |
Yeah there is no need to publish a separate package for a rule! Doing that involves a lot of extra boilerplate and effort - we don't recommend doing that unless you've got an idea for a rule that we haven't marked as accepted. Even if you want to try the rule locally on your project before submitting a PR we suggest local linking for that to save you time! To submit your rule for us you'll just need to fork and clone the repo and then add your code to our plugin, then raise a PR. The pain here will be in adjusting your code and tests to adhere to our code style but should otherwise be straight-forward. |
8AF6
Oh! Sorry about that, I guess I just misunderstood @Zamiell's message on Discord. |
Before You File a Proposal Please Confirm You Have Done The Following...
My proposal is suitable for this project
Description
ESLint's no-implicit-coercion rule can't check for casting a string to a number by using
-
because it would disallow negating a regular number. By using type information, we can provide additional coercion checks.Fail Cases
Pass Cases
Additional Info
No response
The text was updated successfully, but these errors were encountered: