Skip to content

Commit 4b2d7f2

Browse files
committed
Simplify prop sorting code
1 parent 279c850 commit 4b2d7f2

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

lib/rules/jsx-sort-props.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,28 @@ function contextCompare(a, b, options) {
3434
if (options.reservedFirst) {
3535
const aIsReserved = isReservedPropName(aProp, options.reservedList);
3636
const bIsReserved = isReservedPropName(bProp, options.reservedList);
37-
if ((aIsReserved && bIsReserved) || (!aIsReserved && !bIsReserved)) {
38-
// pass
39-
} else if (aIsReserved && !bIsReserved) {
37+
if (aIsReserved && !bIsReserved) {
4038
return -1;
41-
} else {
39+
} else if (!aIsReserved && bIsReserved) {
4240
return 1;
4341
}
4442
}
4543

4644
if (options.callbacksLast) {
4745
const aIsCallback = isCallbackPropName(aProp);
4846
const bIsCallback = isCallbackPropName(bProp);
49-
if ((aIsCallback && bIsCallback) || (!aIsCallback && !bIsCallback)) {
50-
// pass
51-
} else if (aIsCallback && !bIsCallback) {
47+
if (aIsCallback && !bIsCallback) {
5248
return 1;
53-
} else {
49+
} else if (!aIsCallback && bIsCallback) {
5450
return -1;
5551
}
5652
}
5753

5854
if (options.shorthandFirst || options.shorthandLast) {
5955
const shorthandSign = options.shorthandFirst ? -1 : 1;
60-
if (!a.value && !b.value) {
61-
// pass
62-
} else if (!a.value) {
56+
if (!a.value && b.value) {
6357
return shorthandSign;
64-
} else {
58+
} else if (a.value && !b.value) {
6559
return -shorthandSign;
6660
}
6761
}

tests/lib/rules/jsx-sort-props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ ruleTester.run('jsx-sort-props', rule, {
343343
code: '<App ref="ref" key="key" isShorthand veryLastAttribute="yes" />',
344344
errors: [expectedError, expectedShorthandLastError],
345345
options: reservedFirstWithShorthandLast,
346-
output: '<App ref="ref" key="key" veryLastAttribute="yes" isShorthand />'
346+
output: '<App key="key" ref="ref" veryLastAttribute="yes" isShorthand />'
347347
},
348348
{
349349
code: '<App a z onFoo onBar />;',

0 commit comments

Comments
 (0)