Skip to content

Commit

Permalink
[jsx-sort-props] Fix rule's behavior
Browse files Browse the repository at this point in the history
- Remove unneccessary handling of sort-checking in jsx props, as this is
  being handled later by the general case anyways.
- Fix erroneous call to `generateFixerFunction` in general
  sort-checking, which was missing the `reservedList` parameter.
  • Loading branch information
fleischie committed Jul 13, 2018
1 parent 049d95e commit 21faf02
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions lib/rules/jsx-sort-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,24 +245,17 @@ 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({
node: decl,
message: 'Reserved props must be listed before all other props',
fix: generateFixerFunction(node, context, reservedList)
});
return memo;
}
return decl;
}

if (callbacksLast) {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 21faf02

Please sign in to comment.