Skip to content

Commit

Permalink
refactor(plugins/web-api): improve domain models
Browse files Browse the repository at this point in the history
  • Loading branch information
Rel1cx committed Aug 26, 2024
1 parent 129ecc3 commit 6e069d6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import { Data } from "@eslint-react/tools";
import type { TSESTree } from "@typescript-eslint/types";

export type EventListenerEntry = Data.TaggedEnum<{
addEventListener: ERSemanticEntry & {
AddEventListener: {
type: TSESTree.Node;
node: TSESTree.CallExpression | TSESTree.Identifier;
callee: TSESTree.Node;
capture: O.Option<boolean>;
listener: TSESTree.Node;
signal: O.Option<unknown>;
};
removeEventListener: ERSemanticEntry & {
} & ERSemanticEntry;
RemoveEventListener: ERSemanticEntry & {
type: TSESTree.Node;
node: TSESTree.CallExpression | TSESTree.Identifier;
callee: TSESTree.Node;
capture: O.Option<boolean>;
listener: TSESTree.Node;
};
} & ERSemanticEntry;

Check failure on line 21 in packages/plugins/eslint-plugin-react-web-api/src/models/EventListener/EventListenerEntry.ts

View workflow job for this annotation

GitHub Actions / Publish

Intersection type constituent is duplicated with ERSemanticEntry

Check failure on line 21 in packages/plugins/eslint-plugin-react-web-api/src/models/EventListener/EventListenerEntry.ts

View workflow job for this annotation

GitHub Actions / check

Intersection type constituent is duplicated with ERSemanticEntry
}>;

export const EventListenerEntry = Data.taggedEnum<EventListenerEntry>();
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
/* eslint-disable perfectionist/sort-object-types */
import type { ERSemanticEntry } from "@eslint-react/core";
import { Data } from "@eslint-react/tools";
import type { TSESTree } from "@typescript-eslint/types";

import type { ObserverKind } from "./ObserverKind";

export interface ObserverEntry extends ERSemanticEntry {
kind: ObserverKind;
node: TSESTree.CallExpression;
callee: TSESTree.Node;
observer: TSESTree.Node;
}
export type ObserverEntry = Data.TaggedEnum<{
Observe: {
kind: ObserverKind;
node: TSESTree.CallExpression;
element: TSESTree.Node;
callee: TSESTree.Node;
observer: TSESTree.Node;
} & ERSemanticEntry;
Unobserve: {
kind: ObserverKind;
node: TSESTree.CallExpression;
element: TSESTree.Node;
callee: TSESTree.Node;
observer: TSESTree.Node;
} & ERSemanticEntry;
Disconnect: {
kind: ObserverKind;
node: TSESTree.CallExpression;
callee: TSESTree.Node;
observer: TSESTree.Node;
} & ERSemanticEntry;
}>;

export const ObserverEntry = Data.taggedEnum<ObserverEntry>();
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line perfectionist/sort-union-types
export type ObserverMethod = "observe" | "unobserve" | "disconnect";
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./ObserverEntry";
export * from "./ObserverKind";
export * from "./ObserverMethod";
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ type EventMethodKind = "addEventListener" | "removeEventListener";
type CallKind = EventMethodKind | EREffectMethodKind | ERLifecycleMethodKind | "abort" | "other";
/* eslint-enable perfectionist/sort-union-types */

export type AEntry = EventListenerEntry & { _tag: "addEventListener" };
export type AEntry = EventListenerEntry & { _tag: "AddEventListener" };

export type REntry = EventListenerEntry & { _tag: "removeEventListener" };
export type REntry = EventListenerEntry & { _tag: "RemoveEventListener" };

// #endregion

Expand Down Expand Up @@ -185,7 +185,7 @@ export default createRule<[], MessageID>({
if (!PHASE_RELEVANCE.has(fKind)) break;
const opts = options ? getOptions(options, context.sourceCode.getScope(options)) : defaultOptions;
const callee = node.callee;
aEntries.push(EventListenerEntry.addEventListener({
aEntries.push(EventListenerEntry.AddEventListener({
...opts,
type,
node,
Expand All @@ -203,7 +203,7 @@ export default createRule<[], MessageID>({
if (!PHASE_RELEVANCE.has(fKind)) break;
const opts = options ? getOptions(options, context.sourceCode.getScope(options)) : defaultOptions;
const callee = node.callee;
rEntries.push(EventListenerEntry.removeEventListener({
rEntries.push(EventListenerEntry.RemoveEventListener({
...opts,
type,
node,
Expand Down

0 comments on commit 6e069d6

Please sign in to comment.