-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Update: optionally allow bitwise operators (fixes #4742) #4786
Conversation
* @param {ASTNode} node The node to check. | ||
* @returns {boolean} Whether or not the node has a bitwise operator. | ||
*/ | ||
function allowedOperator(node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about isOperatorAllowed
as the name of the function? Then pass in the operator as the argument to his function. Its more readable IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decided to stick with the method signature already present in this rule, but if you feel strong about it I don't mind changing.
Please update:
|
@btmills In the above case, option schema was not updated with the new option. I thought the unit test would fail in this case as the schema is not correct. Am i missing something here? |
Good catch, @gyandeeps - that's a bug. I'll open an issue once I've diagnosed it further. It shouldn't block this PR - we just need to make sure the schema gets updated before we merge. As long as it's not |
Good catch totally forgot about the docs, will add |
958cc4b
to
10d239f
Compare
Not sure about the schema, is there any task/command I can trigger to test if the schema's get updated or not? |
It should be something like this. As long as the schema isn't module.exports.schema = [
{
"type": "object",
"properties": {
"allow": {
"type": "array",
"items": {
"enum": ["^", "|", "&", "<<", ">>", ">>>", "^=", "|=", "&=", "<<=", ">>=", ">>>=", "~"]
},
"uniqueItems": true
}
},
"additionalProperties": false
}
] |
10d239f
to
ee2ac8f
Compare
Added the schema, tests all run fine. |
For anyone reading this PR and not paying attention to the original issue, please hold off on merging until my concerns there are addressed. I think this is entirely the wrong approach. |
ee2ac8f
to
7c42c2e
Compare
7c42c2e
to
4931f56
Compare
+1 on this. This is one of the major "gotchas" that block many folks from switching from JSHint to ESLint. In JSHint the @michaelficarra after reading through #4742 it is clear that you disagree with this approach. That is noted. If you have an alternative approach you would like to suggest a PR speaks much more strongly than comments. @nzakas @gyandeeps are we good here? I'd love to see this land. It's one of the last gotchas for more widespread ESLint adoption at GoDaddy because we switched from JSHint. |
Yeah, I think this is good to go. There haven't been any other proposals and I still feel this is a good solution. |
Update: optionally allow bitwise operators (fixes #4742)
Thanks @nzakas. Happy New Year! 💯 |
Thanks for merging this :) |
Mostly useful for allowing the NOT operator for code like ~[1, 2, 3].indexOf(1), which is something where using bitwise operators makes sense. I know there are no docs attached, but mainly was wondering if these kinds of features get accepted.
Usage would be along the line of
no-bitwise: [2, { allow: [ '~' ] }]
edit: clean new PR from #4738
edit: related to #4742