-
Notifications
You must be signed in to change notification settings - Fork 7
fix: Additional checks for prefer-flat #46
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
fix: Additional checks for prefer-flat #46
Conversation
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.
Thanks for the improvement. However I'd like to keep the code consistent in style. I also wonder if some of the conditions couldn't be enforced by the selector.
rules/prefer-flat.js
Outdated
@@ -1,3 +1,5 @@ | |||
// eslint-disable-next-line eslint-comments/disable-enable-pair | |||
/* eslint-disable no-magic-numbers */ |
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.
I'm sorry, but these rules are there for a reason.
Codecov Report
@@ Coverage Diff @@
## master #46 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 8 8
Lines 111 111
=========================================
Hits 111 111 Continue to review full report at Codecov.
|
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.
Perfect. Also, impressed by the quick turnaround time.
if(node.parent.parent.arguments.length > SECOND && node.parent.parent.arguments[SECOND].type === "ArrayExpression" && | ||
firstElement(node.arguments).name === node.parent.params[SECOND].name && | ||
node.callee.object.name === firstElement(node.parent.params).name) { | ||
'CallExpression[callee.type="MemberExpression"][callee.property.name="reduce"][arguments.length=2][arguments.1.type=ArrayExpression][arguments.1.elements.length=0] > *:function[params.length=2][params.0.type=Identifier][params.1.type=Identifier] > CallExpression[callee.type="MemberExpression"][callee.property.name="concat"][arguments.length=1][arguments.0.type=Identifier]'(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.
Oh wow, I didn't expect this much to be possible within the selector. Nice work!
prefer-flat
is failing in some cases:array.reduce((p, []) => p.concat({}), [])
array.reduce((p, n) => p.concat(n), [1])
array.reduce((p, n) => p.concat(n, n), [])