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

Parse extended class to read some informations #68

Closed
MoOx opened this issue Apr 17, 2015 · 4 comments
Closed

Parse extended class to read some informations #68

MoOx opened this issue Apr 17, 2015 · 4 comments

Comments

@MoOx
Copy link
Contributor

MoOx commented Apr 17, 2015

import React, {Component} from "react"

class A extends Component {

  static propTypes = {
    whatever: PropTypes.isRequired,
  }

  render() {
    return {this.props.whatever}
  }
}

class B extends A {
  render() {
    return {this.props.whatever}
  }
}

B gets an error on propTypes undefined on this component.

@yannickcr
Copy link
Member

Mmm, I think we can only have a limited support for this case.

We can handle the above script but not this one for example:

import A from "a"

class B extends A {
  render() {
    return {this.props.whatever}
  }
}

In this case the extended class is in another file and we cannot know if the propTypes property is defined in it or not.

@MoOx
Copy link
Contributor Author

MoOx commented Apr 17, 2015

I think the fs read might be a problem. But it's doable right ?
Maybe disabled by default but that can be handled when set to true ?

@yannickcr
Copy link
Member

Linting is only made on the current file content, starting to jump from file to file, resolving imports and finding how the class is constructed will be very complicated (but I accept PR 😉 ).

I can handle the original case and if you encounter the second one I think the best way to handle it should be to ignore the prop-types rule for this class:

import A from "a"

class B extends A { // eslint-disable-line react/prop-types
  render() {
    return {this.props.whatever}
  }
}

@gausie
Copy link
Contributor

gausie commented Mar 24, 2016

Is there a way we could do a decorator-style comment above a class manually to inform the parser that the class is a descendent of a Component and lint it thusly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants