Skip to content

Conversation

@chrislaskey
Copy link

Hey there, I've been really enjoying eslint-plugin-react, thanks for creating such a great set of React rules for ESLint!

Our team likes to put required prop type declarations first, followed by optional prop types. I extended the existing jsx-sort-prop-types rule to take a requiredFirst option to make this enforceable by ESLint.

When set to true required props must come first and be sorted alphabetically:

class First extends React.Component {
  render() {
    return <div />;
  }
}

First.propTypes = {
  barRequired: React.PropTypes.string.isRequired,
  fooRequired: React.PropTypes.any.isRequired,
  a: React.PropTypes.any,
  z: React.PropTypes.string,
  onBar: React.PropTypes.func,
  onFoo: React.PropTypes.func
};

In addition to the changes this PR includes tests and documentation.

Figured others could find it useful too. 😃

yannickcr added a commit that referenced this pull request Jan 13, 2016
Add requiredFirst option to jsx-sort-prop-types
@yannickcr yannickcr merged commit 42f9c0c into jsx-eslint:master Jan 13, 2016
@yannickcr
Copy link
Member

Great! Thanks!

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.

2 participants