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

PropTypes defined in an external file #545

Closed
elicwhite opened this issue Apr 13, 2016 · 1 comment
Closed

PropTypes defined in an external file #545

elicwhite opened this issue Apr 13, 2016 · 1 comment
Labels

Comments

@elicwhite
Copy link

We have some prop types that are shared across many components and defined in their own module.

I want to be able to specify a component like this:

'use strict';

var React = require('react');
var externalPropTypes = require('./my_module');

var CommitView = React.createClass({
  propTypes: externalPropTypes.mySharedPropTypes,

  render: function() {
    return (
      <div>
        {this.props.myExternallyDefinedProp}
      </div>
    );
  }
});

module.exports = CommitView;

However it complains about this.props.myExternallyDefinedProp.

I understand that there is no way for eslint to be helpful and successfully lint this file and I'm fine with that. I just don't think it should be complaining here.

It does not complain (as it shouldn't) if the keys are defined and the values are pulled in externally:

'use strict';

var React = require('react');
var externalPropTypes = require('./my_module');

var CommitView = React.createClass({
  propTypes: React.PropTypes.shape({
    foo: externalPropTypes.sharedFooDefinition
  }),

  render: function() {
    return (
      <div>
        {this.props.foo.bar}
      </div>
    );
  }
});

module.exports = CommitView;

I think the rule should have the same non behavior when the whole value is pulled from an external file it doesn't know about.

@yannickcr
Copy link
Member

yannickcr commented Apr 13, 2016

It does not complain in this case:

var externalPropTypes = require('./my_module');

var Hello = React.createClass({
  propTypes: externalPropTypes,
  render: function() {
    return <div>Hello {this.props.name}</div>;
  }
});

So it should be a bug when accessing something like externalPropTypes.mySharedPropTypes instead of externalPropTypes directly.

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

No branches or pull requests

2 participants