Skip to content

sort-comp: enforcing static lifecycle methods order #1795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (indexes.length === 0 && method.static) {
const staticIndex = methodsOrder.indexOf('static-methods');
if (staticIndex >= 0) {
indexes.push(staticIndex);
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/rules/sort-comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down