sort-prop-types
Added in v0.9.1Configuration
Rule Details
Enforce a consistent order for React propTypes declarations. By default,
property names are compared case-sensitively in alphabetical order. A spread
property starts a new ordering group, so properties on either side of a spread
are not compared with each other.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
The rule checks assignments, class properties, object-literal propTypes
properties, and configured prop-wrapper functions. It can also inspect
PropTypes.shape declarations and TypeScript props declared on the first
parameter of a function component.
Options
All options are false by default.
requiredFirst
Require declarations whose validator ends in .isRequired to appear before
optional declarations.
Examples of incorrect code with { "requiredFirst": true }:
Examples of correct code with { "requiredFirst": true }:
callbacksLast
Require callback props whose names begin with on followed by an uppercase
ASCII letter to appear after other props. Callback props remain alphabetically
sorted among themselves unless noSortAlphabetically is enabled.
Examples of incorrect code with { "callbacksLast": true }:
Examples of correct code with { "callbacksLast": true }:
ignoreCase
Compare property names without regard to case.
Examples of incorrect code with { "ignoreCase": true }:
noSortAlphabetically
Disable alphabetical ordering. This is useful when only requiredFirst or
callbacksLast should determine the order.
sortShapeProp
Apply the same ordering rules to the object passed to a shape call. This also
works when the shape object is first assigned to an identifier.
Examples of incorrect code with { "sortShapeProp": true }:
Examples of correct code with { "sortShapeProp": true }:
checkTypes
Check TypeScript props declared as an inline type literal or a type alias on a function declaration or arrow function's first parameter.
Examples of incorrect code with { "checkTypes": true }:
Examples of correct code with { "checkTypes": true }:
Differences from ESLint
eslint-plugin-reactcan automatically reorder declarations with--fix. rslint reports the same ordering problems but does not currently apply a fix.