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

Fix no-this-in-sfc rule behavior for arrow functions inside a class field #1989

Merged
merged 3 commits into from Sep 20, 2018

Conversation

sergei-startsev
Copy link
Contributor

Fixed #1967. Adjusted component detection in getParentStatelessComponent for arrow functions inside a class field, e.g.:

class Foo {
  bar() { 
    () => {
      this.something();
      return null;
    };
  }
}

See details in #1972.

lib/util/Components.js Show resolved Hide resolved
scope = scope.upper;
while (scope) {
const type = scope.block.type;
if (type === 'FunctionExpression' || type === 'FunctionExpression') {
Copy link
Member

Choose a reason for hiding this comment

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

Is this meant to be checking the same thing twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, it should be FunctionExpression and FunctionDeclaration

@sergei-startsev
Copy link
Contributor Author

Fixed typo and added one more more test.

@ljharb
Copy link
Member

ljharb commented Sep 19, 2018

I don't see any tests of function declarations tho (arrows are only ever expressions)

@sergei-startsev
Copy link
Contributor Author

@ljharb A parent scope of arrow function can have FunctionDeclaration type. The check is required to detect parent function scope for arrow expressions properly. I've added a test to illustrate it.

@ljharb ljharb added the bug label Sep 20, 2018
@ljharb ljharb merged commit a93080e into jsx-eslint:master Sep 20, 2018
This was referenced Dec 28, 2018
This was referenced Jan 4, 2019
@ghost ghost mentioned this pull request Jan 12, 2019
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

2 participants