Skip to content

Commit 8515667

Browse files
author
Yannick Croissant
committed
Fix sort-comp bad error message (fixes #507)
1 parent d88ee37 commit 8515667

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/rules/sort-comp.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ module.exports = {
217217
}
218218
// Increment the prop score
219219
errors[propA.index].score++;
220+
// Stop here if we already have pushed another node at this position
221+
if (getPropertyName(errors[propA.index].node) !== getPropertyName(propA.node)) {
222+
return;
223+
}
220224
// Stop here if we already have a closer reference
221225
if (Math.abs(propA.index - propB.index) > errors[propA.index].closest.distance) {
222226
return;

tests/lib/rules/sort-comp.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,5 +378,28 @@ ruleTester.run('sort-comp', rule, {
378378
'render'
379379
]
380380
}]
381+
}, {
382+
code: [
383+
'export default class View extends React.Component {',
384+
' componentDidMountOk() {}',
385+
' getB() {}',
386+
' componentWillMount() {}',
387+
' getA() {}',
388+
' render() {}',
389+
'}'
390+
].join('\n'),
391+
parser: 'babel-eslint',
392+
errors: [{message: 'componentDidMountOk should be placed after getA'}],
393+
options: [{
394+
order: [
395+
'static-methods',
396+
'lifecycle',
397+
'/^on.+$/',
398+
'/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/',
399+
'everything-else',
400+
'/^render.+$/',
401+
'render'
402+
]
403+
}]
381404
}]
382405
});

0 commit comments

Comments
 (0)