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

Accidental bypass for react/jsx-no-bind allowArrowFunctions #1395

Closed
trevtrich opened this issue Aug 23, 2017 · 2 comments · Fixed by #1459
Closed

Accidental bypass for react/jsx-no-bind allowArrowFunctions #1395

trevtrich opened this issue Aug 23, 2017 · 2 comments · Fixed by #1459

Comments

@trevtrich
Copy link

We've recently started to get rid of our usage of arrow functions in component props for similar reasons to that mentioned here. We went ahead and set:

'react/jsx-no-bind': ['error', {
      allowArrowFunctions: false,
      allowBind: false,
}]

but realized we were still able to get away with using something like:

const someFunc = () => onClickHandler(userId)
<SomeComponent onClick={someFunc} />

So we didn't fix the problem, we just accidentally tricked it. Is this expected behavior or is this a bug?

@ljharb
Copy link
Member

ljharb commented Aug 23, 2017

It's not realistic for a rule to always be exhaustive; there's often a way to trick them.

However, it seems reasonable that an arrow function in the same scope should be warned on.

@trevtrich
Copy link
Author

Agreed. The primary concern was that for someone not familiar with the implications of anonymous functions in props, they might think the rules is just stylistic. I think checking current scope would reject the 99% case of extracting to a variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants