Skip to content

Commit 681b10a

Browse files
committed
fix: 'no-default-props' should report only function components, closes #1131
1 parent a22b4e8 commit 681b10a

File tree

2 files changed

+22
-33
lines changed

2 files changed

+22
-33
lines changed

packages/plugins/eslint-plugin-react-x/src/rules/no-default-props.spec.ts

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,6 @@ ruleTester.run(RULE_NAME, rule, {
1414
`,
1515
errors: [{ messageId: "noDefaultProps" }],
1616
},
17-
{
18-
code: tsx`
19-
class Input extends React.Component {
20-
render() {
21-
return <input />;
22-
}
23-
}
24-
Input.defaultProps = {};
25-
`,
26-
errors: [{ messageId: "noDefaultProps" }],
27-
},
28-
{
29-
code: tsx`
30-
class Input extends React.Component {
31-
static defaultProps = {};
32-
33-
render() {
34-
return <input />;
35-
}
36-
}
37-
`,
38-
errors: [{ messageId: "noDefaultProps" }],
39-
},
4017
],
4118
valid: [
4219
...allValid,
@@ -57,5 +34,26 @@ ruleTester.run(RULE_NAME, rule, {
5734
}
5835
}
5936
`,
37+
{
38+
code: tsx`
39+
class Input extends React.Component {
40+
static defaultProps = {};
41+
42+
render() {
43+
return <input />;
44+
}
45+
}
46+
`,
47+
},
48+
{
49+
code: tsx`
50+
class Input extends React.Component {
51+
render() {
52+
return <input />;
53+
}
54+
}
55+
Input.defaultProps = {};
56+
`,
57+
},
6058
],
6159
});

packages/plugins/eslint-plugin-react-x/src/rules/no-default-props.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,8 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
5151
const variable = VAR.findVariable(object.name, context.sourceCode.getScope(node));
5252
const variableNode = VAR.getVariableInitNode(variable, 0);
5353
if (variableNode == null) return;
54-
if (!AST.isFunction(variableNode) && !ER.isClassComponent(variableNode)) return;
54+
if (!AST.isFunction(variableNode)) return;
5555
context.report({ messageId: "noDefaultProps", node: property });
5656
},
57-
PropertyDefinition(node) {
58-
if (!ER.isClassComponent(node.parent.parent)) {
59-
return;
60-
}
61-
if (!node.static || node.key.type !== T.Identifier || node.key.name !== "defaultProps") {
62-
return;
63-
}
64-
context.report({ messageId: "noDefaultProps", node });
65-
},
6657
};
6758
}

0 commit comments

Comments
 (0)