@kutur-kit/oxc 0.0.0-stage → 0.1.0-alpha.0
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 +21 -0
- package/README.md +42 -2
- package/dist/anti-slop.d.ts +4 -0
- package/dist/anti-slop.d.ts.map +1 -0
- package/dist/anti-slop.js +42 -0
- package/dist/anti-slop.js.map +1 -0
- package/dist/base.d.ts +4 -0
- package/dist/base.d.ts.map +1 -0
- package/dist/base.js +45 -0
- package/dist/base.js.map +1 -0
- package/dist/effect.d.ts +4 -0
- package/dist/effect.d.ts.map +1 -0
- package/dist/effect.js +8 -0
- package/dist/effect.js.map +1 -0
- package/dist/format.d.ts +4 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +26 -0
- package/dist/format.js.map +1 -0
- package/dist/plugin.d.ts +3 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +7 -0
- package/dist/plugin.js.map +1 -0
- package/dist/rules/no-yield-in-if.d.ts +2 -0
- package/dist/rules/no-yield-in-if.d.ts.map +1 -0
- package/dist/rules/no-yield-in-if.js +30 -0
- package/dist/rules/no-yield-in-if.js.map +1 -0
- package/dist/vendor/anti-slop/effect/index.d.ts +4 -0
- package/dist/vendor/anti-slop/effect/index.d.ts.map +1 -0
- package/dist/vendor/anti-slop/effect/index.js +19 -0
- package/dist/vendor/anti-slop/effect/index.js.map +1 -0
- package/dist/vendor/anti-slop/effect/rules/no-manual-effect-error-tag.d.ts +2 -0
- package/dist/vendor/anti-slop/effect/rules/no-manual-effect-error-tag.d.ts.map +1 -0
- package/dist/vendor/anti-slop/effect/rules/no-manual-effect-error-tag.js +40 -0
- package/dist/vendor/anti-slop/effect/rules/no-manual-effect-error-tag.js.map +1 -0
- package/dist/vendor/anti-slop/effect/rules/no-manual-tag-comparison.d.ts +2 -0
- package/dist/vendor/anti-slop/effect/rules/no-manual-tag-comparison.d.ts.map +1 -0
- package/dist/vendor/anti-slop/effect/rules/no-manual-tag-comparison.js +33 -0
- package/dist/vendor/anti-slop/effect/rules/no-manual-tag-comparison.js.map +1 -0
- package/dist/vendor/anti-slop/effect/rules/no-manual-tagged-construction.d.ts +2 -0
- package/dist/vendor/anti-slop/effect/rules/no-manual-tagged-construction.d.ts.map +1 -0
- package/dist/vendor/anti-slop/effect/rules/no-manual-tagged-construction.js +28 -0
- package/dist/vendor/anti-slop/effect/rules/no-manual-tagged-construction.js.map +1 -0
- package/dist/vendor/anti-slop/effect/rules/no-service-constructor-imports.d.ts +3 -0
- package/dist/vendor/anti-slop/effect/rules/no-service-constructor-imports.d.ts.map +1 -0
- package/dist/vendor/anti-slop/effect/rules/no-service-constructor-imports.js +45 -0
- package/dist/vendor/anti-slop/effect/rules/no-service-constructor-imports.js.map +1 -0
- package/dist/vendor/anti-slop/effect/rules/prefer-effect-match.d.ts +2 -0
- package/dist/vendor/anti-slop/effect/rules/prefer-effect-match.d.ts.map +1 -0
- package/dist/vendor/anti-slop/effect/rules/prefer-effect-match.js +49 -0
- package/dist/vendor/anti-slop/effect/rules/prefer-effect-match.js.map +1 -0
- package/dist/vendor/anti-slop/effect/shared/tagged-values.d.ts +9 -0
- package/dist/vendor/anti-slop/effect/shared/tagged-values.d.ts.map +1 -0
- package/dist/vendor/anti-slop/effect/shared/tagged-values.js +69 -0
- package/dist/vendor/anti-slop/effect/shared/tagged-values.js.map +1 -0
- package/dist/vendor/anti-slop/index.d.ts +4 -0
- package/dist/vendor/anti-slop/index.d.ts.map +1 -0
- package/dist/vendor/anti-slop/index.js +45 -0
- package/dist/vendor/anti-slop/index.js.map +1 -0
- package/dist/vendor/anti-slop/rules/no-array-filter-map.d.ts +3 -0
- package/dist/vendor/anti-slop/rules/no-array-filter-map.d.ts.map +1 -0
- package/dist/vendor/anti-slop/rules/no-array-filter-map.js +31 -0
- package/dist/vendor/anti-slop/rules/no-array-filter-map.js.map +1 -0
- package/dist/vendor/anti-slop/rules/no-chained-type-assertions.d.ts +3 -0
- package/dist/vendor/anti-slop/rules/no-chained-type-assertions.d.ts.map +1 -0
- package/dist/vendor/anti-slop/rules/no-chained-type-assertions.js +61 -0
- package/dist/vendor/anti-slop/rules/no-chained-type-assertions.js.map +1 -0
- package/dist/vendor/anti-slop/rules/no-conditional-empty-object-spread.d.ts +3 -0
- package/dist/vendor/anti-slop/rules/no-conditional-empty-object-spread.d.ts.map +1 -0
- package/dist/vendor/anti-slop/rules/no-conditional-empty-object-spread.js +41 -0
- package/dist/vendor/anti-slop/rules/no-conditional-empty-object-spread.js.map +1 -0
- package/dist/vendor/anti-slop/rules/no-known-value-widening.d.ts +3 -0
- package/dist/vendor/anti-slop/rules/no-known-value-widening.d.ts.map +1 -0
- package/dist/vendor/anti-slop/rules/no-known-value-widening.js +301 -0
- package/dist/vendor/anti-slop/rules/no-known-value-widening.js.map +1 -0
- package/dist/vendor/anti-slop/rules/no-module-mocking.d.ts +3 -0
- package/dist/vendor/anti-slop/rules/no-module-mocking.d.ts.map +1 -0
- package/dist/vendor/anti-slop/rules/no-module-mocking.js +70 -0
- package/dist/vendor/anti-slop/rules/no-module-mocking.js.map +1 -0
- package/dist/vendor/anti-slop/rules/no-object-parameters.d.ts +3 -0
- package/dist/vendor/anti-slop/rules/no-object-parameters.d.ts.map +1 -0
- package/dist/vendor/anti-slop/rules/no-object-parameters.js +57 -0
- package/dist/vendor/anti-slop/rules/no-object-parameters.js.map +1 -0
- package/dist/vendor/anti-slop/rules/no-reduce-accumulator-copy.d.ts +3 -0
- package/dist/vendor/anti-slop/rules/no-reduce-accumulator-copy.d.ts.map +1 -0
- package/dist/vendor/anti-slop/rules/no-reduce-accumulator-copy.js +100 -0
- package/dist/vendor/anti-slop/rules/no-reduce-accumulator-copy.js.map +1 -0
- package/dist/vendor/anti-slop/rules/no-reflect-apply.d.ts +3 -0
- package/dist/vendor/anti-slop/rules/no-reflect-apply.d.ts.map +1 -0
- package/dist/vendor/anti-slop/rules/no-reflect-apply.js +26 -0
- package/dist/vendor/anti-slop/rules/no-reflect-apply.js.map +1 -0
- package/dist/vendor/anti-slop/rules/no-reflect-get.d.ts +3 -0
- package/dist/vendor/anti-slop/rules/no-reflect-get.d.ts.map +1 -0
- package/dist/vendor/anti-slop/rules/no-reflect-get.js +26 -0
- package/dist/vendor/anti-slop/rules/no-reflect-get.js.map +1 -0
- package/dist/vendor/anti-slop/rules/no-runtime-typeof.d.ts +3 -0
- package/dist/vendor/anti-slop/rules/no-runtime-typeof.d.ts.map +1 -0
- package/dist/vendor/anti-slop/rules/no-runtime-typeof.js +65 -0
- package/dist/vendor/anti-slop/rules/no-runtime-typeof.js.map +1 -0
- package/dist/vendor/anti-slop/rules/no-shape-in-symbol-names.d.ts +3 -0
- package/dist/vendor/anti-slop/rules/no-shape-in-symbol-names.d.ts.map +1 -0
- package/dist/vendor/anti-slop/rules/no-shape-in-symbol-names.js +41 -0
- package/dist/vendor/anti-slop/rules/no-shape-in-symbol-names.js.map +1 -0
- package/dist/vendor/anti-slop/rules/no-unknown-parameters.d.ts +3 -0
- package/dist/vendor/anti-slop/rules/no-unknown-parameters.d.ts.map +1 -0
- package/dist/vendor/anti-slop/rules/no-unknown-parameters.js +52 -0
- package/dist/vendor/anti-slop/rules/no-unknown-parameters.js.map +1 -0
- package/dist/vendor/anti-slop/rules/no-unknown-returns.d.ts +3 -0
- package/dist/vendor/anti-slop/rules/no-unknown-returns.d.ts.map +1 -0
- package/dist/vendor/anti-slop/rules/no-unknown-returns.js +59 -0
- package/dist/vendor/anti-slop/rules/no-unknown-returns.js.map +1 -0
- package/dist/vendor/anti-slop/rules/no-unknown-type-aliases.d.ts +3 -0
- package/dist/vendor/anti-slop/rules/no-unknown-type-aliases.d.ts.map +1 -0
- package/dist/vendor/anti-slop/rules/no-unknown-type-aliases.js +41 -0
- package/dist/vendor/anti-slop/rules/no-unknown-type-aliases.js.map +1 -0
- package/dist/vendor/anti-slop/rules/no-unsafe-dictionary-type.d.ts +3 -0
- package/dist/vendor/anti-slop/rules/no-unsafe-dictionary-type.d.ts.map +1 -0
- package/dist/vendor/anti-slop/rules/no-unsafe-dictionary-type.js +135 -0
- package/dist/vendor/anti-slop/rules/no-unsafe-dictionary-type.js.map +1 -0
- package/dist/vendor/anti-slop/rules/no-widen-then-assert.d.ts +3 -0
- package/dist/vendor/anti-slop/rules/no-widen-then-assert.d.ts.map +1 -0
- package/dist/vendor/anti-slop/rules/no-widen-then-assert.js +271 -0
- package/dist/vendor/anti-slop/rules/no-widen-then-assert.js.map +1 -0
- package/dist/vendor/anti-slop/rules/require-readable-spacing.d.ts +4 -0
- package/dist/vendor/anti-slop/rules/require-readable-spacing.d.ts.map +1 -0
- package/dist/vendor/anti-slop/rules/require-readable-spacing.js +42 -0
- package/dist/vendor/anti-slop/rules/require-readable-spacing.js.map +1 -0
- package/dist/vendor/anti-slop/rules/require-safety-comment-for-type-assertion.d.ts +3 -0
- package/dist/vendor/anti-slop/rules/require-safety-comment-for-type-assertion.d.ts.map +1 -0
- package/dist/vendor/anti-slop/rules/require-safety-comment-for-type-assertion.js +101 -0
- package/dist/vendor/anti-slop/rules/require-safety-comment-for-type-assertion.js.map +1 -0
- package/dist/vendor/anti-slop/shared/array-method.d.ts +13 -0
- package/dist/vendor/anti-slop/shared/array-method.d.ts.map +1 -0
- package/dist/vendor/anti-slop/shared/array-method.js +85 -0
- package/dist/vendor/anti-slop/shared/array-method.js.map +1 -0
- package/dist/vendor/anti-slop/shared/dictionary-types.d.ts +21 -0
- package/dist/vendor/anti-slop/shared/dictionary-types.d.ts.map +1 -0
- package/dist/vendor/anti-slop/shared/dictionary-types.js +378 -0
- package/dist/vendor/anti-slop/shared/dictionary-types.js.map +1 -0
- package/dist/vendor/anti-slop/shared/function-parameters.d.ts +9 -0
- package/dist/vendor/anti-slop/shared/function-parameters.d.ts.map +1 -0
- package/dist/vendor/anti-slop/shared/function-parameters.js +41 -0
- package/dist/vendor/anti-slop/shared/function-parameters.js.map +1 -0
- package/dist/vendor/anti-slop/shared/lexical-type-parameters.d.ts +6 -0
- package/dist/vendor/anti-slop/shared/lexical-type-parameters.d.ts.map +1 -0
- package/dist/vendor/anti-slop/shared/lexical-type-parameters.js +48 -0
- package/dist/vendor/anti-slop/shared/lexical-type-parameters.js.map +1 -0
- package/dist/vendor/anti-slop/shared/reflect-method.d.ts +4 -0
- package/dist/vendor/anti-slop/shared/reflect-method.d.ts.map +1 -0
- package/dist/vendor/anti-slop/shared/reflect-method.js +21 -0
- package/dist/vendor/anti-slop/shared/reflect-method.js.map +1 -0
- package/dist/vendor/anti-slop/shared/scope.d.ts +4 -0
- package/dist/vendor/anti-slop/shared/scope.d.ts.map +1 -0
- package/dist/vendor/anti-slop/shared/scope.js +12 -0
- package/dist/vendor/anti-slop/shared/scope.js.map +1 -0
- package/dist/vendor/anti-slop/shared/type-alias-resolution.d.ts +24 -0
- package/dist/vendor/anti-slop/shared/type-alias-resolution.d.ts.map +1 -0
- package/dist/vendor/anti-slop/shared/type-alias-resolution.js +163 -0
- package/dist/vendor/anti-slop/shared/type-alias-resolution.js.map +1 -0
- package/dist/vendor/anti-slop/vendor/eslint-stylistic/padding-line-ast.d.ts +28 -0
- package/dist/vendor/anti-slop/vendor/eslint-stylistic/padding-line-ast.d.ts.map +1 -0
- package/dist/vendor/anti-slop/vendor/eslint-stylistic/padding-line-ast.js +29 -0
- package/dist/vendor/anti-slop/vendor/eslint-stylistic/padding-line-ast.js.map +1 -0
- package/dist/vendor/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.d.ts +5 -0
- package/dist/vendor/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.d.ts.map +1 -0
- package/dist/vendor/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.js +699 -0
- package/dist/vendor/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.js.map +1 -0
- package/package.json +71 -3
- package/src/anti-slop.ts +48 -0
- package/src/base.ts +49 -0
- package/src/effect.ts +12 -0
- package/src/format.ts +28 -0
- package/src/plugin.ts +8 -0
- package/src/rules/no-yield-in-if.ts +40 -0
- package/src/vendor/anti-slop/LICENSE +21 -0
- package/src/vendor/anti-slop/UPSTREAM.md +10 -0
- package/src/vendor/anti-slop/effect/index.ts +21 -0
- package/src/vendor/anti-slop/effect/rules/no-manual-effect-error-tag.ts +52 -0
- package/src/vendor/anti-slop/effect/rules/no-manual-tag-comparison.ts +45 -0
- package/src/vendor/anti-slop/effect/rules/no-manual-tagged-construction.ts +37 -0
- package/src/vendor/anti-slop/effect/rules/no-service-constructor-imports.ts +52 -0
- package/src/vendor/anti-slop/effect/rules/prefer-effect-match.ts +54 -0
- package/src/vendor/anti-slop/effect/shared/tagged-values.ts +97 -0
- package/src/vendor/anti-slop/index.ts +47 -0
- package/src/vendor/anti-slop/rules/no-array-filter-map.ts +28 -0
- package/src/vendor/anti-slop/rules/no-chained-type-assertions.ts +77 -0
- package/src/vendor/anti-slop/rules/no-conditional-empty-object-spread.ts +49 -0
- package/src/vendor/anti-slop/rules/no-known-value-widening.ts +415 -0
- package/src/vendor/anti-slop/rules/no-module-mocking.ts +80 -0
- package/src/vendor/anti-slop/rules/no-object-parameters.ts +83 -0
- package/src/vendor/anti-slop/rules/no-reduce-accumulator-copy.ts +109 -0
- package/src/vendor/anti-slop/rules/no-reflect-apply.ts +28 -0
- package/src/vendor/anti-slop/rules/no-reflect-get.ts +28 -0
- package/src/vendor/anti-slop/rules/no-runtime-typeof.ts +77 -0
- package/src/vendor/anti-slop/rules/no-shape-in-symbol-names.ts +46 -0
- package/src/vendor/anti-slop/rules/no-unknown-parameters.ts +69 -0
- package/src/vendor/anti-slop/rules/no-unknown-returns.ts +82 -0
- package/src/vendor/anti-slop/rules/no-unknown-type-aliases.ts +54 -0
- package/src/vendor/anti-slop/rules/no-unsafe-dictionary-type.ts +154 -0
- package/src/vendor/anti-slop/rules/no-widen-then-assert.ts +366 -0
- package/src/vendor/anti-slop/rules/require-readable-spacing.ts +47 -0
- package/src/vendor/anti-slop/rules/require-safety-comment-for-type-assertion.ts +131 -0
- package/src/vendor/anti-slop/shared/array-method.ts +94 -0
- package/src/vendor/anti-slop/shared/dictionary-types.ts +515 -0
- package/src/vendor/anti-slop/shared/function-parameters.ts +49 -0
- package/src/vendor/anti-slop/shared/lexical-type-parameters.ts +61 -0
- package/src/vendor/anti-slop/shared/reflect-method.ts +24 -0
- package/src/vendor/anti-slop/shared/scope.ts +15 -0
- package/src/vendor/anti-slop/shared/type-alias-resolution.ts +250 -0
- package/src/vendor/anti-slop/vendor/eslint-stylistic/LICENSE +22 -0
- package/src/vendor/anti-slop/vendor/eslint-stylistic/UPSTREAM.md +28 -0
- package/src/vendor/anti-slop/vendor/eslint-stylistic/padding-line-ast.ts +51 -0
- package/src/vendor/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.ts +906 -0
- package/src/vendor/anti-slop/vendor/eslint-stylistic/padding-line-options.d.ts +87 -0
|
@@ -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,47 @@
|
|
|
1
|
+
import { eslintCompatPlugin } from "@oxlint/plugins";
|
|
2
|
+
|
|
3
|
+
import { noArrayFilterMapRule } from "./rules/no-array-filter-map.ts";
|
|
4
|
+
import { noReduceAccumulatorCopyRule } from "./rules/no-reduce-accumulator-copy.ts";
|
|
5
|
+
import { noChainedTypeAssertionsRule } from "./rules/no-chained-type-assertions.ts";
|
|
6
|
+
import { noConditionalEmptyObjectSpreadRule } from "./rules/no-conditional-empty-object-spread.ts";
|
|
7
|
+
import { noKnownValueWideningRule } from "./rules/no-known-value-widening.ts";
|
|
8
|
+
import { noModuleMockingRule } from "./rules/no-module-mocking.ts";
|
|
9
|
+
import { noObjectParametersRule } from "./rules/no-object-parameters.ts";
|
|
10
|
+
import { noReflectApplyRule } from "./rules/no-reflect-apply.ts";
|
|
11
|
+
import { noReflectGetRule } from "./rules/no-reflect-get.ts";
|
|
12
|
+
import { noRuntimeTypeofRule } from "./rules/no-runtime-typeof.ts";
|
|
13
|
+
import { noForbiddenTermInSymbolNamesRule } from "./rules/no-shape-in-symbol-names.ts";
|
|
14
|
+
import { noUnknownParametersRule } from "./rules/no-unknown-parameters.ts";
|
|
15
|
+
import { noUnknownReturnsRule } from "./rules/no-unknown-returns.ts";
|
|
16
|
+
import { noUnknownTypeAliasesRule } from "./rules/no-unknown-type-aliases.ts";
|
|
17
|
+
import { noUnsafeDictionaryTypeRule } from "./rules/no-unsafe-dictionary-type.ts";
|
|
18
|
+
import { noWidenThenAssertRule } from "./rules/no-widen-then-assert.ts";
|
|
19
|
+
import { requireReadableSpacingRule } from "./rules/require-readable-spacing.ts";
|
|
20
|
+
import { requireSafetyCommentForTypeAssertionRule } from "./rules/require-safety-comment-for-type-assertion.ts";
|
|
21
|
+
|
|
22
|
+
/** Generic Oxlint rules that reject low-evidence and low-signal implementation patterns. */
|
|
23
|
+
const antiSlopPlugin = eslintCompatPlugin({
|
|
24
|
+
meta: { name: "anti-slop" },
|
|
25
|
+
rules: {
|
|
26
|
+
"no-array-filter-map": noArrayFilterMapRule,
|
|
27
|
+
"no-reduce-accumulator-copy": noReduceAccumulatorCopyRule,
|
|
28
|
+
"no-chained-type-assertions": noChainedTypeAssertionsRule,
|
|
29
|
+
"no-conditional-empty-object-spread": noConditionalEmptyObjectSpreadRule,
|
|
30
|
+
"no-known-value-widening": noKnownValueWideningRule,
|
|
31
|
+
"no-module-mocking": noModuleMockingRule,
|
|
32
|
+
"no-object-parameters": noObjectParametersRule,
|
|
33
|
+
"no-reflect-apply": noReflectApplyRule,
|
|
34
|
+
"no-reflect-get": noReflectGetRule,
|
|
35
|
+
"no-runtime-typeof": noRuntimeTypeofRule,
|
|
36
|
+
"no-unsafe-dictionary-type": noUnsafeDictionaryTypeRule,
|
|
37
|
+
"no-shape-in-symbol-names": noForbiddenTermInSymbolNamesRule,
|
|
38
|
+
"no-unknown-parameters": noUnknownParametersRule,
|
|
39
|
+
"no-unknown-returns": noUnknownReturnsRule,
|
|
40
|
+
"no-unknown-type-aliases": noUnknownTypeAliasesRule,
|
|
41
|
+
"no-widen-then-assert": noWidenThenAssertRule,
|
|
42
|
+
"require-readable-spacing": requireReadableSpacingRule,
|
|
43
|
+
"require-safety-comment-for-type-assertion": requireSafetyCommentForTypeAssertionRule,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export default antiSlopPlugin;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
|
|
3
|
+
import { arrayMethodTarget, isKnownArrayExpression, unwrapArrayExpression } from "../shared/array-method.ts";
|
|
4
|
+
|
|
5
|
+
/** Reject eager array filter/map pipelines; lazy iterator helpers remain allowed. */
|
|
6
|
+
export const noArrayFilterMapRule = defineRule({
|
|
7
|
+
meta: {
|
|
8
|
+
type: "suggestion",
|
|
9
|
+
docs: { description: "Disallow adjacent array filter/map passes in favor of lazy iterator helpers or a single transformation." },
|
|
10
|
+
messages: {
|
|
11
|
+
arrayFilterMap: "Avoid consecutive array `{{first}}` and `{{second}}` passes. Prefer `.values().{{first}}(...).{{second}}(...).toArray()` where iterator helpers are supported, or a single `flatMap`/mutating reducer. Preserve callback ordering, indexes, and filtering semantics.",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
createOnce(context) {
|
|
15
|
+
return {
|
|
16
|
+
CallExpression(node) {
|
|
17
|
+
const outer = arrayMethodTarget(node.callee);
|
|
18
|
+
if (outer === null || (outer.name !== "map" && outer.name !== "filter")) return;
|
|
19
|
+
const innerCall = unwrapArrayExpression(outer.object);
|
|
20
|
+
if (innerCall.type !== "CallExpression") return;
|
|
21
|
+
const inner = arrayMethodTarget(innerCall.callee);
|
|
22
|
+
if (inner === null || inner.name !== (outer.name === "map" ? "filter" : "map")) return;
|
|
23
|
+
if (!isKnownArrayExpression(context.sourceCode, inner.object)) return;
|
|
24
|
+
context.report({ node, messageId: "arrayFilterMap", data: { first: inner.name, second: outer.name } });
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import type { ESTree } from "@oxlint/plugins";
|
|
3
|
+
|
|
4
|
+
type TypeAssertionExpression = ESTree.TSAsExpression | ESTree.TSTypeAssertion;
|
|
5
|
+
|
|
6
|
+
function isTypeAssertionExpression(node: ESTree.Node): node is TypeAssertionExpression {
|
|
7
|
+
return node.type === "TSAsExpression" || node.type === "TSTypeAssertion";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function unwrapParenthesizedExpression(expression: ESTree.Expression): ESTree.Expression {
|
|
11
|
+
let current = expression;
|
|
12
|
+
while (current.type === "ParenthesizedExpression") {
|
|
13
|
+
current = current.expression;
|
|
14
|
+
}
|
|
15
|
+
return current;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function isConstAssertion(node: TypeAssertionExpression): boolean {
|
|
19
|
+
const { typeAnnotation } = node;
|
|
20
|
+
return (
|
|
21
|
+
typeAnnotation.type === "TSTypeReference" &&
|
|
22
|
+
typeAnnotation.typeName.type === "Identifier" &&
|
|
23
|
+
typeAnnotation.typeName.name === "const"
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isOutermostAssertionInChain(node: TypeAssertionExpression): boolean {
|
|
28
|
+
let current: ESTree.Expression = node;
|
|
29
|
+
let parent = node.parent;
|
|
30
|
+
|
|
31
|
+
while (parent.type === "ParenthesizedExpression" && parent.expression === current) {
|
|
32
|
+
current = parent;
|
|
33
|
+
parent = parent.parent;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return !isTypeAssertionExpression(parent) || parent.expression !== current;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isForbiddenAssertionChain(node: TypeAssertionExpression): boolean {
|
|
40
|
+
let assertionCount = 0;
|
|
41
|
+
let hasNonConstAssertion = false;
|
|
42
|
+
let current: ESTree.Expression = node;
|
|
43
|
+
|
|
44
|
+
while (isTypeAssertionExpression(current)) {
|
|
45
|
+
assertionCount += 1;
|
|
46
|
+
hasNonConstAssertion ||= !isConstAssertion(current);
|
|
47
|
+
current = unwrapParenthesizedExpression(current.expression);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return assertionCount > 1 && hasNonConstAssertion;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Disallow nested TypeScript type assertions, while permitting chains made only of const assertions. */
|
|
54
|
+
export const noChainedTypeAssertionsRule = defineRule({
|
|
55
|
+
meta: {
|
|
56
|
+
type: "problem",
|
|
57
|
+
docs: {
|
|
58
|
+
description:
|
|
59
|
+
"Disallow chained TypeScript as and angle-bracket assertions, including parenthesized chains.",
|
|
60
|
+
},
|
|
61
|
+
messages: {
|
|
62
|
+
chained:
|
|
63
|
+
"This assertion chain discards type evidence. Keep the original precise type, or parse untrusted input at its boundary before narrowing it.",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
createOnce(context) {
|
|
67
|
+
const checkTypeAssertion = (node: TypeAssertionExpression) => {
|
|
68
|
+
if (!isOutermostAssertionInChain(node) || !isForbiddenAssertionChain(node)) return;
|
|
69
|
+
context.report({ node, messageId: "chained" });
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
TSAsExpression: checkTypeAssertion,
|
|
74
|
+
TSTypeAssertion: checkTypeAssertion,
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import type { ESTree } from "@oxlint/plugins";
|
|
3
|
+
|
|
4
|
+
function unwrapParentheses(node: ESTree.Expression): ESTree.Expression {
|
|
5
|
+
let current = node;
|
|
6
|
+
while (current.type === "ParenthesizedExpression") {
|
|
7
|
+
current = current.expression;
|
|
8
|
+
}
|
|
9
|
+
return current;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function isEmptyObjectExpression(node: ESTree.Expression): boolean {
|
|
13
|
+
return node.type === "ObjectExpression" && node.properties.length === 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function isConditionalEmptyObjectSpread(node: ESTree.Expression): boolean {
|
|
17
|
+
const conditional = unwrapParentheses(node);
|
|
18
|
+
return (
|
|
19
|
+
conditional.type === "ConditionalExpression" &&
|
|
20
|
+
(isEmptyObjectExpression(conditional.consequent) ||
|
|
21
|
+
isEmptyObjectExpression(conditional.alternate))
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Ban conditional empty-object spreads without changing their omission semantics. */
|
|
26
|
+
export const noConditionalEmptyObjectSpreadRule = defineRule({
|
|
27
|
+
meta: {
|
|
28
|
+
type: "suggestion",
|
|
29
|
+
docs: {
|
|
30
|
+
description:
|
|
31
|
+
"Disallow object spreads that conditionally spread an empty object to omit fields.",
|
|
32
|
+
},
|
|
33
|
+
messages: {
|
|
34
|
+
avoid:
|
|
35
|
+
"This conditional spread hides property omission behind an empty object. Build the object in separate statements and add the property only when present.",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
createOnce(context) {
|
|
39
|
+
return {
|
|
40
|
+
SpreadElement(node) {
|
|
41
|
+
if (node.parent.type !== "ObjectExpression") return;
|
|
42
|
+
|
|
43
|
+
if (isConditionalEmptyObjectSpread(node.argument)) {
|
|
44
|
+
context.report({ node, messageId: "avoid" });
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
});
|