@jfalava/ts-standard 0.2.3 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/lint.ts CHANGED
@@ -1,35 +1,188 @@
1
- import { createHash } from "node:crypto";
2
- import { existsSync, readdirSync, readFileSync } from "node:fs";
3
- import { join, relative } from "node:path";
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { dirname, join, relative, resolve } from "node:path";
4
3
 
5
4
  import type { Finding } from "./finding.ts";
6
- import type { Repo } from "./repo.ts";
5
+ import type { Pkg, Repo } from "./repo.ts";
7
6
 
8
7
  const PRESET = "@cloudflare/oxlint-config";
9
- const REMAINDER = "tools/oxlint/anti-slop";
10
- /** The anti-slop rules @cloudflare/oxlint-config does not carry, as every repo vendors them. */
11
- const REFERENCE_REMAINDER = join(import.meta.dir, "..", "reference", "anti-slop");
12
- const OXFMT_CONFIGS = ["oxfmt.config.ts", ".oxfmtrc.json", ".oxfmtrc.jsonc"];
8
+ /** The anti-slop rules the preset does not carry, as this package publishes them. */
9
+ const ANTI_SLOP = "@jfalava/ts-standard/oxlint";
10
+ /** Where repos vendored those rules before this package published them. */
11
+ const VENDORED = "tools/oxlint/anti-slop";
13
12
 
14
- const filesUnder = (dir: string): string[] =>
15
- readdirSync(dir, { recursive: true, withFileTypes: true })
16
- .filter((entry) => entry.isFile())
17
- .map((entry) => relative(dir, join(entry.parentPath, entry.name)))
18
- .sort();
13
+ interface Plugin {
14
+ /** The plugin name, which prefixes its rule ids. */
15
+ readonly name: string;
16
+ readonly specifier: string;
17
+ /** The built file the specifier resolves to, inside this package. */
18
+ readonly file: string;
19
+ readonly rules: readonly string[];
20
+ }
19
21
 
