Skip to content

Commit 2daaefe

Browse files
committed
feat(kit): add Reporter interface and update make function to return Reporter type
1 parent 2cf540b commit 2daaefe

File tree

6 files changed

+67
-65
lines changed

6 files changed

+67
-65
lines changed

packages/plugins/eslint-plugin-react-x/src/rules/no-missing-key.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default createRule<[], MessageID>({
3636
});
3737

3838
export function create(context: RuleContext<MessageID, []>): RuleListener {
39-
const report = RPT.make(context);
39+
const report = RPT.make<MessageID>(context);
4040
const state = { isWithinChildrenToArray: false };
4141

4242
function checkIteratorElement(node: TSESTree.Node): null | ReportDescriptor<MessageID> {
@@ -103,6 +103,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
103103
}
104104
const initialScope = context.sourceCode.getScope(node);
105105
for (const element of elements) {
106+
if (element?.type !== T.JSXElement) continue;
106107
if (!ER.hasAttribute(context, "key", element.openingElement.attributes, initialScope)) {
107108
report.send({
108109
messageId: "missingKey",

packages/utilities/ast/src/is.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { TSESTree } from "@typescript-eslint/utils";
21
import { or } from "@eslint-react/eff";
32
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
43
import { ASTUtils } from "@typescript-eslint/utils";

packages/utilities/kit/docs/@eslint-react/namespaces/Reporter/functions/make.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66

77
# Function: make()
88

9-
> **make**(`context`): [`Reporter`](../interfaces/Reporter.md)
9+
> **make**\<`TMessageID`\>(`context`): [`Reporter`](../interfaces/Reporter.md)\<`TMessageID`\>
10+
11+
## Type Parameters
12+
13+
### TMessageID
14+
15+
`TMessageID` *extends* `string`
1016

1117
## Parameters
1218

@@ -16,4 +22,4 @@
1622

1723
## Returns
1824

19-
[`Reporter`](../interfaces/Reporter.md)
25+
[`Reporter`](../interfaces/Reporter.md)\<`TMessageID`\>

packages/utilities/kit/docs/@eslint-react/namespaces/Reporter/interfaces/Reporter.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44

55
[@eslint-react/kit](../../../../README.md) / [Reporter](../README.md) / Reporter
66

7-
# Interface: Reporter
7+
# Interface: Reporter\<TMessageID\>
88

9-
## Properties
9+
## Type Parameters
1010

11-
### send()
11+
### TMessageID
1212

13-
> **send**: \<`TMessageID`\>(`descriptor`) => `void`
13+
`TMessageID` *extends* `string`
1414

15-
#### Type Parameters
15+
## Properties
1616

17-
##### TMessageID
17+
### send()
1818

19-
`TMessageID` *extends* `string`
19+
> **send**: (`descriptor`) => `void`
2020
2121
#### Parameters
2222

@@ -32,14 +32,10 @@
3232

3333
### sendOrElse()
3434

35-
> **sendOrElse**: \<`TMessageID`, `TElse`\>(`descriptor`, `cb`) => `undefined` \| `TElse`
35+
> **sendOrElse**: \<`TElse`\>(`descriptor`, `cb`) => `undefined` \| `TElse`
3636
3737
#### Type Parameters
3838

39-
##### TMessageID
40-
41-
`TMessageID` *extends* `string`
42-
4339
##### TElse
4440

4541
`TElse`

packages/utilities/kit/src/Reporter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import type { ReportDescriptor } from "@typescript-eslint/utils/ts-eslint";
22
import type { RuleContext } from "./types";
33
import { type _, dual } from "@eslint-react/eff";
44

5-
export interface Reporter {
6-
send: <TMessageID extends string>(descriptor: _ | null | ReportDescriptor<TMessageID>) => void;
5+
export interface Reporter<TMessageID extends string> {
6+
send: (descriptor: _ | null | ReportDescriptor<TMessageID>) => void;
77
// dprint-ignore
8-
sendOrElse: <TMessageID extends string, TElse>(descriptor: _ | null | ReportDescriptor<TMessageID>, cb: () => TElse) => _ | TElse;
8+
sendOrElse: <TElse>(descriptor: _ | null | ReportDescriptor<TMessageID>, cb: () => TElse) => _ | TElse;
99
}
1010

1111
export const send: {
@@ -26,7 +26,7 @@ export const sendOrElse: {
2626
return context.report(descriptor);
2727
});
2828

29-
export function make(context: RuleContext): Reporter {
29+
export function make<TMessageID extends string>(context: RuleContext): Reporter<TMessageID> {
3030
return {
3131
send: (...args) => send(context, ...args),
3232
sendOrElse: (...args) => sendOrElse(context, ...args),

0 commit comments

Comments
 (0)