Skip to content

Commit 0eacd40

Browse files
committed
Improve tests.
1 parent 3d0dc23 commit 0eacd40

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

lib/rules/sort-comp.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,14 @@ module.exports = {
398398
getter: node.kind === 'get',
399399
setter: node.kind === 'set',
400400
static: node.static,
401-
instanceVariable: node.value && node.value.type !== 'ArrowFunctionExpression' && node.value.type !== 'FunctionExpression',
402-
instanceMethod: node.value && (node.value.type === 'ArrowFunctionExpression' || node.value.type === 'FunctionExpression'),
401+
instanceVariable: !node.static &&
402+
node.value &&
403+
node.value.type !== 'ArrowFunctionExpression' &&
404+
node.value.type !== 'FunctionExpression',
405+
instanceMethod: !node.static &&
406+
node.value &&
407+
(node.value.type === 'ArrowFunctionExpression' ||
408+
node.value.type === 'FunctionExpression'),
403409
typeAnnotation: !!node.typeAnnotation && node.value === null
404410
}));
405411

tests/lib/rules/sort-comp.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ ruleTester.run('sort-comp', rule, {
316316
'class Hello extends React.Component {',
317317
' foo = () => {}',
318318
' constructor() {}',
319+
' static bar = () => {}',
319320
' render() {',
320321
' return <div>{this.props.text}</div>;',
321322
' }',
@@ -325,7 +326,6 @@ ruleTester.run('sort-comp', rule, {
325326
options: [{
326327
order: [
327328
'instance-methods',
328-
'static-methods',
329329
'lifecycle',
330330
'everything-else',
331331
'render'
@@ -335,9 +335,10 @@ ruleTester.run('sort-comp', rule, {
335335
// Instance variables should be at the top
336336
code: [
337337
'class Hello extends React.Component {',
338-
' foo = "bar"',
338+
' foo = \'bar\'',
339339
' constructor() {}',
340340
' state = {}',
341+
' static bar = \'foo\'',
341342
' render() {',
342343
' return <div>{this.props.text}</div>;',
343344
' }',
@@ -347,7 +348,6 @@ ruleTester.run('sort-comp', rule, {
347348
options: [{
348349
order: [
349350
'instance-variables',
350-
'static-methods',
351351
'lifecycle',
352352
'everything-else',
353353
'render'
@@ -563,18 +563,18 @@ ruleTester.run('sort-comp', rule, {
563563
code: [
564564
'class Hello extends React.Component {',
565565
' constructor() {}',
566+
' static bar = () => {}',
566567
' foo = () => {}',
567568
' render() {',
568569
' return <div>{this.props.text}</div>;',
569570
' }',
570571
'}'
571572
].join('\n'),
572573
parser: 'babel-eslint',
573-
errors: [{message: 'constructor should be placed after foo'}],
574+
errors: [{message: 'foo should be placed before constructor'}],
574575
options: [{
575576
order: [
576577
'instance-methods',
577-
'static-methods',
578578
'lifecycle',
579579
'everything-else',
580580
'render'
@@ -586,7 +586,8 @@ ruleTester.run('sort-comp', rule, {
586586
'class Hello extends React.Component {',
587587
' constructor() {}',
588588
' state = {}',
589-
' foo = "bar"',
589+
' static bar = {}',
590+
' foo = {}',
590591
' render() {',
591592
' return <div>{this.props.text}</div>;',
592593
' }',
@@ -597,7 +598,6 @@ ruleTester.run('sort-comp', rule, {
597598
options: [{
598599
order: [
599600
'instance-variables',
600-
'static-methods',
601601
'lifecycle',
602602
'everything-else',
603603
'render'

0 commit comments

Comments
 (0)