20
- /** SHA-256 over every file's relative path and bytes, in path order. */
21
- export const treeHash = (dir: string): string => {
22
- const hash = createHash("sha256");
23
- for (const file of filesUnder(dir)) {
24
- hash.update(`${file}\0`);
25
- hash.update(readFileSync(join(dir, file)));
26
- hash.update("\0");
22
+ const GENERIC: Plugin = {
23
+ name: "anti-slop",
24
+ specifier: ANTI_SLOP,
25
+ file: "dist/oxlint/index.js",
26
+ rules: ["no-module-mocking", "require-safety-comment-for-type-assertion"],
27
+ };
28
+
29
+ // Its rules match code shape, such as any `x._tag === "A"`, not imports from `effect`: a package
30
+ // without Effect that loads it gets false positives, and one with Effect that does not loses them.
31
+ const EFFECT: Plugin = {
32
+ name: "anti-slop-effect",
33
+ specifier: `${ANTI_SLOP}/effect`,
34
+ file: "dist/oxlint/effect/index.js",
35
+ rules: [
36
+ "no-manual-effect-error-tag",
37
+ "no-manual-tag-comparison",
38
+ "no-manual-tagged-construction",
39
+ "no-service-constructor-imports",
40
+ "prefer-effect-match",
41
+ ],
42
+ };
43
+
44
+ const DEP_FIELDS = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"];
45
+ const usesEffect = (pkg: Pkg): boolean => DEP_FIELDS.some((f) => pkg.json[f]?.effect !== undefined);
46
+
47
+ /**
48
+ * The oxlint config a package's scripts lint with: the `-c`/`--config` one scripts pass, or else
49
+ * the nearest `oxlint.config.ts` up to the root. Undefined when no script runs oxlint.
50
+ */
51
+ const lintConfigOf = (repo: Repo, pkg: Pkg): string | undefined => {
52
+ const runs = Object.values(pkg.scripts).filter((s) => /(?:^|[\s;&|(])oxlint(?:\s|$)/.test(s));
53
+ if (runs.length === 0) {
54
+ return undefined;
27
55
  }
28
- return hash.digest("hex");
56
+ for (const script of runs) {
57
+ const flag = /(?:^|\s)(?:-c|--config)[ =](\S+)/.exec(script);
58
+ if (flag?.[1] !== undefined) {
59
+ return resolve(pkg.abs, flag[1]);
60
+ }
61
+ }
62
+ for (let dir = pkg.abs; ; dir = dirname(dir)) {
63
+ const path = join(dir, "oxlint.config.ts");
64
+ if (existsSync(path)) {
65
+ return path;
66
+ }
67
+ if (dir === repo.root || dir === dirname(dir)) {
68
+ return undefined;
69
+ }
70
+ }
71
+ };
72
+
73
+ type JsPlugin = string | { readonly name: string; readonly specifier: string };
74
+ type Level = "allow" | "off" | "warn" | "error" | "deny" | number;
75
+ interface Resolved {
76
+ readonly jsPlugins?: readonly JsPlugin[];
77
+ readonly rules?: Readonly<Partial<Record<string, Level | readonly [Level, ...unknown[]]>>>;
78
+ }
79
+
80
+ const specifierOf = (p: JsPlugin): string =>
81
+ (typeof p === "string" ? p : p.specifier).replace(/^file:\/\//, "");
82
+ /** Whether a resolved specifier is `plugin.file` inside this package, however it was installed. */
83
+ const isFileOf = (spec: string, plugin: Plugin): boolean => {
84
+ for (let dir = dirname(spec); dir !== dirname(dir); dir = dirname(dir)) {
85
+ const manifest = join(dir, "package.json");
86
+ if (existsSync(manifest)) {
87
+ const { name } = JSON.parse(readFileSync(manifest, "utf8")) as { name?: string };
88
+ return name === "@jfalava/ts-standard" && relative(dir, spec) === plugin.file;
89
+ }
90
+ }
91
+ return false;
29
92
  };
93
+ const loads = (config: Resolved, plugin: Plugin): JsPlugin | undefined =>
94
+ (config.jsPlugins ?? []).find((p) => {
95
+ const spec = specifierOf(p);
96
+ return spec === plugin.specifier || (spec.startsWith("/") && isFileOf(spec, plugin));
97
+ });
30
98
 
31
- const ignores = (text: string): boolean =>
32
- /["'](tools\/\*\*|tools\/oxlint\/anti-slop\/\*\*)["']/.test(text);
99
+ const isOff = (value: Level | readonly [Level, ...unknown[]]): boolean => {
100
+ const level = typeof value === "object" ? value[0] : value;
101
+ return level === "off" || level === 0;
102
+ };
103
+
104
+ /**
105
+ * A rule kept off on purpose sits in a pending map with its finding count, as
106
+ * `"anti-slop/x": "off", // 4`, in one of the repo's oxlint configs.
107
+ */
108
+ const pendingIn = (texts: readonly string[], rule: string): boolean => {
109
+ const id = rule.replaceAll("/", String.raw`\/`).replaceAll("-", String.raw`\-`);
110
+ const marker = new RegExp(`["']${id}["']\\s*:\\s*["']off["']\\s*,?\\s*//\\s*\\d`);
111
+ return texts.some((text) => marker.test(text));
112
+ };
113
+
114
+ /**
115
+ * Loads each linted package's oxlint config, as oxlint would, and reads its `jsPlugins` and
116
+ * top-level `rules`: the anti-slop plugin everywhere, the Effect plugin exactly where the
117
+ * package depends on `effect`, and every rule of a loaded plugin on or pending.
118
+ */
119
+ const pluginRules = (repo: Repo): Finding[] => {
120
+ const out: Finding[] = [];
121
+ const f = (where: string, message: string) =>
122
+ out.push({ rule: "lint/anti-slop", where, message });
123
+ const configs = new Set(
124
+ [repo.rootPkg, ...repo.workspaces].flatMap((pkg) => {
125
+ const path = join(pkg.abs, "oxlint.config.ts");
126
+ return existsSync(path) ? [path] : [];
127
+ }),
128
+ );
129
+ const texts = [...configs].map((path) => readFileSync(path, "utf8"));
130
+ for (const pkg of [repo.rootPkg, ...repo.workspaces]) {
131
+ const path = lintConfigOf(repo, pkg);
132
+ if (path === undefined) {
133
+ continue;
134
+ }
135
+ let config: Resolved;
136
+ try {
137
+ // oxlint imports the config the same way; it runs the repo's own code.
138
+ const mod = import.meta.require(path);
139
+ config = mod.default ?? mod;
140
+ } catch (error) {
141
+ f(pkg.dir, `could not load \`${relative(repo.root, path)}\`: ${String(error)}`);
142
+ continue;
143
+ }
144
+ if (!configs.has(path)) {
145
+ configs.add(path);
146
+ texts.push(readFileSync(path, "utf8"));
147
+ }
148
+ const effect = usesEffect(pkg);
149
+ for (const plugin of [GENERIC, EFFECT]) {
150
+ const entry = loads(config, plugin);
151
+ if (entry === undefined) {
152
+ if (plugin === GENERIC) {
153
+ f(pkg.dir, `does not load \`${GENERIC.specifier}\``);
154
+ } else if (effect) {
155
+ f(pkg.dir, `depends on \`effect\` but does not load \`${EFFECT.specifier}\``);
156
+ }
157
+ continue;
158
+ }
159
+ if (plugin === EFFECT && !effect) {
160
+ f(
161
+ pkg.dir,
162
+ `loads \`${EFFECT.specifier}\` without depending on \`effect\`; its rules match code shape and report code that is not Effect`,
163
+ );
164
+ continue;
165
+ }
166
+ if (typeof entry !== "string" && entry.name !== plugin.name) {
167
+ f(pkg.dir, `loads \`${plugin.specifier}\` as "${entry.name}"; name it "${plugin.name}"`);
168
+ continue;
169
+ }
170
+ for (const name of plugin.rules) {
171
+ const rule = `${plugin.name}/${name}`;
172
+ const value = config.rules?.[rule];
173
+ if (value === undefined) {
174
+ f(`${pkg.dir}:${rule}`, "is not configured, so it never runs; turn it on");
175
+ } else if (isOff(value) && !pendingIn(texts, rule)) {
176
+ f(
177
+ `${pkg.dir}:${rule}`,
178
+ `is off with no pending count; turn it on, or list it as \`"${rule}": "off", // <findings>\``,
179
+ );
180
+ }
181
+ }
182
+ }
183
+ }
184
+ return out;
185
+ };
33
186
 
34
187
  export const lintRules = (repo: Repo): Finding[] => {
35
188
  const out: Finding[] = [];
@@ -62,13 +215,6 @@ export const lintRules = (repo: Repo): Finding[] => {
62
215
  "set `categories.correctness`; the preset turns the category off",
63
216
  );
64
217
  }
65
- if (!ignores(text)) {
66
- f(
67
- "lint/anti-slop-remainder",
68
- "oxlint.config.ts",
69
- `\`ignorePatterns\` lacks \`${REMAINDER}\``,
70
- );
71
- }
72
218
  }
73
219
  for (const pkg of [repo.rootPkg, ...repo.workspaces]) {
74
220
  const path = join(pkg.abs, "oxlint.config.ts");
@@ -81,21 +227,13 @@ export const lintRules = (repo: Repo): Finding[] => {
81
227
  }
82
228
  }
83
229
 
84
- const remainder = join(repo.root, REMAINDER);
85
- if (!existsSync(remainder)) {
86
- f("lint/anti-slop-remainder", REMAINDER, "missing");
87
- } else if (treeHash(remainder) !== treeHash(REFERENCE_REMAINDER)) {
230
+ if (existsSync(join(repo.root, VENDORED))) {
88
231
  f(
89
- "lint/anti-slop-remainder",
90
- REMAINDER,
91
- "differs from the remainder every repo shares; copy node_modules/@jfalava/ts-standard/reference/anti-slop",
232
+ "lint/anti-slop",
233
+ VENDORED,
234
+ `a vendored copy; load \`${ANTI_SLOP}\` (and \`${ANTI_SLOP}/effect\`) and delete it`,
92
235
  );
93
236
  }
94
- const oxfmt = OXFMT_CONFIGS.find((name) => existsSync(join(repo.root, name)));
95
- if (oxfmt === undefined) {
96
- f("lint/anti-slop-remainder", ".", "no oxfmt config");
97
- } else if (!ignores(readFileSync(join(repo.root, oxfmt), "utf8"))) {
98
- f("lint/anti-slop-remainder", oxfmt, `\`ignorePatterns\` lacks \`${REMAINDER}\``);
99
- }
237
+ out.push(...pluginRules(repo));
100
238
  return out;
101
239
  };
@@ -1,8 +0,0 @@
1
- # anti-slop remainder
2
-
3
- - Source: https://github.com/dmmulroy/anti-slop at `63dbb09` (2026-11-20), `skills/install-anti-slop/assets/anti-slop/`. Its rule files are identical to `13909c9`.
4
- - Only the rules that `@cloudflare/oxlint-config` does not carry are vendored, unchanged:
5
- - `anti-slop`: `no-module-mocking`, `no-runtime-typeof`, `no-shape-in-symbol-names`, `no-unknown-parameters`, `require-safety-comment-for-type-assertion`, with `shared/function-parameters.ts` and `shared/scope.ts`.
6
- - `anti-slop-effect`: all five rules and `effect/shared/tagged-values.ts`. `effect/index.ts` is upstream's.
7
- - `index.ts` is upstream's with the other rules removed. The other twelve generic rules are in the preset as `quality/*`; `require-readable-spacing` is not kept.
8
- - This directory is the same in every repo that follows the TypeScript scripts and workflows standard. Change it in all of them at once.
@@ -1,21 +0,0 @@
1
- import { eslintCompatPlugin } from "@oxlint/plugins";
2
-
3
- import { noManualEffectErrorTagRule } from "./rules/no-manual-effect-error-tag.ts";
4
- import { noManualTagComparisonRule } from "./rules/no-manual-tag-comparison.ts";
5
- import { noManualTaggedConstructionRule } from "./rules/no-manual-tagged-construction.ts";
6
- import { noServiceConstructorImportsRule } from "./rules/no-service-constructor-imports.ts";
7
- import { preferEffectMatchRule } from "./rules/prefer-effect-match.ts";
8
-
9
- /** Opt-in Oxlint rules for Effect service and Layer architecture. */
10
- const antiSlopEffectPlugin = eslintCompatPlugin({
11
- meta: { name: "anti-slop-effect" },
12
- rules: {
13
- "no-manual-effect-error-tag": noManualEffectErrorTagRule,
14
- "no-manual-tag-comparison": noManualTagComparisonRule,
15
- "no-manual-tagged-construction": noManualTaggedConstructionRule,
16
- "no-service-constructor-imports": noServiceConstructorImportsRule,
17
- "prefer-effect-match": preferEffectMatchRule,
18
- },
19
- });
20
-
21
- export default antiSlopEffectPlugin;
@@ -1,52 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import {
4
- isInsideBroadEffectHandler,
5
- isReasonTagMember,
6
- isTagMember,
7
- tagMemberFromComparison,
8
- } from "../shared/tagged-values.ts";
9
-
10
- export const noManualEffectErrorTagRule = defineRule({
11
- meta: {
12
- type: "problem",
13
- docs: {
14
- description:
15
- "Use Effect tagged error handlers instead of manually branching on `_tag` in a catch handler.",
16
- },
17
- messages: {
18
- tag: "Use Effect.catchTag or Effect.catchTags instead of manually discriminating a tagged error in a broad Effect catch handler.",
19
- reason:
20
- "Use Effect.catchReason or Effect.catchReasons instead of manually discriminating a tagged `reason` in a broad Effect catch handler.",
21
- },
22
- },
23
- createOnce(context) {
24
- return {
25
- BinaryExpression(node) {
26
- const tagMember = tagMemberFromComparison(node);
27
- if (
28
- tagMember === undefined ||
29
- !isInsideBroadEffectHandler(node)
30
- ) {
31
- return;
32
- }
33
- context.report({
34
- node,
35
- messageId: isReasonTagMember(tagMember) ? "reason" : "tag",
36
- });
37
- },
38
- SwitchStatement(node) {
39
- if (
40
- !isTagMember(node.discriminant) ||
41
- !isInsideBroadEffectHandler(node)
42
- ) {
43
- return;
44
- }
45
- context.report({
46
- node,
47
- messageId: isReasonTagMember(node.discriminant) ? "reason" : "tag",
48
- });
49
- },
50
- };
51
- },
52
- });
@@ -1,45 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import {
4
- isInsideBroadEffectHandler,
5
- isTagMember,
6
- tagMemberFromComparison,
7
- } from "../shared/tagged-values.ts";
8
-
9
- export const noManualTagComparisonRule = defineRule({
10
- meta: {
11
- type: "problem",
12
- docs: {
13
- description:
14
- "Use Effect Match or Predicate helpers instead of manually branching on `_tag`.",
15
- },
16
- messages: {
17
- manualComparison:
18
- "Use Match.tag/Match.tags for tagged-value branching, or Predicate.isTagged for a simple reusable predicate.",
19
- manualSwitch:
20
- "Use Match.value(value).pipe(Match.tag/Match.tags/Match.tagsExhaustive) or the tagged enum `$match` helper instead of switching on `_tag`.",
21
- },
22
- },
23
- createOnce(context) {
24
- return {
25
- BinaryExpression(node) {
26
- if (
27
- tagMemberFromComparison(node) === undefined ||
28
- isInsideBroadEffectHandler(node)
29
- ) {
30
- return;
31
- }
32
- context.report({ node, messageId: "manualComparison" });
33
- },
34
- SwitchStatement(node) {
35
- if (
36
- !isTagMember(node.discriminant) ||
37
- isInsideBroadEffectHandler(node)
38
- ) {
39
- return;
40
- }
41
- context.report({ node, messageId: "manualSwitch" });
42
- },
43
- };
44
- },
45
- });
@@ -1,37 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import {
4
- isMatchPatternObject,
5
- isStringLiteral,
6
- propertyName,
7
- } from "../shared/tagged-values.ts";
8
-
9
- export const noManualTaggedConstructionRule = defineRule({
10
- meta: {
11
- type: "problem",
12
- docs: {
13
- description:
14
- "Construct tagged values with their existing Effect constructor instead of writing `_tag` manually.",
15
- },
16
- messages: {
17
- manualConstruction:
18
- "Use the existing Schema tagged `.make`, tagged class/error constructor, or Data.taggedEnum variant constructor instead of writing a literal `_tag` object.",
19
- },
20
- },
21
- createOnce(context) {
22
- return {
23
- ObjectExpression(node) {
24
- if (isMatchPatternObject(node)) return;
25
- const tag = node.properties.find(
26
- (property) =>
27
- property.type === "Property" &&
28
- propertyName(property) === "_tag" &&
29
- isStringLiteral(property.value),
30
- );
31
- if (tag !== undefined) {
32
- context.report({ node: tag, messageId: "manualConstruction" });
33
- }
34
- },
35
- };
36
- },
37
- });
@@ -1,52 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
-
3
- import type { ESTree } from "@oxlint/plugins";
4
-
5
- const SERVICE_CONSTRUCTOR_NAME = /^make[A-Z]/u;
6
- const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
7
-
8
- function isProjectLocalImport(source: string): boolean {
9
- return source.startsWith("./") || source.startsWith("../");
10
- }
11
-
12
- function getImportedName(specifier: ESTree.ImportSpecifier): string {
13
- if (specifier.imported.type === "Identifier") return specifier.imported.name;
14
- return specifier.imported.value;
15
- }
16
-
17
- /** Keep dependency-bearing Effect service constructors local to their owning capability modules. */
18
- export const noServiceConstructorImportsRule = defineRule({
19
- meta: {
20
- type: "problem",
21
- docs: {
22
- description:
23
- "Disallow project-local make<CapabilityName> imports outside test and spec files.",
24
- },
25
- messages: {
26
- serviceConstructorImport:
27
- 'Do not import Effect service constructor "{{name}}" into runtime code. Import the owning Layer, yield the contextual service, and allow its requirements to propagate to the composition root.',
28
- },
29
- },
30
- create(context) {
31
- const isTestFile = TEST_FILE.test(context.filename.replaceAll("\\", "/"));
32
-
33
- return {
34
- ImportDeclaration(node) {
35
- if (isTestFile || !isProjectLocalImport(node.source.value)) return;
36
-
37
- for (const specifier of node.specifiers) {
38
- if (specifier.type !== "ImportSpecifier") continue;
39
-
40
- const importedName = getImportedName(specifier);
41
- if (!SERVICE_CONSTRUCTOR_NAME.test(importedName)) continue;
42
-
43
- context.report({
44
- node: specifier,
45
- messageId: "serviceConstructorImport",
46
- data: { name: importedName },
47
- });
48
- }
49
- },
50
- };
51
- },
52
- });
@@ -1,54 +0,0 @@
1
- import { defineRule, type ESTree } from "@oxlint/plugins";
2
-
3
- const equalityOperators = new Set(["==", "===", "!=", "!=="]);
4
-
5
- export const preferEffectMatchRule = defineRule({
6
- meta: {
7
- type: "problem",
8
- docs: {
9
- description:
10
- "Use Match from Effect for chained literal ternaries over the same value.",
11
- },
12
- messages: {
13
- preferMatch:
14
- "Use Match from Effect instead of a chained literal ternary.",
15
- },
16
- },
17
- createOnce(context) {
18
- const isLiteral = (node: ESTree.Node): boolean =>
19
- node.type === "Literal" ||
20
- (node.type === "TemplateLiteral" && node.expressions.length === 0);
21
-
22
- const comparedValue = (node: ESTree.Expression): string | undefined => {
23
- if (
24
- node.type !== "BinaryExpression" ||
25
- !equalityOperators.has(node.operator)
26
- ) {
27
- return undefined;
28
- }
29
- if (isLiteral(node.left)) return context.sourceCode.getText(node.right);
30
- if (isLiteral(node.right)) return context.sourceCode.getText(node.left);
31
- return undefined;
32
- };
33
-
34
- return {
35
- ConditionalExpression(node) {
36
- if (node.parent?.type === "ConditionalExpression") return;
37
- const value = comparedValue(node.test);
38
- if (value === undefined) return;
39
-
40
- let alternate = node.alternate;
41
- let literalChecks = 1;
42
- while (alternate.type === "ConditionalExpression") {
43
- if (comparedValue(alternate.test) !== value) return;
44
- literalChecks += 1;
45
- alternate = alternate.alternate;
46
- }
47
-
48
- if (literalChecks > 1) {
49
- context.report({ node, messageId: "preferMatch" });
50
- }
51
- },
52
- };
53
- },
54
- });
@@ -1,97 +0,0 @@
1
- import type { ESTree } from "@oxlint/plugins";
2
-
3
- const equalityOperators = new Set(["==", "===", "!=", "!=="]);
4
- const broadEffectCatchMethods = new Set(["catch", "catchAll", "catchIf"]);
5
-
6
- export const isStringLiteral = (
7
- node: ESTree.Node | null | undefined,
8
- ): node is ESTree.StringLiteral =>
9
- node?.type === "Literal" && typeof node.value === "string";
10
-
11
- export const isTagMember = (
12
- node: ESTree.Node | null | undefined,
13
- ): node is ESTree.MemberExpression =>
14
- node?.type === "MemberExpression" &&
15
- ((!node.computed &&
16
- node.property.type === "Identifier" &&
17
- node.property.name === "_tag") ||
18
- (node.computed &&
19
- isStringLiteral(node.property) &&
20
- node.property.value === "_tag"));
21
-
22
- export const tagMemberFromComparison = (
23
- node: ESTree.BinaryExpression,
24
- ): ESTree.MemberExpression | undefined => {
25
- if (!equalityOperators.has(node.operator)) return undefined;
26
- if (isTagMember(node.left) && isStringLiteral(node.right)) return node.left;
27
- if (isTagMember(node.right) && isStringLiteral(node.left)) return node.right;
28
- return undefined;
29
- };
30
-
31
- const isBroadEffectCatchCall = (
32
- node: ESTree.Node | null | undefined,
33
- ): node is ESTree.CallExpression =>
34
- node?.type === "CallExpression" &&
35
- node.callee.type === "MemberExpression" &&
36
- node.callee.object.type === "Identifier" &&
37
- node.callee.object.name === "Effect" &&
38
- !node.callee.computed &&
39
- node.callee.property.type === "Identifier" &&
40
- broadEffectCatchMethods.has(node.callee.property.name);
41
-
42
- export const isInsideBroadEffectHandler = (node: ESTree.Node): boolean => {
43
- let current: ESTree.Node | null | undefined = node.parent;
44
- while (current !== null && current !== undefined) {
45
- if (
46
- current.type === "ArrowFunctionExpression" ||
47
- current.type === "FunctionExpression"
48
- ) {
49
- return (
50
- isBroadEffectCatchCall(current.parent) &&
51
- current.parent.arguments.includes(current)
52
- );
53
- }
54
- current = current.parent;
55
- }
56
- return false;
57
- };
58
-
59
- export const isReasonTagMember = (node: ESTree.MemberExpression): boolean =>
60
- node.object.type === "MemberExpression" &&
61
- ((!node.object.computed &&
62
- node.object.property.type === "Identifier" &&
63
- node.object.property.name === "reason") ||
64
- (node.object.computed &&
65
- isStringLiteral(node.object.property) &&
66
- node.object.property.value === "reason"));
67
-
68
- export const propertyName = (
69
- property: ESTree.ObjectProperty,
70
- ): string | undefined => {
71
- if (!property.computed && property.key.type === "Identifier") {
72
- return property.key.name;
73
- }
74
- if (
75
- property.key.type === "Literal" &&
76
- typeof property.key.value === "string"
77
- ) {
78
- return property.key.value;
79
- }
80
- return undefined;
81
- };
82
-
83
- export const isMatchPatternObject = (node: ESTree.ObjectExpression): boolean => {
84
- const call = node.parent;
85
- if (call?.type !== "CallExpression" || !call.arguments.includes(node)) {
86
- return false;
87
- }
88
- const callee = call.callee;
89
- return (
90
- callee.type === "MemberExpression" &&
91
- callee.object.type === "Identifier" &&
92
- callee.object.name === "Match" &&
93
- !callee.computed &&
94
- callee.property.type === "Identifier" &&
95
- (callee.property.name === "when" || callee.property.name === "not")
96
- );
97
- };
@@ -1,24 +0,0 @@
1
- import { eslintCompatPlugin } from "@oxlint/plugins";
2
-
3
- import { noModuleMockingRule } from "./rules/no-module-mocking.ts";
4
- import { noRuntimeTypeofRule } from "./rules/no-runtime-typeof.ts";
5
- import { noForbiddenTermInSymbolNamesRule } from "./rules/no-shape-in-symbol-names.ts";
6
- import { noUnknownParametersRule } from "./rules/no-unknown-parameters.ts";
7
- import { requireSafetyCommentForTypeAssertionRule } from "./rules/require-safety-comment-for-type-assertion.ts";
8
-
9
- /**
10
- * The anti-slop rules that @cloudflare/oxlint-config does not carry. The rest of anti-slop ships
11
- * in that preset as `quality/*`.
12
- */
13
- const antiSlopPlugin = eslintCompatPlugin({
14
- meta: { name: "anti-slop" },
15
- rules: {
16
- "no-module-mocking": noModuleMockingRule,
17
- "no-runtime-typeof": noRuntimeTypeofRule,
18
- "no-shape-in-symbol-names": noForbiddenTermInSymbolNamesRule,
19
- "no-unknown-parameters": noUnknownParametersRule,
20
- "require-safety-comment-for-type-assertion": requireSafetyCommentForTypeAssertionRule,
21
- },
22
- });
23
-
24
- export default antiSlopPlugin;