Skip to content

Commit

Permalink
Handle spread in jsx-sort-props
Browse files Browse the repository at this point in the history
  • Loading branch information
zertosh committed Mar 30, 2015
1 parent 6eac519 commit 08d791d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/rules/jsx-sort-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ module.exports = function(context) {

return {
JSXOpeningElement: function(node) {
node.attributes.reduce(function(memo, decl) {
var attributes = node.attributes.filter(function(decl) {
return decl.type === 'JSXAttribute';
});

attributes.reduce(function(memo, decl) {
var lastPropName = memo.name.name;
var currenPropName = decl.name.name;

Expand All @@ -30,7 +34,7 @@ module.exports = function(context) {
}

return decl;
}, node.attributes[0]);
}, attributes[0]);
}
};
};
7 changes: 6 additions & 1 deletion tests/lib/rules/jsx-sort-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,23 @@ var features = {
eslintTester.addRuleTest('lib/rules/jsx-sort-props', {
valid: [
{code: '<App />;', ecmaFeatures: features},
{code: '<App {...this.props} />;', ecmaFeatures: features},
{code: '<App a b c />;', ecmaFeatures: features},
{code: '<App {...this.props} a b c />;', ecmaFeatures: features},
{code: '<App a="c" b="b" c="a" />;', ecmaFeatures: features},
{code: '<App {...this.props} a="c" b="b" c="a" />;', ecmaFeatures: features},
{code: '<App A a />;', ecmaFeatures: features},
{code: '<App a A />;', args: ignoreCaseArgs, ecmaFeatures: features},
{code: '<App a B c />;', args: ignoreCaseArgs, ecmaFeatures: features},
{code: '<App A b C />;', args: ignoreCaseArgs, ecmaFeatures: features}
],
invalid: [
{code: '<App b a />;', errors: [expectedError], ecmaFeatures: features},
{code: '<App {...this.props} b a />;', errors: [expectedError], ecmaFeatures: features},
{code: '<App a A />;', errors: [expectedError], ecmaFeatures: features},
{code: '<App B a />;', args: ignoreCaseArgs, errors: [expectedError], ecmaFeatures: features},
{code: '<App B A c />;', args: ignoreCaseArgs, errors: [expectedError], ecmaFeatures: features},
{code: '<App c="a" a="c" b="b" />;', errors: 2, ecmaFeatures: features}
{code: '<App c="a" a="c" b="b" />;', errors: 2, ecmaFeatures: features},
{code: '<App {...this.props} c="a" a="c" b="b" />;', errors: 2, ecmaFeatures: features}
]
});

0 comments on commit 08d791d

Please sign in to comment.