Skip to content

Commit 7659928

Browse files
committed
refactor: minor improvements
1 parent 9d59cec commit 7659928

File tree

5 files changed

+28
-17
lines changed

5 files changed

+28
-17
lines changed

packages/ast/src/construction/construction-detector.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ export function constructionDetector<T extends RuleContext>(context: T): (node:
161161
});
162162
}
163163

164-
if (!("init" in latestDef.node) || latestDef.node.init === null) {
164+
if (
165+
!("init" in latestDef.node)
166+
|| latestDef.node.init === null
167+
) {
165168
return None;
166169
}
167170

packages/core/src/component/component-collector.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,9 @@ export function componentCollector(
202202
return;
203203
}
204204

205-
const component = Array.from(components.values()).findLast(c => {
206-
return O.isSome(c.name)
207-
&& c.name.value === maybeComponentName.value;
208-
});
205+
const component = Array
206+
.from(components.values())
207+
.findLast(({ name }) => O.exists(name, n => n === maybeComponentName.value));
209208

210209
if (!component) {
211210
return;

packages/core/src/hook/hook-collector.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ export function hookCollector(): {
6868
// "Custom Hooks may call other Hooks (that’s their whole purpose)." from https://react.dev/warnings/invalid-hook-call-warning
6969
// Further Reading: https://react.dev/learn/reusing-logic-with-custom-hooks#should-all-functions-called-during-rendering-start-with-the-use-prefix
7070
if (unsafeIsReactHookCall(node)) {
71-
const hook = Array.from(hooks.values()).find((hook) => hook.node === currentFn);
71+
const hook = Array
72+
.from(hooks.values())
73+
.find((hook) => hook.node === currentFn);
7274
if (!hook) {
7375
return;
7476
}

packages/eslint-plugin-jsx/src/rules/no-duplicate-key.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,19 @@ export default createRule<[], MessageID>({
125125
TSESTree.JSXExpression | TSESTree.Literal,
126126
][]>(
127127
(acc, element) => {
128-
const attr = element
129-
.openingElement
130-
.attributes
131-
.findLast(M.isMatching({ type: NodeType.JSXAttribute, name: { name: "key" } }));
132-
133-
if (!attr || !("value" in attr) || attr.value === null) {
128+
const attr = element.openingElement.attributes
129+
.findLast(M.isMatching({
130+
type: NodeType.JSXAttribute,
131+
name: {
132+
name: "key",
133+
},
134+
}));
135+
136+
if (
137+
!attr
138+
|| !("value" in attr)
139+
|| attr.value === null
140+
) {
134141
return acc;
135142
}
136143

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)