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

no-array-for-each: Ignore React.Children.forEach #1088

Merged
merged 13 commits into from Feb 6, 2021

Conversation

fisker
Copy link
Collaborator

@fisker fisker commented Jan 30, 2021

Fixes #1087

@sindresorhus
Copy link
Owner

I think this rule should share code with

const ignoredCallee = [
'Promise',
'React.children',
'Children',
'lodash',
'underscore',
'_',
'Async',
'async'
];

@fisker
Copy link
Collaborator Author

fisker commented Jan 30, 2021

I wrote a new function and applied to no-array-callback-reference too, the logic changed a little bit, old one ignores AnyThing.Children, I don't think it mean to do that. New logic is stricter.

const ignoredObjects = [
'React.Children',
'Children'
];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking we could have a shared utility method that is like isNotNativeArrayMethod. In case there are other false-positives in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, like the not-dom-node.js, but I was hoping get some help from eslint-utils, anyway I'll keep this in mind, maybe try in another PR.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That package isn't very actively maintained. I suggest we just do the utilities here for now and we can move them there later on if it becomes maintained again. Alternatively, you could fork eslint-utils for now.

return true;
}

function isNodeMatches(node, descriptions) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a short doc comment on what descriptions is.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keyPath is a commonly used term for foo.bar descriptions of a method chain.

'foo.notForEach(element => bar())',
// #1087
'React.Children.forEach(children, (child) => {});',
'React.Children.forEach(children, (child) => {});'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'React.Children.forEach(children, (child) => {});'
'Children.forEach(children, (child) => {});'

@@ -70,7 +71,7 @@ const iteratorMethods = [

const ignoredCallee = [
'Promise',
'React.children',
'React.Children',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this mean to be React.Children.

@fisker
Copy link
Collaborator Author

fisker commented Jan 30, 2021

My 11 month daughter is coding for me... I'll fix after she sleep.

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.

False positive on no-array-for-each
2 participants