Skip to content

Commit dccccad

Browse files
committed
sort-comp: enforcing static lifecycle methods order
1 parent 7aa4a03 commit dccccad

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/rules/sort-comp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ module.exports = {
172172
}
173173
}
174174

175-
if (method.static) {
175+
if (method.static && methodsOrder.indexOf(method.name) === -1) {
176176
const staticIndex = methodsOrder.indexOf('static-methods');
177177
if (staticIndex >= 0) {
178178
indexes.push(staticIndex);

tests/lib/rules/sort-comp.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,16 @@ ruleTester.run('sort-comp', rule, {
504504
].join('\n'),
505505
parser: 'babel-eslint',
506506
errors: [{message: 'render should be placed after displayName'}]
507+
}, {
508+
// Must validate static lifecycle methods
509+
code: [
510+
'class Hello extends React.Component {',
511+
' static getDerivedStateFromProps() {}',
512+
' constructor() {}',
513+
'}'
514+
].join('\n'),
515+
parser: 'babel-eslint',
516+
errors: [{message: 'getDerivedStateFromProps should be placed after constructor'}]
507517
}, {
508518
// Type Annotations should not be at the top by default
509519
code: [

0 commit comments

Comments
 (0)