Skip to content

Commit

Permalink
Merge pull request #1221 from jseminck/sort-props-regression
Browse files Browse the repository at this point in the history
Fix regression bug in jsx-sort-props
  • Loading branch information
ljharb committed May 24, 2017
2 parents a8d4c9b + 12067db commit b74a693
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/rules/jsx-sort-props.js
Expand Up @@ -150,6 +150,8 @@ module.exports = {
var currentPropName = propName(decl);
var previousValue = memo.value;
var currentValue = decl.value;
var previousIsCallback = isCallbackPropName(previousPropName);
var currentIsCallback = isCallbackPropName(currentPropName);

if (ignoreCase) {
previousPropName = previousPropName.toLowerCase();
Expand Down Expand Up @@ -186,9 +188,6 @@ module.exports = {
}

if (callbacksLast) {
var previousIsCallback = isCallbackPropName(previousPropName);
var currentIsCallback = isCallbackPropName(currentPropName);

if (!previousIsCallback && currentIsCallback) {
// Entering the callback prop section
return decl;
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/rules/jsx-sort-props.js
Expand Up @@ -56,6 +56,10 @@ var expectedInvalidReservedFirstError = {
var callbacksLastArgs = [{
callbacksLast: true
}];
var ignoreCaseAndCallbackLastArgs = [{
callbacksLast: true,
ignoreCase: true
}];
var shorthandFirstArgs = [{
shorthandFirst: true
}];
Expand Down Expand Up @@ -109,6 +113,7 @@ ruleTester.run('jsx-sort-props', rule, {
{code: '<App A b C />;', options: ignoreCaseArgs},
// Sorting callbacks below all other props
{code: '<App a z onBar onFoo />;', options: callbacksLastArgs},
{code: '<App z onBar onFoo />;', options: ignoreCaseAndCallbackLastArgs},
// Sorting shorthand props before others
{code: '<App a b="b" />;', options: shorthandFirstArgs},
{code: '<App z a="a" />;', options: shorthandFirstArgs},
Expand Down

0 comments on commit b74a693

Please sign in to comment.