From 4b2d7f27bb6a9932726eb783cc8df8b23f71a74e Mon Sep 17 00:00:00 2001 From: George Guliashvili Date: Thu, 25 Apr 2019 23:28:28 +0100 Subject: [PATCH] Simplify prop sorting code --- lib/rules/jsx-sort-props.js | 18 ++++++------------ tests/lib/rules/jsx-sort-props.js | 2 +- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/rules/jsx-sort-props.js b/lib/rules/jsx-sort-props.js index 5255093ae6..a0b83a4d06 100644 --- a/lib/rules/jsx-sort-props.js +++ b/lib/rules/jsx-sort-props.js @@ -34,11 +34,9 @@ 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; } } @@ -46,22 +44,18 @@ function contextCompare(a, b, options) { 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; } } diff --git a/tests/lib/rules/jsx-sort-props.js b/tests/lib/rules/jsx-sort-props.js index 33712a5996..a58dd57c91 100644 --- a/tests/lib/rules/jsx-sort-props.js +++ b/tests/lib/rules/jsx-sort-props.js @@ -343,7 +343,7 @@ ruleTester.run('jsx-sort-props', rule, { code: '', errors: [expectedError, expectedShorthandLastError], options: reservedFirstWithShorthandLast, - output: '' + output: '' }, { code: ';',