diff --git a/lib/rules/sort-comp.js b/lib/rules/sort-comp.js index e5e141fcb1..5c3e8f7ccb 100644 --- a/lib/rules/sort-comp.js +++ b/lib/rules/sort-comp.js @@ -384,10 +384,11 @@ module.exports = { node.value.type !== 'ArrowFunctionExpression' && node.value.type !== 'FunctionExpression', instanceMethod: !node.static && - node.type === 'ClassProperty' && node.value && - (node.value.type === 'ArrowFunctionExpression' || - node.value.type === 'FunctionExpression'), + ( + (node.type === 'ClassProperty' && node.value.type === 'ArrowFunctionExpression') || + (node.type === 'MethodDefinition' && node.value.type === 'FunctionExpression') + ), typeAnnotation: !!node.typeAnnotation && node.value === null })); diff --git a/tests/lib/rules/sort-comp.js b/tests/lib/rules/sort-comp.js index ac9da200a3..5de2f037fd 100644 --- a/tests/lib/rules/sort-comp.js +++ b/tests/lib/rules/sort-comp.js @@ -315,8 +315,8 @@ ruleTester.run('sort-comp', rule, { code: [ 'class Hello extends React.Component {', ' foo = () => {}', - ' constructor() {}', ' classMethod() {}', + ' constructor() {}', ' static bar = () => {}', ' render() {', ' return
{this.props.text}
;', @@ -573,7 +573,7 @@ ruleTester.run('sort-comp', rule, { '}' ].join('\n'), parser: 'babel-eslint', - errors: [{message: 'foo should be placed before constructor'}], + errors: [{message: 'classMethod should be placed before constructor'}], options: [{ order: [ 'instance-methods',