jsx-sort-props
Added in v0.9.1Configuration
Enforce a consistent order for JSX props.
Rule Details
This rule sorts JSX props alphabetically by default. A spread prop starts a new sortable group, so explicitly written props are never moved across a spread and their runtime override behavior is preserved. The default comparison is case-sensitive.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
The rule accepts one options object. Ordering constraints apply in this order: reserved props, callbacks, shorthand props, multiline props, then alphabetical sorting.
ignoreCase
When true, prop names are compared without case distinctions.
callbacksLast
When true, callback props whose names start with on followed by an uppercase
letter must appear after other props. This takes precedence over shorthand and
multiline ordering.
shorthandFirst
When true, shorthand props without a value appear before props with values.
They remain alphabetically sorted within each group.
shorthandLast
When true, shorthand props without a value appear after props with values.
They remain alphabetically sorted within each group.
multiline
Use "ignore" (the default), "first", or "last" to control props whose
source text spans multiple lines. Callback and shorthand constraints take
precedence over multiline ordering.
noSortAlphabetically
When true, alphabetical ordering is disabled while the other selected
constraints still apply.
reservedFirst
Set this to true to place React's reserved props (children,
dangerouslySetInnerHTML, key, and ref) before other props. The
dangerouslySetInnerHTML prop is reserved only on intrinsic DOM elements.
You can instead provide a non-empty subset of the reserved prop list.
locale
"auto" (the default) uses rslint's default collation for locale-aware
comparisons when ignoreCase is enabled. Provide a locale name to use
locale-aware ordering even without ignoreCase. Unicode collation extensions
used by Intl.Collator (co, kf, and kn) and the POSIX variant are
accepted; unsupported collations use the locale's default ordering. The
collation is selected the way Intl.Collator selects it, including language
aliases and region or script fallbacks. ASCII prop names are ordered like
Node.js's ICU, including locale contractions such as Czech and Slovak ch or
Danish aa, and locale-specific case order.
Differences from ESLint
- With
locale: "auto", rslint uses a deterministic default collation instead of the host environment's locale. Set an explicit locale such as"de"when locale-specific ordering is required. - Prop names outside printable ASCII use a simplified, deterministic
collation: an accented letter sorts with its base letter, but locale
rules for non-ASCII letters are not applied. For example, with
locale: "sv", rslint accepts<App ä z />while ESLint expects<App z ä />. - Hungarian uses the default order even for ASCII prop names, because its
doubled digraphs such as
ccs(twocsletters) are not modeled. For example, withlocale: "hu", rslint accepts<App cs cz />while ESLint expects<App cz cs />. - With a malformed
locale, rslint continues linting with its default order; ESLint stops with aRangeError. - If sorting a comment-attached block would reverse duplicate props, rslint reports the order without a fix; ESLint can change which prop value wins.
- rslint accepts only strings in a
reservedFirstarray. ESLint accepts other values and reports them as invalid rule options during linting; rslint rejects those configurations during schema validation.
When Not To Use It
This rule is a formatting preference. If alphabetical JSX prop ordering is not part of your project's style, leave it disabled.