Skip to content

Commit

Permalink
Simplify prop sorting code
Browse files Browse the repository at this point in the history
  • Loading branch information
guliashvili committed Apr 25, 2019
1 parent 279c850 commit 4b2d7f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
18 changes: 6 additions & 12 deletions lib/rules/jsx-sort-props.js
Expand Up @@ -34,34 +34,28 @@ function contextCompare(a, b, options) {
if (options.reservedFirst) {
const aIsReserved = isReservedPropName(aProp, options.reservedList);
const bIsReserved = isReservedPropName(bProp, options.reservedList);
if ((aIsReserved && bIsReserved) || (!aIsReserved && !bIsReserved)) {
// pass
} else if (aIsReserved && !bIsReserved) {
if (aIsReserved && !bIsReserved) {
return -1;
} else {
} else if (!aIsReserved && bIsReserved) {
return 1;
}
}

if (options.callbacksLast) {
const aIsCallback = isCallbackPropName(aProp);
const bIsCallback = isCallbackPropName(bProp);
if ((aIsCallback && bIsCallback) || (!aIsCallback && !bIsCallback)) {
// pass
} else if (aIsCallback && !bIsCallback) {
if (aIsCallback && !bIsCallback) {
return 1;
} else {
} else if (!aIsCallback && bIsCallback) {
return -1;
}
}

if (options.shorthandFirst || options.shorthandLast) {
const shorthandSign = options.shorthandFirst ? -1 : 1;
if (!a.value && !b.value) {
// pass
} else if (!a.value) {
if (!a.value && b.value) {
return shorthandSign;
} else {
} else if (a.value && !b.value) {
return -shorthandSign;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/jsx-sort-props.js
Expand Up @@ -343,7 +343,7 @@ ruleTester.run('jsx-sort-props', rule, {
code: '<App ref="ref" key="key" isShorthand veryLastAttribute="yes" />',
errors: [expectedError, expectedShorthandLastError],
options: reservedFirstWithShorthandLast,
output: '<App ref="ref" key="key" veryLastAttribute="yes" isShorthand />'
output: '<App key="key" ref="ref" veryLastAttribute="yes" isShorthand />'
},
{
code: '<App a z onFoo onBar />;',
Expand Down

0 comments on commit 4b2d7f2

Please sign in to comment.