Enhance jsx-sort-props to allow for non-alphabetically sorted groupings
See original GitHub issueIs there any interest in including a rule like the following in this plugin?
https://github.com/ericmatthys/eslint-plugin-jsx-grouped-sort-props
This is a rule that allows sorting of jsx props in groups without requiring an alphabetical sort. My motivation was wanting specific props sorted first (e.g. key
and ref
), then all other non-callback props in any order, then all callback props in any order at the end. The rule allows specific prop names in an array or various pre-configured groups (e.g. html
, reserved
, callback
). If there is a spread, it validates the prop order before and after the spread independently. For the use case above, the configuration would look like:
[
'key',
'ref',
{ group: 'other' },
{ group: 'callback' }
]
Valid:
<Button
ref="btn"
isLoading={true}
onClick={onClick}
/>
<Button
ref="btn"
onClick={onClick}
{...props}
isLoading={true}
/>
Invalid:
<Button
isLoading={true}
ref="btn"
onClick={onClick}
/>
<Button
ref="btn"
onClick={onClick}
isLoading={true}
/>
<Button
ref="btn"
{...props}
onClick={onClick}
isLoading={true}
/>
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Enhance jsx-sort-props to allow for non-alphabetically sorted ...
I think a good solution to this would be to have sortFirst and sortLast , which both take arrays of strings or regexes....
Read more >Sort objects in an array alphabetically on one property of the ...
sort () method to sort this array of objects by the DepartmentName property of each object? The array.sort() method works just fine when...
Read more >Sorting search results in SharePoint | Microsoft Learn
Sort search results by managed property value: Enables you to sort the search result based on the value of one or more managed...
Read more >Radix sort: No comparisons required - LogRocket Blog
We cover a special kind of sorting algorithm called radix sort, exploring how it works and how to implement it with JavaScript.
Read more >Sorting in JavaScript Grid control - Syncfusion
To sort multiple columns, press and hold the CTRL key and click the column header. You can clear sorting of any one of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sounds like an enhanced version of jsx-sort-props. There’s already a
callbacksLast
configuration option.I’ve rethought my opinion here.
While this would be a possible (feasible) option on jsx-sort-props, I think it would not be a good idea. Enforcing a magic, arbitrary sorting of props that isn’t based on something you can see by looking directly at the prop names would be incredibly confusing, and relying on the autofixer to understand what the “right” thing doesn’t remove that problem.
I think that it’s best that props either be unordered, or, ordered by simple-to-understand rules and categories, which currently include “reserved by react” props like key and ref etc, “alphabetical”, “boolean shorthand”, and “callbacks”. Arguably, this is already too complex.
I’m going to close this for now.