Skip to content

Commit

Permalink
Fix sort-comp bad error message (fixes #507)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Croissant committed Nov 6, 2016
1 parent d88ee37 commit 8515667
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rules/sort-comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ module.exports = {
}
// Increment the prop score
errors[propA.index].score++;
// Stop here if we already have pushed another node at this position
if (getPropertyName(errors[propA.index].node) !== getPropertyName(propA.node)) {
return;
}
// Stop here if we already have a closer reference
if (Math.abs(propA.index - propB.index) > errors[propA.index].closest.distance) {
return;
Expand Down
23 changes: 23 additions & 0 deletions tests/lib/rules/sort-comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,5 +378,28 @@ ruleTester.run('sort-comp', rule, {
'render'
]
}]
}, {
code: [
'export default class View extends React.Component {',
' componentDidMountOk() {}',
' getB() {}',
' componentWillMount() {}',
' getA() {}',
' render() {}',
'}'
].join('\n'),
parser: 'babel-eslint',
errors: [{message: 'componentDidMountOk should be placed after getA'}],
options: [{
order: [
'static-methods',
'lifecycle',
'/^on.+$/',
'/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/',
'everything-else',
'/^render.+$/',
'render'
]
}]
}]
});

0 comments on commit 8515667

Please sign in to comment.