Skip to content

Commit

Permalink
sort-comp: enforcing static lifecycle methods order
Browse files Browse the repository at this point in the history
  • Loading branch information
lynxtaa committed May 14, 2018
1 parent 7aa4a03 commit dccccad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/sort-comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ module.exports = {
}
}

if (method.static) {
if (method.static && methodsOrder.indexOf(method.name) === -1) {
const staticIndex = methodsOrder.indexOf('static-methods');
if (staticIndex >= 0) {
indexes.push(staticIndex);
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/sort-comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,16 @@ 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'),
parser: 'babel-eslint',
errors: [{message: 'getDerivedStateFromProps should be placed after constructor'}]
}, {
// Type Annotations should not be at the top by default
code: [
Expand Down

0 comments on commit dccccad

Please sign in to comment.