diff --git a/lib/rules/sort-comp.js b/lib/rules/sort-comp.js index def7f9a694..6befbc0ba8 100644 --- a/lib/rules/sort-comp.js +++ b/lib/rules/sort-comp.js @@ -172,7 +172,7 @@ module.exports = { } } - if (method.static) { + if (indexes.length === 0 && method.static) { const staticIndex = methodsOrder.indexOf('static-methods'); if (staticIndex >= 0) { indexes.push(staticIndex); diff --git a/tests/lib/rules/sort-comp.js b/tests/lib/rules/sort-comp.js index 739ee55d73..7468acd42b 100644 --- a/tests/lib/rules/sort-comp.js +++ b/tests/lib/rules/sort-comp.js @@ -504,6 +504,15 @@ ruleTester.run('sort-comp', rule, { ].join('\n'), parser: 'babel-eslint', errors: [{message: 'render should be placed after displayName'}] + }, { + // Must validate static lifecycle methods + code: [ + 'class Hello extends React.Component {', + ' static getDerivedStateFromProps() {}', + ' constructor() {}', + '}' + ].join('\n'), + errors: [{message: 'getDerivedStateFromProps should be placed after constructor'}] }, { // Type Annotations should not be at the top by default code: [