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

Add requiredFirst option to jsx-sort-prop-types #392

Merged
merged 2 commits into from
Jan 13, 2016

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