Skip to content

Commit c71d604

Browse files
committed
release: 0.10.4-beta.0
1 parent 969327f commit c71d604

File tree

3 files changed

+44
-29
lines changed

3 files changed

+44
-29
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
- Improve rule `react/no-unstable-default-props` to support checking for ObjectPatterns within VariableDeclarators that occur on props.
66

7+
### 🐞 Fixes
8+
9+
- Fix same kind of error inside a component should not only be reported once in rule `react/no-create-ref` and `react/no-constructed-context-value`.
10+
711
## v0.10.3 (Fri Jan 5 2024)
812

913
### 🪄 Improvements

packages/plugins/eslint-plugin-react/src/rules/no-constructed-context-value.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default createRule<[], MessageID>({
3535
create(context) {
3636
const { ctx, listeners } = useComponentCollector(context);
3737
const detectConstruction = constructionDetector(context);
38-
const possibleValueConstructions = new Map<TSESTreeFunction, ERConstruction>();
38+
const possibleValueConstructions = new Map<TSESTreeFunction, ERConstruction[]>();
3939

4040
return {
4141
...listeners,
@@ -55,30 +55,34 @@ export default createRule<[], MessageID>({
5555
const valueExpression = valueNode.expression;
5656
const constructionDetail = detectConstruction(valueExpression);
5757
if (constructionDetail._tag === "None") return;
58-
O.map(ctx.getCurrentFunction(), ([currentFn]) => possibleValueConstructions.set(currentFn, constructionDetail));
58+
O.map(
59+
ctx.getCurrentFunction(),
60+
([currentFn]) =>
61+
possibleValueConstructions.set(currentFn, [
62+
...possibleValueConstructions.get(currentFn) ?? [],
63+
constructionDetail,
64+
]),
65+
);
5966
},
6067
"Program:exit"(node) {
6168
const components = Array.from(ctx.getAllComponents(node).values());
62-
for (const [fn, detail] of possibleValueConstructions.entries()) {
63-
if (
64-
!components.some((component) => component.node === fn)
65-
|| detail._tag === "None"
66-
) {
67-
continue;
69+
for (const { node: component } of components) {
70+
const constructions = possibleValueConstructions.get(component);
71+
if (!constructions) continue;
72+
for (const construction of constructions) {
73+
if (construction._tag === "None") continue;
74+
const { _tag, node: constructionNode } = construction;
75+
const messageId = _tag.startsWith("Function")
76+
? "NO_CONSTRUCTED_CONTEXT_VALUE_WITH_FUNCTION"
77+
: "NO_CONSTRUCTED_CONTEXT_VALUE_WITH_IDENTIFIER";
78+
context.report({
79+
node: constructionNode,
80+
messageId,
81+
data: {
82+
type: constructionNode.type,
83+
},
84+
});
6885
}
69-
70-
const messageId = detail._tag.startsWith("Function")
71-
? "NO_CONSTRUCTED_CONTEXT_VALUE_WITH_FUNCTION"
72-
: "NO_CONSTRUCTED_CONTEXT_VALUE_WITH_IDENTIFIER";
73-
const { _tag, node } = detail;
74-
75-
context.report({
76-
data: {
77-
type: _tag.replaceAll("_", "").toLowerCase(),
78-
},
79-
messageId,
80-
node,
81-
});
8286
}
8387
},
8488
};

packages/plugins/eslint-plugin-react/src/rules/no-create-ref.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,29 @@ export default createRule<[], MessageID>({
2828
defaultOptions: [],
2929
create(context) {
3030
const { ctx, listeners } = useComponentCollector(context);
31-
const possibleCreateRefCalls = new Map<TSESTreeFunction, TSESTree.CallExpression>();
31+
const possibleCreateRefCalls = new Map<TSESTreeFunction, TSESTree.CallExpression[]>();
3232

3333
return {
3434
...listeners,
3535
CallExpression(node) {
3636
if (!isCreateRefCall(node, context)) return;
37-
O.map(ctx.getCurrentFunction(), ([currentFn]) => possibleCreateRefCalls.set(currentFn, node));
37+
O.map(
38+
ctx.getCurrentFunction(),
39+
([currentFn]) =>
40+
possibleCreateRefCalls.set(currentFn, [...possibleCreateRefCalls.get(currentFn) ?? [], node]),
41+
);
3842
},
3943
"Program:exit"(node) {
4044
const components = Array.from(ctx.getAllComponents(node).values());
41-
for (const [fn, call] of possibleCreateRefCalls.entries()) {
42-
if (!components.some((component) => component.node === fn)) continue;
43-
context.report({
44-
messageId: "NO_CREATE_REF",
45-
node: call,
46-
});
45+
for (const { node: component } of components) {
46+
const createRefCalls = possibleCreateRefCalls.get(component);
47+
if (!createRefCalls) continue;
48+
for (const createRefCall of createRefCalls) {
49+
context.report({
50+
node: createRefCall,
51+
messageId: "NO_CREATE_REF",
52+
});
53+
}
4754
}
4855
},
4956
};

0 commit comments

Comments
 (0)