diff --git a/lib/rules/jsx-sort-props.js b/lib/rules/jsx-sort-props.js index 99aba6b070..d6e5a982ef 100644 --- a/lib/rules/jsx-sort-props.js +++ b/lib/rules/jsx-sort-props.js @@ -245,15 +245,8 @@ module.exports = { const previousIsReserved = isReservedPropName(previousPropName, reservedList); const currentIsReserved = isReservedPropName(currentPropName, reservedList); - if ((previousIsReserved && currentIsReserved) || (!previousIsReserved && !currentIsReserved)) { - if (!noSortAlphabetically && currentPropName < previousPropName) { - context.report({ - node: decl, - message: 'Props should be sorted alphabetically', - fix: generateFixerFunction(node, context, reservedList) - }); - return memo; - } + if (previousIsReserved && !currentIsReserved) { + return decl; } if (!previousIsReserved && currentIsReserved) { context.report({ @@ -261,8 +254,8 @@ module.exports = { message: 'Reserved props must be listed before all other props', fix: generateFixerFunction(node, context, reservedList) }); + return memo; } - return decl; } if (callbacksLast) { @@ -310,7 +303,7 @@ module.exports = { context.report({ node: decl, message: 'Props should be sorted alphabetically', - fix: generateFixerFunction(node, context) + fix: generateFixerFunction(node, context, reservedList) }); return memo; } diff --git a/tests/lib/rules/jsx-sort-props.js b/tests/lib/rules/jsx-sort-props.js index 412ef4aefd..2f32e6b2ac 100644 --- a/tests/lib/rules/jsx-sort-props.js +++ b/tests/lib/rules/jsx-sort-props.js @@ -88,6 +88,10 @@ const reservedFirstWithNoSortAlphabeticallyArgs = [{ noSortAlphabetically: true, reservedFirst: true }]; +const reservedFirstWithShorthandLast = [{ + reservedFirst: true, + shorthandLast: true +}]; const reservedFirstAsEmptyArrayArgs = [{ reservedFirst: [] }]; @@ -149,6 +153,10 @@ ruleTester.run('jsx-sort-props', rule, { { code: '
} b a c />', options: reservedFirstWithNoSortAlphabeticallyArgs + }, + { + code: '