Skip to content

More robust no typos fix #1375

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

Merged
merged 6 commits into from
Aug 21, 2017

Conversation

jseminck
Copy link
Contributor

Second attempt at fixing #1353

I think this is a better approach, but it means that currently one case is not supported. See the added test:

      MyComponent.PROPTYPES = {}
      /** @extends React.Component */
      class MyComponent extends BaseComponent {}

I suppose that is acceptable for now, at least it is better than having the rule crash.

Also explained why the try/catch is needed and linked to relevant eslint-scope issue that needs to be implemented before it can be removed.

const comment = sourceCode.getJSDocComment(node);
let comment;
// Sometimes the passed node may not have been parsed yet by eslint, and this function call crashes.
// Can be removed when eslint sets "parent" property for all nodes on initial AST traversal: https://github.com/eslint/eslint-scope/issues/27
Copy link
Member

Choose a reason for hiding this comment

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

What about changing the places calling this method to be ":exit"?

Copy link
Contributor Author

@jseminck jseminck Aug 16, 2017

Choose a reason for hiding this comment

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

It does not help. The relatedComponent (in the case below it is class MyComponent) is not a child in the AST of the MemberExpression "MyComponent.PROPTYPES" - so using :exit does not work.

The reason is just that class MyComponent is declared after MyComponent.PROPTYPES and therefore eslint has not yet visited it, and therefore it does not have the parent property yet (which getJSDocComment() expects to exist).

      MyComponent.PROPTYPES = {}
      /** @extends React.Component */
      class MyComponent extends BaseComponent {}

They have a task to add parent property to all nodes on initial traversal, that would fix our issue.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Could you add a link to that parent task in your comment, with a TODO or FIXME?

@@ -218,7 +218,7 @@ function componentRule(rule, context) {
let comment;
// Sometimes the passed node may not have been parsed yet by eslint, and this function call crashes.
// Can be removed when eslint sets "parent" property for all nodes on initial AST traversal: https://github.com/eslint/eslint-scope/issues/27
// FIXME: Remove try/catch when https://github.com/eslint/eslint-scope/issues/27 is implemented.
Copy link
Member

Choose a reason for hiding this comment

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

i think we should override the linting rule rather than avoid using "FIXME"

@jseminck
Copy link
Contributor Author

Also wrote a comment explaining the issue to the eslint core team: eslint/eslint#9101 (comment)

@jseminck
Copy link
Contributor Author

jseminck commented Aug 18, 2017

One of the eslint maintainers gave some good ideas on how to get it working properly. I'll have to re-write the rule a bit: eslint/eslint#9101 (comment) (or someone else can give it a go if they want to)

@yannickcr yannickcr merged commit 686ab89 into jsx-eslint:master Aug 21, 2017
@jseminck
Copy link
Contributor Author

With ESLint 4.7.0 we could now get rid of this patch, as parent should always be available when executing rules. https://eslint.org/blog/2017/09/eslint-v4.7.0-released

However, I suppose it's not so "easy" to update our peerDependency to 4.7.0, right? That would probably require a major version bump?

@ljharb
Copy link
Member

ljharb commented Sep 19, 2017

Yes, it would require a major version bump.

@jseminck jseminck deleted the more-robust-no-typos-fix branch November 19, 2017 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants