@jfalava/ts-standard 0.1.0 → 0.2.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 jfalava
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@jfalava/ts-standard",
3
- "version": "0.1.0",
3
+ "version": "0.2.3",
4
4
  "description": "Checks a Bun repo against the TypeScript scripts and workflows standard: package.json scripts, pins, tsconfig and GitHub workflows.",
5
+ "license": "MIT",
5
6
  "repository": {
6
7
  "type": "git",
7
8
  "url": "git+https://github.com/jfalava/ts-standard.git"
8
9
  },
9
10
  "bin": {
10
- "ts-standard": "./src/cli.ts"
11
+ "ts-standard": "src/cli.ts"
11
12
  },
12
13
  "files": [
13
14
  "src",
@@ -25,14 +26,15 @@
25
26
  "fix": "bun run lint:fix && bun run format",
26
27
  "format": "oxfmt",
27
28
  "format:check": "oxfmt --check",
28
- "lint": "oxlint --type-aware --type-check",
29
- "lint:fix": "oxlint --type-aware --type-check --fix",
29
+ "lint": "oxlint --type-aware --type-check --disable-nested-config",
30
+ "lint:fix": "oxlint --type-aware --type-check --disable-nested-config --fix",
30
31
  "prepare": "effect-tsgo patch --no-typescript --tsrs --oxlint",
31
32
  "standard:check": "bun src/cli.ts",
32
33
  "test": "bun test",
33
34
  "typecheck": "effect-tsgo tsrs --noEmit"
34
35
  },
35
36
  "devDependencies": {
37
+ "@cloudflare/oxlint-config": "0.2.0",
36
38
  "@effect/tsgo": "0.74.1",
37
39
  "@oxlint/plugins": "1.95.0",
38
40
  "bun-types": "1.4.5",
@@ -0,0 +1,8 @@
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.
@@ -0,0 +1,21 @@
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;
@@ -0,0 +1,52 @@
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
+ });
@@ -0,0 +1,45 @@
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
+ });
@@ -0,0 +1,37 @@
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
+ });
@@ -0,0 +1,52 @@
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
+ });
@@ -0,0 +1,54 @@
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
+ });
@@ -0,0 +1,97 @@
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
+ };
@@ -0,0 +1,24 @@
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;
@@ -0,0 +1,80 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ import { resolveVariable } from "../shared/scope.ts";
4
+
5
+ import type { ESTree, SourceCode } from "@oxlint/plugins";
6
+
7
+ const moduleMockMethods = new Set(["doMock", "mock", "unstable_mockModule"]);
8
+
9
+ function importedName(node: ESTree.Node): string | null {
10
+ if (node.type !== "ImportSpecifier") return null;
11
+ return node.imported.type === "Identifier" ? node.imported.name : node.imported.value;
12
+ }
13
+
14
+ function isTestFrameworkObject(
15
+ sourceCode: SourceCode,
16
+ expression: ESTree.Expression,
17
+ ): expression is ESTree.IdentifierReference {
18
+ if (expression.type !== "Identifier") return false;
19
+ if (
20
+ (expression.name === "vi" || expression.name === "jest") &&
21
+ sourceCode.isGlobalReference(expression)
22
+ ) {
23
+ return true;
24
+ }
25
+
26
+ const variable = resolveVariable(sourceCode, expression);
27
+ if (variable === null || variable.defs.length === 0) {
28
+ return expression.name === "vi" || expression.name === "jest";
29
+ }
30
+ return variable.defs.some((definition) => {
31
+ if (definition.type !== "ImportBinding" || definition.parent?.type !== "ImportDeclaration") {
32
+ return false;
33
+ }
34
+ const source = definition.parent.source.value;
35
+ const name = importedName(definition.node);
36
+ return (source === "vitest" && name === "vi") || (source === "@jest/globals" && name === "jest");
37
+ });
38
+ }
39
+
40
+ function moduleMockCall(sourceCode: SourceCode, callee: ESTree.Expression): boolean {
41
+ if (!("property" in callee) || !("object" in callee) || !("computed" in callee)) return false;
42
+ if (!isTestFrameworkObject(sourceCode, callee.object)) return false;
43
+ const property = callee.property;
44
+ const method = callee.computed
45
+ ? property.type === "Literal" &&
46
+ (property.value === "doMock" ||
47
+ property.value === "mock" ||
48
+ property.value === "unstable_mockModule")
49
+ ? property.value
50
+ : null
51
+ : property.type === "Identifier"
52
+ ? property.name
53
+ : null;
54
+ return method !== null && moduleMockMethods.has(method);
55
+ }
56
+
57
+ /** Ban test framework module mocking in favor of real dependency seams. */
58
+ export const noModuleMockingRule = defineRule({
59
+ meta: {
60
+ type: "problem",
61
+ docs: {
62
+ description:
63
+ "Disallow Vitest and Jest module mocking; tests must replace dependencies through real interfaces.",
64
+ },
65
+ messages: {
66
+ moduleMock:
67
+ "Replace module mocking with dependency injection through a real interface, service layer, or faithful test implementation.",
68
+ },
69
+ },
70
+ createOnce(context) {
71
+ return {
72
+ CallExpression(node) {
73
+ if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression") return;
74
+ if (moduleMockCall(context.sourceCode, node.callee)) {
75
+ context.report({ node, messageId: "moduleMock" });
76
+ }
77
+ },
78
+ };
79
+ },
80
+ });
@@ -0,0 +1,77 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ import type { ESTree } from "@oxlint/plugins";
4
+
5
+ type RuntimeFunction = ESTree.ArrowFunctionExpression | ESTree.Function;
6
+
7
+ function isRuntimeFunction(node: ESTree.Node): node is RuntimeFunction {
8
+ return (
9
+ node.type === "ArrowFunctionExpression" ||
10
+ node.type === "FunctionDeclaration" ||
11
+ node.type === "FunctionExpression"
12
+ );
13
+ }
14
+
15
+ function isInsideTypeGuard(node: ESTree.Node): boolean {
16
+ let current: ESTree.Node | null = node.parent;
17
+ while (current !== null && current.type !== "Program") {
18
+ if (isRuntimeFunction(current)) {
19
+ return current.returnType?.typeAnnotation.type === "TSTypePredicate";
20
+ }
21
+ current = current.parent;
22
+ }
23
+ return false;
24
+ }
25
+
26
+ /** Return whether typeof safely probes for the existence of a possibly absent binding. */
27
+ function isExistenceProbe(node: ESTree.UnaryExpression): boolean {
28
+ const parent = node.parent;
29
+ if (parent.type !== "BinaryExpression") return false;
30
+ if (!["===", "!==", "==", "!="].includes(parent.operator)) return false;
31
+ const other = parent.left === node ? parent.right : parent.left;
32
+ return other.type === "Literal" && other.value === "undefined";
33
+ }
34
+
35
+ /** Disallow runtime typeof checks that narrow unparsed values instead of decoding them. */
36
+ export const noRuntimeTypeofRule = defineRule({
37
+ meta: {
38
+ type: "problem",
39
+ docs: {
40
+ description:
41
+ "Disallow runtime typeof checks; external values must be decoded into meaningful types at their I/O boundary.",
42
+ },
43
+ messages: {
44
+ runtimeTypeof:
45
+ "A `typeof` check narrows a representation without establishing its contract. Parse input at its I/O boundary, then branch on the domain value.",
46
+ },
47
+ schema: [
48
+ {
49
+ type: "object",
50
+ properties: {
51
+ allowInTypeGuards: { type: "boolean" },
52
+ },
53
+ additionalProperties: false,
54
+ },
55
+ ],
56
+ defaultOptions: [{ allowInTypeGuards: false }],
57
+ },
58
+ createOnce(context) {
59
+ return {
60
+ UnaryExpression(node) {
61
+ const option = context.options?.[0];
62
+ const allowInTypeGuards =
63
+ typeof option === "object" &&
64
+ option !== null &&
65
+ !Array.isArray(option) &&
66
+ option.allowInTypeGuards === true;
67
+ if (
68
+ node.operator === "typeof" &&
69
+ !isExistenceProbe(node) &&
70
+ (!allowInTypeGuards || !isInsideTypeGuard(node))
71
+ ) {
72
+ context.report({ node, messageId: "runtimeTypeof" });
73
+ }
74
+ },
75
+ };
76
+ },
77
+ });
@@ -0,0 +1,46 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import type { ESTree } from "@oxlint/plugins";
3
+
4
+ const FORBIDDEN_SYMBOL_NAME = "shape";
5
+
6
+ function containsForbiddenSymbolName(name: string): boolean {
7
+ return name.toLowerCase().includes(FORBIDDEN_SYMBOL_NAME);
8
+ }
9
+
10
+ /** Return whether an identifier names a statically accessed member owned by another value. */
11
+ function isBorrowedMemberName(node: ESTree.Node): boolean {
12
+ const parent = node.parent;
13
+ if (parent === null || parent.type !== "MemberExpression") return false;
14
+ return parent.property === node && parent.computed === false;
15
+ }
16
+
17
+ /** Ban the case-insensitive substring "shape" in every JavaScript and TypeScript symbol name. */
18
+ export const noForbiddenTermInSymbolNamesRule = defineRule({
19
+ meta: {
20
+ type: "problem",
21
+ docs: {
22
+ description:
23
+ 'Disallow the case-insensitive substring "shape" in JavaScript, TypeScript, private, and JSX symbol names.',
24
+ },
25
+ messages: {
26
+ forbiddenSymbolName:
27
+ 'Rename symbol "{{name}}" for its domain role; "shape" describes structure rather than ownership.',
28
+ },
29
+ },
30
+ createOnce(context) {
31
+ const reportForbiddenSymbolName = (node: ESTree.Node & { name: string }) => {
32
+ if (!containsForbiddenSymbolName(node.name) || isBorrowedMemberName(node)) return;
33
+ context.report({
34
+ node,
35
+ messageId: "forbiddenSymbolName",
36
+ data: { name: node.name },
37
+ });
38
+ };
39
+
40
+ return {
41
+ Identifier: reportForbiddenSymbolName,
42
+ PrivateIdentifier: reportForbiddenSymbolName,
43
+ JSXIdentifier: reportForbiddenSymbolName,
44
+ };
45
+ },
46
+ });