Skip to content

Commit ab1631d

Browse files
author
Roy Sutton
committed
Fix sort-comp ClassExpression
Fixes #1076. Also adds test.
1 parent 22f3638 commit ab1631d

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/rules/sort-comp.js

+1
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ module.exports = {
291291
*/
292292
function getComponentProperties(node) {
293293
switch (node.type) {
294+
case 'ClassExpression':
294295
case 'ClassDeclaration':
295296
return node.body.body;
296297
case 'ObjectExpression':

tests/lib/rules/sort-comp.js

+14
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,20 @@ ruleTester.run('sort-comp', rule, {
286286
].join('\n'),
287287
parserOptions: parserOptions,
288288
errors: [{message: 'render should be placed after onClick'}]
289+
}, {
290+
// Must force a custom method to be placed before render, even in function
291+
code: [
292+
'var Hello = () => {',
293+
' return class Test extends React.Component {',
294+
' render () {',
295+
' return <div>Hello</div>;',
296+
' }',
297+
' onClick () {}',
298+
' }',
299+
'};'
300+
].join('\n'),
301+
parserOptions: parserOptions,
302+
errors: [{message: 'render should be placed after onClick'}]
289303
}, {
290304
// Must force a custom method to be placed after render if no 'everything-else' group is specified
291305
code: [

0 commit comments

Comments
 (0)