Skip to content

Commit e1a5889

Browse files
author
Yannick Croissant
committed
[Fix] sort-comp: correctly recognize instance variables declared without explicit value
Fixes #2183
1 parent 4a72e6a commit e1a5889

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/rules/sort-comp.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,7 @@ module.exports = {
392392
static: node.static,
393393
instanceVariable: !node.static &&
394394
node.type === 'ClassProperty' &&
395-
node.value &&
396-
!astUtil.isFunctionLikeExpression(node.value),
395+
(!node.value || !astUtil.isFunctionLikeExpression(node.value)),
397396
instanceMethod: !node.static &&
398397
node.type === 'ClassProperty' &&
399398
node.value &&

tests/lib/rules/sort-comp.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,29 @@ ruleTester.run('sort-comp', rule, {
480480
' static getDerivedStateFromProps() {}',
481481
'}'
482482
].join('\n')
483+
}, {
484+
code: `
485+
class MyComponent extends React.Component {
486+
state = {};
487+
foo;
488+
static propTypes;
489+
490+
render() {
491+
return null;
492+
}
493+
}
494+
`,
495+
parser: 'babel-eslint',
496+
options: [{
497+
order: [
498+
'state',
499+
'instance-variables',
500+
'static-methods',
501+
'lifecycle',
502+
'render',
503+
'everything-else'
504+
]
505+
}]
483506
}],
484507

485508
invalid: [{

0 commit comments

Comments
 (0)