Skip to content

Commit

Permalink
[fix] jsx-sort-props: use localCompare rather than comparison operator
Browse files Browse the repository at this point in the history
Fixes #2381.
  • Loading branch information
tanmoyopenroot authored and ljharb committed Aug 23, 2019
1 parent e7f7e89 commit 398b7d7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/rules/jsx-sort-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ module.exports = {
}
}

if (!noSortAlphabetically && currentPropName < previousPropName) {
if (!noSortAlphabetically && previousPropName.localeCompare(currentPropName) > 0) {
context.report({
node: decl.name,
message: 'Props should be sorted alphabetically',
Expand Down
36 changes: 30 additions & 6 deletions tests/lib/rules/jsx-sort-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ ruleTester.run('jsx-sort-props', rule, {
{code: '<App a="c" b="b" c="a" />;'},
{code: '<App {...this.props} a="c" b="b" c="a" />;'},
{code: '<App c="a" {...this.props} a="c" b="b" />;'},
{code: '<App A a />;'},
{code: '<App a A />;'},
{code: '<App aa aB />;'},
{code: '<App aA aB />;'},
{code: '<App aaa aB />;'},
{code: '<App a aa aB />;'},
// Ignoring case
{code: '<App a A />;', options: ignoreCaseArgs},
{code: '<App a B c />;', options: ignoreCaseArgs},
Expand Down Expand Up @@ -165,6 +169,31 @@ ruleTester.run('jsx-sort-props', rule, {
errors: [expectedError],
output: '<App a b />;'
},
{
code: '<App aB a />;',
errors: [expectedError],
output: '<App a aB />;'
},
{
code: '<App A a />;',
errors: [expectedError],
output: '<App a A />;'
},
{
code: '<App aB aA />;',
errors: [expectedError],
output: '<App aA aB />;'
},
{
code: '<App aaB aA />;',
errors: [expectedError],
output: '<App aA aaB />;'
},
{
code: '<App aaB aaa aA a />;',
errors: [expectedError, expectedError, expectedError],
output: '<App a aA aaa aaB />;'
},
{
code: '<App {...this.props} b a />;',
errors: [expectedError],
Expand All @@ -175,11 +204,6 @@ ruleTester.run('jsx-sort-props', rule, {
errors: [expectedError],
output: '<App c {...this.props} a b />;'
},
{
code: '<App a A />;',
errors: [expectedError],
output: '<App a A />;'
},
{
code: '<App B a />;',
options: ignoreCaseArgs,
Expand Down

0 comments on commit 398b7d7

Please sign in to comment.