Skip to content

Commit

Permalink
[Fix] sort-comp: correctly recognize instance variables declared wi…
Browse files Browse the repository at this point in the history
…thout explicit value

Fixes #2183
  • Loading branch information
Yannick Croissant committed Mar 5, 2019
1 parent 4a72e6a commit e1a5889
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/rules/sort-comp.js
Expand Up @@ -392,8 +392,7 @@ module.exports = {
static: node.static,
instanceVariable: !node.static &&
node.type === 'ClassProperty' &&
node.value &&
!astUtil.isFunctionLikeExpression(node.value),
(!node.value || !astUtil.isFunctionLikeExpression(node.value)),
instanceMethod: !node.static &&
node.type === 'ClassProperty' &&
node.value &&
Expand Down
23 changes: 23 additions & 0 deletions tests/lib/rules/sort-comp.js
Expand Up @@ -480,6 +480,29 @@ ruleTester.run('sort-comp', rule, {
' static getDerivedStateFromProps() {}',
'}'
].join('\n')
}, {
code: `
class MyComponent extends React.Component {
state = {};
foo;
static propTypes;
render() {
return null;
}
}
`,
parser: 'babel-eslint',
options: [{
order: [
'state',
'instance-variables',
'static-methods',
'lifecycle',
'render',
'everything-else'
]
}]
}],

invalid: [{
Expand Down

0 comments on commit e1a5889

Please sign in to comment.