Skip to content

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

Conversation

doniyor2109
Copy link
Contributor

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), [])

@doniyor2109 doniyor2109 changed the title fix: Additional checks prefer-flat fix: Additional checks for prefer-flat Feb 25, 2020
Copy link
Owner

@freaktechnik freaktechnik left a 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.

@@ -1,3 +1,5 @@
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable no-magic-numbers */
Copy link
Owner

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
Copy link

codecov bot commented Feb 26, 2020

Codecov Report

Merging #46 into master will not change coverage by %.
The diff coverage is n/a.

Impacted file tree graph

@@            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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2133139...d55aab3. Read the comment docs.

Copy link
Owner

@freaktechnik freaktechnik left a 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) {
Copy link
Owner

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!

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.

2 participants