@kutur-kit/oxc 0.0.0-stage → 0.1.0-alpha.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/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,9 @@
|
|
|
1
|
+
import type { ESTree } from "@oxlint/plugins";
|
|
2
|
+
export declare const isStringLiteral: (node: ESTree.Node | null | undefined) => node is ESTree.StringLiteral;
|
|
3
|
+
export declare const isTagMember: (node: ESTree.Node | null | undefined) => node is ESTree.MemberExpression;
|
|
4
|
+
export declare const tagMemberFromComparison: (node: ESTree.BinaryExpression) => ESTree.MemberExpression | undefined;
|
|
5
|
+
export declare const isInsideBroadEffectHandler: (node: ESTree.Node) => boolean;
|
|
6
|
+
export declare const isReasonTagMember: (node: ESTree.MemberExpression) => boolean;
|
|
7
|
+
export declare const propertyName: (property: ESTree.ObjectProperty) => string | undefined;
|
|
8
|
+
export declare const isMatchPatternObject: (node: ESTree.ObjectExpression) => boolean;
|
|
9
|
+
//# sourceMappingURL=tagged-values.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tagged-values.d.ts","sourceRoot":"","sources":["../../../../../src/vendor/anti-slop/effect/shared/tagged-values.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAK9C,eAAO,MAAM,eAAe,SACrB,MAAM,CAAC,IAAI,GAAG,IAAI,GAAG,SAAS,KAClC,IAAI,IAAI,MAAM,CAAC,aACyC,CAAC;AAE5D,eAAO,MAAM,WAAW,SACjB,MAAM,CAAC,IAAI,GAAG,IAAI,GAAG,SAAS,KAClC,IAAI,IAAI,MAAM,CAAC,gBAOiB,CAAC;AAEpC,eAAO,MAAM,uBAAuB,SAC7B,MAAM,CAAC,gBAAgB,KAC3B,MAAM,CAAC,gBAAgB,GAAG,SAK5B,CAAC;AAaF,eAAO,MAAM,0BAA0B,SAAU,MAAM,CAAC,IAAI,KAAG,OAe9D,CAAC;AAEF,eAAO,MAAM,iBAAiB,SAAU,MAAM,CAAC,gBAAgB,KAAG,OAOtB,CAAC;AAE7C,eAAO,MAAM,YAAY,aACd,MAAM,CAAC,cAAc,KAC7B,MAAM,GAAG,SAWX,CAAC;AAEF,eAAO,MAAM,oBAAoB,SAAU,MAAM,CAAC,gBAAgB,KAAG,OAcpE,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const equalityOperators = new Set(["==", "===", "!=", "!=="]);
|
|
2
|
+
const broadEffectCatchMethods = new Set(["catch", "catchAll", "catchIf"]);
|
|
3
|
+
export const isStringLiteral = (node) => node?.type === "Literal" && typeof node.value === "string";
|
|
4
|
+
export const isTagMember = (node) => node?.type === "MemberExpression" &&
|
|
5
|
+
((!node.computed &&
|
|
6
|
+
node.property.type === "Identifier" &&
|
|
7
|
+
node.property.name === "_tag") ||
|
|
8
|
+
(node.computed &&
|
|
9
|
+
isStringLiteral(node.property) &&
|
|
10
|
+
node.property.value === "_tag"));
|
|
11
|
+
export const tagMemberFromComparison = (node) => {
|
|
12
|
+
if (!equalityOperators.has(node.operator))
|
|
13
|
+
return undefined;
|
|
14
|
+
if (isTagMember(node.left) && isStringLiteral(node.right))
|
|
15
|
+
return node.left;
|
|
16
|
+
if (isTagMember(node.right) && isStringLiteral(node.left))
|
|
17
|
+
return node.right;
|
|
18
|
+
return undefined;
|
|
19
|
+
};
|
|
20
|
+
const isBroadEffectCatchCall = (node) => node?.type === "CallExpression" &&
|
|
21
|
+
node.callee.type === "MemberExpression" &&
|
|
22
|
+
node.callee.object.type === "Identifier" &&
|
|
23
|
+
node.callee.object.name === "Effect" &&
|
|
24
|
+
!node.callee.computed &&
|
|
25
|
+
node.callee.property.type === "Identifier" &&
|
|
26
|
+
broadEffectCatchMethods.has(node.callee.property.name);
|
|
27
|
+
export const isInsideBroadEffectHandler = (node) => {
|
|
28
|
+
let current = node.parent;
|
|
29
|
+
while (current !== null && current !== undefined) {
|
|
30
|
+
if (current.type === "ArrowFunctionExpression" ||
|
|
31
|
+
current.type === "FunctionExpression") {
|
|
32
|
+
return (isBroadEffectCatchCall(current.parent) &&
|
|
33
|
+
current.parent.arguments.includes(current));
|
|
34
|
+
}
|
|
35
|
+
current = current.parent;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
};
|
|
39
|
+
export const isReasonTagMember = (node) => node.object.type === "MemberExpression" &&
|
|
40
|
+
((!node.object.computed &&
|
|
41
|
+
node.object.property.type === "Identifier" &&
|
|
42
|
+
node.object.property.name === "reason") ||
|
|
43
|
+
(node.object.computed &&
|
|
44
|
+
isStringLiteral(node.object.property) &&
|
|
45
|
+
node.object.property.value === "reason"));
|
|
46
|
+
export const propertyName = (property) => {
|
|
47
|
+
if (!property.computed && property.key.type === "Identifier") {
|
|
48
|
+
return property.key.name;
|
|
49
|
+
}
|
|
50
|
+
if (property.key.type === "Literal" &&
|
|
51
|
+
typeof property.key.value === "string") {
|
|
52
|
+
return property.key.value;
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
};
|
|
56
|
+
export const isMatchPatternObject = (node) => {
|
|
57
|
+
const call = node.parent;
|
|
58
|
+
if (call?.type !== "CallExpression" || !call.arguments.includes(node)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
const callee = call.callee;
|
|
62
|
+
return (callee.type === "MemberExpression" &&
|
|
63
|
+
callee.object.type === "Identifier" &&
|
|
64
|
+
callee.object.name === "Match" &&
|
|
65
|
+
!callee.computed &&
|
|
66
|
+
callee.property.type === "Identifier" &&
|
|
67
|
+
(callee.property.name === "when" || callee.property.name === "not"));
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=tagged-values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tagged-values.js","sourceRoot":"","sources":["../../../../../src/vendor/anti-slop/effect/shared/tagged-values.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/vendor/anti-slop/index.ts"],"names":[],"mappings":"AAqBA,4FAA4F;AAC5F,QAAA,MAAM,cAAc,kCAsBlB,CAAC;eAEY,cAAc"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { eslintCompatPlugin } from "@oxlint/plugins";
|
|
2
|
+
import { noArrayFilterMapRule } from "./rules/no-array-filter-map.js";
|
|
3
|
+
import { noReduceAccumulatorCopyRule } from "./rules/no-reduce-accumulator-copy.js";
|
|
4
|
+
import { noChainedTypeAssertionsRule } from "./rules/no-chained-type-assertions.js";
|
|
5
|
+
import { noConditionalEmptyObjectSpreadRule } from "./rules/no-conditional-empty-object-spread.js";
|
|
6
|
+
import { noKnownValueWideningRule } from "./rules/no-known-value-widening.js";
|
|
7
|
+
import { noModuleMockingRule } from "./rules/no-module-mocking.js";
|
|
8
|
+
import { noObjectParametersRule } from "./rules/no-object-parameters.js";
|
|
9
|
+
import { noReflectApplyRule } from "./rules/no-reflect-apply.js";
|
|
10
|
+
import { noReflectGetRule } from "./rules/no-reflect-get.js";
|
|
11
|
+
import { noRuntimeTypeofRule } from "./rules/no-runtime-typeof.js";
|
|
12
|
+
import { noForbiddenTermInSymbolNamesRule } from "./rules/no-shape-in-symbol-names.js";
|
|
13
|
+
import { noUnknownParametersRule } from "./rules/no-unknown-parameters.js";
|
|
14
|
+
import { noUnknownReturnsRule } from "./rules/no-unknown-returns.js";
|
|
15
|
+
import { noUnknownTypeAliasesRule } from "./rules/no-unknown-type-aliases.js";
|
|
16
|
+
import { noUnsafeDictionaryTypeRule } from "./rules/no-unsafe-dictionary-type.js";
|
|
17
|
+
import { noWidenThenAssertRule } from "./rules/no-widen-then-assert.js";
|
|
18
|
+
import { requireReadableSpacingRule } from "./rules/require-readable-spacing.js";
|
|
19
|
+
import { requireSafetyCommentForTypeAssertionRule } from "./rules/require-safety-comment-for-type-assertion.js";
|
|
20
|
+
/** Generic Oxlint rules that reject low-evidence and low-signal implementation patterns. */
|
|
21
|
+
const antiSlopPlugin = eslintCompatPlugin({
|
|
22
|
+
meta: { name: "anti-slop" },
|
|
23
|
+
rules: {
|
|
24
|
+
"no-array-filter-map": noArrayFilterMapRule,
|
|
25
|
+
"no-reduce-accumulator-copy": noReduceAccumulatorCopyRule,
|
|
26
|
+
"no-chained-type-assertions": noChainedTypeAssertionsRule,
|
|
27
|
+
"no-conditional-empty-object-spread": noConditionalEmptyObjectSpreadRule,
|
|
28
|
+
"no-known-value-widening": noKnownValueWideningRule,
|
|
29
|
+
"no-module-mocking": noModuleMockingRule,
|
|
30
|
+
"no-object-parameters": noObjectParametersRule,
|
|
31
|
+
"no-reflect-apply": noReflectApplyRule,
|
|
32
|
+
"no-reflect-get": noReflectGetRule,
|
|
33
|
+
"no-runtime-typeof": noRuntimeTypeofRule,
|
|
34
|
+
"no-unsafe-dictionary-type": noUnsafeDictionaryTypeRule,
|
|
35
|
+
"no-shape-in-symbol-names": noForbiddenTermInSymbolNamesRule,
|
|
36
|
+
"no-unknown-parameters": noUnknownParametersRule,
|
|
37
|
+
"no-unknown-returns": noUnknownReturnsRule,
|
|
38
|
+
"no-unknown-type-aliases": noUnknownTypeAliasesRule,
|
|
39
|
+
"no-widen-then-assert": noWidenThenAssertRule,
|
|
40
|
+
"require-readable-spacing": requireReadableSpacingRule,
|
|
41
|
+
"require-safety-comment-for-type-assertion": requireSafetyCommentForTypeAssertionRule,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
export default antiSlopPlugin;
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/vendor/anti-slop/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAC;AACpF,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAC;AACpF,OAAO,EAAE,kCAAkC,EAAE,MAAM,+CAA+C,CAAC;AACnG,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,gCAAgC,EAAE,MAAM,qCAAqC,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EAAE,wCAAwC,EAAE,MAAM,sDAAsD,CAAC;AAEhH,4FAA4F;AAC5F,MAAM,cAAc,GAAG,kBAAkB,CAAC;IACzC,IAAI,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;IAC3B,KAAK,EAAE;QACN,qBAAqB,EAAE,oBAAoB;QAC3C,4BAA4B,EAAE,2BAA2B;QACzD,4BAA4B,EAAE,2BAA2B;QACzD,oCAAoC,EAAE,kCAAkC;QACxE,yBAAyB,EAAE,wBAAwB;QACnD,mBAAmB,EAAE,mBAAmB;QACxC,sBAAsB,EAAE,sBAAsB;QAC9C,kBAAkB,EAAE,kBAAkB;QACtC,gBAAgB,EAAE,gBAAgB;QAClC,mBAAmB,EAAE,mBAAmB;QACxC,2BAA2B,EAAE,0BAA0B;QACvD,0BAA0B,EAAE,gCAAgC;QAC5D,uBAAuB,EAAE,uBAAuB;QAChD,oBAAoB,EAAE,oBAAoB;QAC1C,yBAAyB,EAAE,wBAAwB;QACnD,sBAAsB,EAAE,qBAAqB;QAC7C,0BAA0B,EAAE,0BAA0B;QACtD,2CAA2C,EAAE,wCAAwC;KACrF;CACD,CAAC,CAAC;AAEH,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-array-filter-map.d.ts","sourceRoot":"","sources":["../../../../src/vendor/anti-slop/rules/no-array-filter-map.ts"],"names":[],"mappings":"AAIA,qFAAqF;AACrF,eAAO,MAAM,oBAAoB,gCAsB/B,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import { arrayMethodTarget, isKnownArrayExpression, unwrapArrayExpression } from "../shared/array-method.js";
|
|
3
|
+
/** Reject eager array filter/map pipelines; lazy iterator helpers remain allowed. */
|
|
4
|
+
export const noArrayFilterMapRule = defineRule({
|
|
5
|
+
meta: {
|
|
6
|
+
type: "suggestion",
|
|
7
|
+
docs: { description: "Disallow adjacent array filter/map passes in favor of lazy iterator helpers or a single transformation." },
|
|
8
|
+
messages: {
|
|
9
|
+
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.",
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
createOnce(context) {
|
|
13
|
+
return {
|
|
14
|
+
CallExpression(node) {
|
|
15
|
+
const outer = arrayMethodTarget(node.callee);
|
|
16
|
+
if (outer === null || (outer.name !== "map" && outer.name !== "filter"))
|
|
17
|
+
return;
|
|
18
|
+
const innerCall = unwrapArrayExpression(outer.object);
|
|
19
|
+
if (innerCall.type !== "CallExpression")
|
|
20
|
+
return;
|
|
21
|
+
const inner = arrayMethodTarget(innerCall.callee);
|
|
22
|
+
if (inner === null || inner.name !== (outer.name === "map" ? "filter" : "map"))
|
|
23
|
+
return;
|
|
24
|
+
if (!isKnownArrayExpression(context.sourceCode, inner.object))
|
|
25
|
+
return;
|
|
26
|
+
context.report({ node, messageId: "arrayFilterMap", data: { first: inner.name, second: outer.name } });
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=no-array-filter-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-array-filter-map.js","sourceRoot":"","sources":["../../../../src/vendor/anti-slop/rules/no-array-filter-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAE7G,qFAAqF;AACrF,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC;IAC7C,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,EAAE,WAAW,EAAE,yGAAyG,EAAE;QAChI,QAAQ,EAAE;YACR,cAAc,EAAE,sQAAsQ;SACvR;KACF;IACD,UAAU,CAAC,OAAO;QAChB,OAAO;YACL,cAAc,CAAC,IAAI;gBACjB,MAAM,KAAK,GAAG,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBAC7C,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;oBAAE,OAAO;gBAChF,MAAM,SAAS,GAAG,qBAAqB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBACtD,IAAI,SAAS,CAAC,IAAI,KAAK,gBAAgB;oBAAE,OAAO;gBAChD,MAAM,KAAK,GAAG,iBAAiB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBAClD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;oBAAE,OAAO;gBACvF,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC;oBAAE,OAAO;gBACtE,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,gBAAgB,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACzG,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-chained-type-assertions.d.ts","sourceRoot":"","sources":["../../../../src/vendor/anti-slop/rules/no-chained-type-assertions.ts"],"names":[],"mappings":"AAoDA,yGAAyG;AACzG,eAAO,MAAM,2BAA2B,gCAuBtC,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
function isTypeAssertionExpression(node) {
|
|
3
|
+
return node.type === "TSAsExpression" || node.type === "TSTypeAssertion";
|
|
4
|
+
}
|
|
5
|
+
function unwrapParenthesizedExpression(expression) {
|
|
6
|
+
let current = expression;
|
|
7
|
+
while (current.type === "ParenthesizedExpression") {
|
|
8
|
+
current = current.expression;
|
|
9
|
+
}
|
|
10
|
+
return current;
|
|
11
|
+
}
|
|
12
|
+
function isConstAssertion(node) {
|
|
13
|
+
const { typeAnnotation } = node;
|
|
14
|
+
return (typeAnnotation.type === "TSTypeReference" &&
|
|
15
|
+
typeAnnotation.typeName.type === "Identifier" &&
|
|
16
|
+
typeAnnotation.typeName.name === "const");
|
|
17
|
+
}
|
|
18
|
+
function isOutermostAssertionInChain(node) {
|
|
19
|
+
let current = node;
|
|
20
|
+
let parent = node.parent;
|
|
21
|
+
while (parent.type === "ParenthesizedExpression" && parent.expression === current) {
|
|
22
|
+
current = parent;
|
|
23
|
+
parent = parent.parent;
|
|
24
|
+
}
|
|
25
|
+
return !isTypeAssertionExpression(parent) || parent.expression !== current;
|
|
26
|
+
}
|
|
27
|
+
function isForbiddenAssertionChain(node) {
|
|
28
|
+
let assertionCount = 0;
|
|
29
|
+
let hasNonConstAssertion = false;
|
|
30
|
+
let current = node;
|
|
31
|
+
while (isTypeAssertionExpression(current)) {
|
|
32
|
+
assertionCount += 1;
|
|
33
|
+
hasNonConstAssertion ||= !isConstAssertion(current);
|
|
34
|
+
current = unwrapParenthesizedExpression(current.expression);
|
|
35
|
+
}
|
|
36
|
+
return assertionCount > 1 && hasNonConstAssertion;
|
|
37
|
+
}
|
|
38
|
+
/** Disallow nested TypeScript type assertions, while permitting chains made only of const assertions. */
|
|
39
|
+
export const noChainedTypeAssertionsRule = defineRule({
|
|
40
|
+
meta: {
|
|
41
|
+
type: "problem",
|
|
42
|
+
docs: {
|
|
43
|
+
description: "Disallow chained TypeScript as and angle-bracket assertions, including parenthesized chains.",
|
|
44
|
+
},
|
|
45
|
+
messages: {
|
|
46
|
+
chained: "This assertion chain discards type evidence. Keep the original precise type, or parse untrusted input at its boundary before narrowing it.",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
createOnce(context) {
|
|
50
|
+
const checkTypeAssertion = (node) => {
|
|
51
|
+
if (!isOutermostAssertionInChain(node) || !isForbiddenAssertionChain(node))
|
|
52
|
+
return;
|
|
53
|
+
context.report({ node, messageId: "chained" });
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
TSAsExpression: checkTypeAssertion,
|
|
57
|
+
TSTypeAssertion: checkTypeAssertion,
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=no-chained-type-assertions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-chained-type-assertions.js","sourceRoot":"","sources":["../../../../src/vendor/anti-slop/rules/no-chained-type-assertions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAK7C,SAAS,yBAAyB,CAAC,IAAiB;IAClD,OAAO,IAAI,CAAC,IAAI,KAAK,gBAAgB,IAAI,IAAI,CAAC,IAAI,KAAK,iBAAiB,CAAC;AAC3E,CAAC;AAED,SAAS,6BAA6B,CAAC,UAA6B;IAClE,IAAI,OAAO,GAAG,UAAU,CAAC;IACzB,OAAO,OAAO,CAAC,IAAI,KAAK,yBAAyB,EAAE,CAAC;QAClD,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC;IAC/B,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,gBAAgB,CAAC,IAA6B;IACrD,MAAM,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;IAChC,OAAO,CACL,cAAc,CAAC,IAAI,KAAK,iBAAiB;QACzC,cAAc,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY;QAC7C,cAAc,CAAC,QAAQ,CAAC,IAAI,KAAK,OAAO,CACzC,CAAC;AACJ,CAAC;AAED,SAAS,2BAA2B,CAAC,IAA6B;IAChE,IAAI,OAAO,GAAsB,IAAI,CAAC;IACtC,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAEzB,OAAO,MAAM,CAAC,IAAI,KAAK,yBAAyB,IAAI,MAAM,CAAC,UAAU,KAAK,OAAO,EAAE,CAAC;QAClF,OAAO,GAAG,MAAM,CAAC;QACjB,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IACzB,CAAC;IAED,OAAO,CAAC,yBAAyB,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,UAAU,KAAK,OAAO,CAAC;AAC7E,CAAC;AAED,SAAS,yBAAyB,CAAC,IAA6B;IAC9D,IAAI,cAAc,GAAG,CAAC,CAAC;IACvB,IAAI,oBAAoB,GAAG,KAAK,CAAC;IACjC,IAAI,OAAO,GAAsB,IAAI,CAAC;IAEtC,OAAO,yBAAyB,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1C,cAAc,IAAI,CAAC,CAAC;QACpB,oBAAoB,KAAK,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QACpD,OAAO,GAAG,6BAA6B,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,cAAc,GAAG,CAAC,IAAI,oBAAoB,CAAC;AACpD,CAAC;AAED,yGAAyG;AACzG,MAAM,CAAC,MAAM,2BAA2B,GAAG,UAAU,CAAC;IACpD,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EACT,8FAA8F;SACjG;QACD,QAAQ,EAAE;YACR,OAAO,EACL,4IAA4I;SAC/I;KACF;IACD,UAAU,CAAC,OAAO;QAChB,MAAM,kBAAkB,GAAG,CAAC,IAA6B,EAAE,EAAE;YAC3D,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC;gBAAE,OAAO;YACnF,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;QACjD,CAAC,CAAC;QAEF,OAAO;YACL,cAAc,EAAE,kBAAkB;YAClC,eAAe,EAAE,kBAAkB;SACpC,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-conditional-empty-object-spread.d.ts","sourceRoot":"","sources":["../../../../src/vendor/anti-slop/rules/no-conditional-empty-object-spread.ts"],"names":[],"mappings":"AAwBA,sFAAsF;AACtF,eAAO,MAAM,kCAAkC,gCAuB7C,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
function unwrapParentheses(node) {
|
|
3
|
+
let current = node;
|
|
4
|
+
while (current.type === "ParenthesizedExpression") {
|
|
5
|
+
current = current.expression;
|
|
6
|
+
}
|
|
7
|
+
return current;
|
|
8
|
+
}
|
|
9
|
+
function isEmptyObjectExpression(node) {
|
|
10
|
+
return node.type === "ObjectExpression" && node.properties.length === 0;
|
|
11
|
+
}
|
|
12
|
+
function isConditionalEmptyObjectSpread(node) {
|
|
13
|
+
const conditional = unwrapParentheses(node);
|
|
14
|
+
return (conditional.type === "ConditionalExpression" &&
|
|
15
|
+
(isEmptyObjectExpression(conditional.consequent) ||
|
|
16
|
+
isEmptyObjectExpression(conditional.alternate)));
|
|
17
|
+
}
|
|
18
|
+
/** Ban conditional empty-object spreads without changing their omission semantics. */
|
|
19
|
+
export const noConditionalEmptyObjectSpreadRule = defineRule({
|
|
20
|
+
meta: {
|
|
21
|
+
type: "suggestion",
|
|
22
|
+
docs: {
|
|
23
|
+
description: "Disallow object spreads that conditionally spread an empty object to omit fields.",
|
|
24
|
+
},
|
|
25
|
+
messages: {
|
|
26
|
+
avoid: "This conditional spread hides property omission behind an empty object. Build the object in separate statements and add the property only when present.",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
createOnce(context) {
|
|
30
|
+
return {
|
|
31
|
+
SpreadElement(node) {
|
|
32
|
+
if (node.parent.type !== "ObjectExpression")
|
|
33
|
+
return;
|
|
34
|
+
if (isConditionalEmptyObjectSpread(node.argument)) {
|
|
35
|
+
context.report({ node, messageId: "avoid" });
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=no-conditional-empty-object-spread.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-conditional-empty-object-spread.js","sourceRoot":"","sources":["../../../../src/vendor/anti-slop/rules/no-conditional-empty-object-spread.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,SAAS,iBAAiB,CAAC,IAAuB;IAChD,IAAI,OAAO,GAAG,IAAI,CAAC;IACnB,OAAO,OAAO,CAAC,IAAI,KAAK,yBAAyB,EAAE,CAAC;QAClD,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC;IAC/B,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,uBAAuB,CAAC,IAAuB;IACtD,OAAO,IAAI,CAAC,IAAI,KAAK,kBAAkB,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC;AAC1E,CAAC;AAED,SAAS,8BAA8B,CAAC,IAAuB;IAC7D,MAAM,WAAW,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC5C,OAAO,CACL,WAAW,CAAC,IAAI,KAAK,uBAAuB;QAC5C,CAAC,uBAAuB,CAAC,WAAW,CAAC,UAAU,CAAC;YAC9C,uBAAuB,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAClD,CAAC;AACJ,CAAC;AAED,sFAAsF;AACtF,MAAM,CAAC,MAAM,kCAAkC,GAAG,UAAU,CAAC;IAC3D,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EACT,mFAAmF;SACtF;QACD,QAAQ,EAAE;YACR,KAAK,EACH,yJAAyJ;SAC5J;KACF;IACD,UAAU,CAAC,OAAO;QAChB,OAAO;YACL,aAAa,CAAC,IAAI;gBAChB,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,kBAAkB;oBAAE,OAAO;gBAEpD,IAAI,8BAA8B,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAClD,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;gBAC/C,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-known-value-widening.d.ts","sourceRoot":"","sources":["../../../../src/vendor/anti-slop/rules/no-known-value-widening.ts"],"names":[],"mappings":"AAoQA,iGAAiG;AACjG,eAAO,MAAM,wBAAwB,gCAyJnC,CAAC"}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import { classifyUnsafeDictionaryValue, classifyWideningTarget, createTypeEnvironment, isKnownEvidenceExpression, } from "../shared/dictionary-types.js";
|
|
3
|
+
import { containsUnknownType, functionParameterBindingName, functionParameterTypeAnnotation, } from "../shared/function-parameters.js";
|
|
4
|
+
import { resolveVariable } from "../shared/scope.js";
|
|
5
|
+
function unwrapExpression(expression) {
|
|
6
|
+
let current = expression;
|
|
7
|
+
while (current.type === "ParenthesizedExpression" ||
|
|
8
|
+
current.type === "TSAsExpression" ||
|
|
9
|
+
current.type === "TSSatisfiesExpression" ||
|
|
10
|
+
current.type === "TSTypeAssertion" ||
|
|
11
|
+
current.type === "TSNonNullExpression") {
|
|
12
|
+
current = current.expression;
|
|
13
|
+
}
|
|
14
|
+
return current;
|
|
15
|
+
}
|
|
16
|
+
function variableDeclarator(variable) {
|
|
17
|
+
if (variable.defs.length !== 1)
|
|
18
|
+
return null;
|
|
19
|
+
const [definition] = variable.defs;
|
|
20
|
+
return definition?.type === "Variable" && definition.node.type === "VariableDeclarator"
|
|
21
|
+
? definition.node
|
|
22
|
+
: null;
|
|
23
|
+
}
|
|
24
|
+
function isStableConstVariable(variable, declarator) {
|
|
25
|
+
return (declarator.parent.type === "VariableDeclaration" &&
|
|
26
|
+
declarator.parent.kind === "const" &&
|
|
27
|
+
variable.references.every((reference) => reference.init || !reference.isWrite()));
|
|
28
|
+
}
|
|
29
|
+
function hasKnownEvidence(sourceCode, expression, visitedVariables = new Set()) {
|
|
30
|
+
if (isKnownEvidenceExpression(expression))
|
|
31
|
+
return true;
|
|
32
|
+
const unwrapped = unwrapExpression(expression);
|
|
33
|
+
if (unwrapped.type !== "Identifier")
|
|
34
|
+
return false;
|
|
35
|
+
const variable = resolveVariable(sourceCode, unwrapped);
|
|
36
|
+
if (variable === null || visitedVariables.has(variable))
|
|
37
|
+
return false;
|
|
38
|
+
const declarator = variableDeclarator(variable);
|
|
39
|
+
if (declarator === null ||
|
|
40
|
+
declarator.init === null ||
|
|
41
|
+
!isStableConstVariable(variable, declarator)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
visitedVariables.add(variable);
|
|
45
|
+
return hasKnownEvidence(sourceCode, declarator.init, visitedVariables);
|
|
46
|
+
}
|
|
47
|
+
function isFunctionExpression(node) {
|
|
48
|
+
return (node.type === "ArrowFunctionExpression" ||
|
|
49
|
+
node.type === "FunctionDeclaration" ||
|
|
50
|
+
node.type === "FunctionExpression" ||
|
|
51
|
+
node.type === "TSDeclareFunction" ||
|
|
52
|
+
node.type === "TSEmptyBodyFunctionExpression");
|
|
53
|
+
}
|
|
54
|
+
function localFunctionForCall(sourceCode, callee) {
|
|
55
|
+
const unwrapped = unwrapExpression(callee);
|
|
56
|
+
if (isFunctionExpression(unwrapped))
|
|
57
|
+
return unwrapped;
|
|
58
|
+
if (unwrapped.type !== "Identifier")
|
|
59
|
+
return null;
|
|
60
|
+
const variable = resolveVariable(sourceCode, unwrapped);
|
|
61
|
+
if (variable === null || variable.defs.length !== 1)
|
|
62
|
+
return null;
|
|
63
|
+
const [definition] = variable.defs;
|
|
64
|
+
if (definition === undefined)
|
|
65
|
+
return null;
|
|
66
|
+
if (definition.type === "FunctionName" && isFunctionExpression(definition.node)) {
|
|
67
|
+
return definition.node;
|
|
68
|
+
}
|
|
69
|
+
if (definition.type !== "Variable" || definition.node.type !== "VariableDeclarator") {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const initializer = definition.node.init;
|
|
73
|
+
if (initializer === null)
|
|
74
|
+
return null;
|
|
75
|
+
const unwrappedInitializer = unwrapExpression(initializer);
|
|
76
|
+
return isFunctionExpression(unwrappedInitializer) ? unwrappedInitializer : null;
|
|
77
|
+
}
|
|
78
|
+
function variableTypeAnnotation(sourceCode, variable) {
|
|
79
|
+
if (variable.defs.length !== 1)
|
|
80
|
+
return null;
|
|
81
|
+
const [definition] = variable.defs;
|
|
82
|
+
if (definition === undefined)
|
|
83
|
+
return null;
|
|
84
|
+
if (definition.type === "Variable" &&
|
|
85
|
+
definition.node.type === "VariableDeclarator" &&
|
|
86
|
+
definition.node.id.type === "Identifier") {
|
|
87
|
+
return definition.node.id.typeAnnotation ?? null;
|
|
88
|
+
}
|
|
89
|
+
if (definition.type !== "Parameter" || !isFunctionExpression(definition.node)) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const parameter = definition.node.params.find((candidate) => functionParameterBindingName(candidate, sourceCode) === variable.name);
|
|
93
|
+
return parameter === undefined ? null : (functionParameterTypeAnnotation(parameter) ?? null);
|
|
94
|
+
}
|
|
95
|
+
function hasInformativeType(type, environment) {
|
|
96
|
+
return classifyUnsafeDictionaryValue(type, environment) === null;
|
|
97
|
+
}
|
|
98
|
+
function hasKnownCallArgumentEvidence(sourceCode, expression, environment, visitedVariables = new Set()) {
|
|
99
|
+
if (expression.type === "ParenthesizedExpression" || expression.type === "TSNonNullExpression") {
|
|
100
|
+
return hasKnownCallArgumentEvidence(sourceCode, expression.expression, environment, visitedVariables);
|
|
101
|
+
}
|
|
102
|
+
if (expression.type === "TSAsExpression" || expression.type === "TSTypeAssertion") {
|
|
103
|
+
return hasInformativeType(expression.typeAnnotation, environment);
|
|
104
|
+
}
|
|
105
|
+
if (expression.type === "TSSatisfiesExpression") {
|
|
106
|
+
return hasKnownCallArgumentEvidence(sourceCode, expression.expression, environment, visitedVariables);
|
|
107
|
+
}
|
|
108
|
+
if (expression.type === "CallExpression") {
|
|
109
|
+
const owner = localFunctionForCall(sourceCode, expression.callee);
|
|
110
|
+
const returnType = owner?.returnType?.typeAnnotation;
|
|
111
|
+
return returnType !== undefined && hasInformativeType(returnType, environment);
|
|
112
|
+
}
|
|
113
|
+
if (expression.type !== "Identifier")
|
|
114
|
+
return isKnownEvidenceExpression(expression);
|
|
115
|
+
const variable = resolveVariable(sourceCode, expression);
|
|
116
|
+
if (variable === null || visitedVariables.has(variable))
|
|
117
|
+
return false;
|
|
118
|
+
const annotation = variableTypeAnnotation(sourceCode, variable);
|
|
119
|
+
if (annotation !== null) {
|
|
120
|
+
return hasInformativeType(annotation.typeAnnotation, environment);
|
|
121
|
+
}
|
|
122
|
+
const declarator = variableDeclarator(variable);
|
|
123
|
+
if (declarator === null ||
|
|
124
|
+
declarator.init === null ||
|
|
125
|
+
!isStableConstVariable(variable, declarator)) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
visitedVariables.add(variable);
|
|
129
|
+
return hasKnownCallArgumentEvidence(sourceCode, declarator.init, environment, visitedVariables);
|
|
130
|
+
}
|
|
131
|
+
function typePredicateSubjectIndex(sourceCode, owner) {
|
|
132
|
+
const predicate = owner.returnType?.typeAnnotation;
|
|
133
|
+
if (predicate?.type !== "TSTypePredicate" || predicate.parameterName.type !== "Identifier") {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
const predicateParameterName = predicate.parameterName.name;
|
|
137
|
+
const index = owner.params.findIndex((parameter) => functionParameterBindingName(parameter, sourceCode) === predicateParameterName);
|
|
138
|
+
return index === -1 ? null : index;
|
|
139
|
+
}
|
|
140
|
+
function annotationTarget(annotation, environment) {
|
|
141
|
+
return annotation === null || annotation === undefined
|
|
142
|
+
? null
|
|
143
|
+
: classifyWideningTarget(annotation.typeAnnotation, environment);
|
|
144
|
+
}
|
|
145
|
+
function enclosingFunction(node) {
|
|
146
|
+
let current = node.parent;
|
|
147
|
+
while (current !== null && current.type !== "Program") {
|
|
148
|
+
if (current.type === "ArrowFunctionExpression" ||
|
|
149
|
+
current.type === "FunctionDeclaration" ||
|
|
150
|
+
current.type === "FunctionExpression") {
|
|
151
|
+
return current;
|
|
152
|
+
}
|
|
153
|
+
current = current.parent;
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
function sourceKeyName(sourceCode, key) {
|
|
158
|
+
if (key.type === "Identifier" || key.type === "PrivateIdentifier")
|
|
159
|
+
return key.name;
|
|
160
|
+
if (key.type === "Literal")
|
|
161
|
+
return String(key.value);
|
|
162
|
+
return sourceCode.getText(key);
|
|
163
|
+
}
|
|
164
|
+
function functionName(sourceCode, owner) {
|
|
165
|
+
if (owner === null)
|
|
166
|
+
return "anonymous function";
|
|
167
|
+
if (owner.id !== null)
|
|
168
|
+
return owner.id.name;
|
|
169
|
+
const parent = owner.parent;
|
|
170
|
+
if (parent.type === "VariableDeclarator" && parent.id.type === "Identifier")
|
|
171
|
+
return parent.id.name;
|
|
172
|
+
if (parent.type === "MethodDefinition")
|
|
173
|
+
return sourceKeyName(sourceCode, parent.key);
|
|
174
|
+
return "anonymous function";
|
|
175
|
+
}
|
|
176
|
+
function isEmptyObjectExpression(expression) {
|
|
177
|
+
const unwrapped = unwrapExpression(expression);
|
|
178
|
+
return unwrapped.type === "ObjectExpression" && unwrapped.properties.length === 0;
|
|
179
|
+
}
|
|
180
|
+
function isDictionaryAccumulatorTarget(destination) {
|
|
181
|
+
return destination.kind === "open dictionary" || destination.kind === "generic container";
|
|
182
|
+
}
|
|
183
|
+
function hasParentAssertion(node) {
|
|
184
|
+
return node.parent?.type === "TSAsExpression" || node.parent?.type === "TSTypeAssertion";
|
|
185
|
+
}
|
|
186
|
+
/** Detect sound syntactic cases where a known value is explicitly widened and loses evidence. */
|
|
187
|
+
export const noKnownValueWideningRule = defineRule({
|
|
188
|
+
meta: {
|
|
189
|
+
type: "problem",
|
|
190
|
+
docs: {
|
|
191
|
+
description: "Disallow syntactically established values from flowing into explicitly broad or anonymous target types that discard useful evidence.",
|
|
192
|
+
},
|
|
193
|
+
messages: {
|
|
194
|
+
widening: "The explicit {{target}} type on {{subject}} discards known type evidence. Keep inference, validate with `satisfies`, or use a named owner contract.",
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
createOnce(context) {
|
|
198
|
+
let environment = null;
|
|
199
|
+
const reportFlow = (expression, destination, subject) => {
|
|
200
|
+
if (destination === null)
|
|
201
|
+
return;
|
|
202
|
+
if (isDictionaryAccumulatorTarget(destination) &&
|
|
203
|
+
isEmptyObjectExpression(expression)) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (!hasKnownEvidence(context.sourceCode, expression))
|
|
207
|
+
return;
|
|
208
|
+
context.report({
|
|
209
|
+
node: expression,
|
|
210
|
+
messageId: "widening",
|
|
211
|
+
data: { subject, target: destination.kind },
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
const targetFromAnnotation = (annotation) => environment === null ? null : annotationTarget(annotation, environment);
|
|
215
|
+
return {
|
|
216
|
+
Program(node) {
|
|
217
|
+
environment = createTypeEnvironment(node, context.sourceCode.visitorKeys);
|
|
218
|
+
},
|
|
219
|
+
VariableDeclarator(node) {
|
|
220
|
+
if (node.init === null || node.id.type !== "Identifier")
|
|
221
|
+
return;
|
|
222
|
+
reportFlow(node.init, targetFromAnnotation(node.id.typeAnnotation), `binding \`${node.id.name}\``);
|
|
223
|
+
},
|
|
224
|
+
PropertyDefinition(node) {
|
|
225
|
+
if (node.value === null)
|
|
226
|
+
return;
|
|
227
|
+
reportFlow(node.value, targetFromAnnotation(node.typeAnnotation), `property \`${sourceKeyName(context.sourceCode, node.key)}\``);
|
|
228
|
+
},
|
|
229
|
+
AccessorProperty(node) {
|
|
230
|
+
if (node.value === null)
|
|
231
|
+
return;
|
|
232
|
+
reportFlow(node.value, targetFromAnnotation(node.typeAnnotation), `property \`${sourceKeyName(context.sourceCode, node.key)}\``);
|
|
233
|
+
},
|
|
234
|
+
AssignmentExpression(node) {
|
|
235
|
+
if (node.operator !== "=" || node.left.type !== "Identifier")
|
|
236
|
+
return;
|
|
237
|
+
const variable = resolveVariable(context.sourceCode, node.left);
|
|
238
|
+
if (variable === null)
|
|
239
|
+
return;
|
|
240
|
+
const declarator = variableDeclarator(variable);
|
|
241
|
+
if (declarator === null || declarator.id.type !== "Identifier")
|
|
242
|
+
return;
|
|
243
|
+
reportFlow(node.right, targetFromAnnotation(declarator.id.typeAnnotation), `binding \`${declarator.id.name}\``);
|
|
244
|
+
},
|
|
245
|
+
CallExpression(node) {
|
|
246
|
+
if (environment === null)
|
|
247
|
+
return;
|
|
248
|
+
const owner = localFunctionForCall(context.sourceCode, node.callee);
|
|
249
|
+
if (owner === null)
|
|
250
|
+
return;
|
|
251
|
+
const parameterIndex = typePredicateSubjectIndex(context.sourceCode, owner);
|
|
252
|
+
if (parameterIndex === null)
|
|
253
|
+
return;
|
|
254
|
+
const parameter = owner.params[parameterIndex];
|
|
255
|
+
const argument = node.arguments[parameterIndex];
|
|
256
|
+
if (parameter === undefined || argument === undefined || argument.type === "SpreadElement") {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const parameterAnnotation = functionParameterTypeAnnotation(parameter);
|
|
260
|
+
if (parameterAnnotation === null ||
|
|
261
|
+
parameterAnnotation === undefined ||
|
|
262
|
+
!containsUnknownType(parameterAnnotation.typeAnnotation)) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (!hasKnownCallArgumentEvidence(context.sourceCode, argument, environment)) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
context.report({
|
|
269
|
+
node: argument,
|
|
270
|
+
messageId: "widening",
|
|
271
|
+
data: {
|
|
272
|
+
subject: `argument for parameter \`${functionParameterBindingName(parameter, context.sourceCode)}\` of \`${functionName(context.sourceCode, owner)}\``,
|
|
273
|
+
target: "unknown",
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
},
|
|
277
|
+
ReturnStatement(node) {
|
|
278
|
+
if (node.argument === null)
|
|
279
|
+
return;
|
|
280
|
+
const owner = enclosingFunction(node);
|
|
281
|
+
reportFlow(node.argument, targetFromAnnotation(owner?.returnType), `return value of \`${functionName(context.sourceCode, owner)}\``);
|
|
282
|
+
},
|
|
283
|
+
ArrowFunctionExpression(node) {
|
|
284
|
+
if (node.body.type === "BlockStatement")
|
|
285
|
+
return;
|
|
286
|
+
reportFlow(node.body, targetFromAnnotation(node.returnType), `return value of \`${functionName(context.sourceCode, node)}\``);
|
|
287
|
+
},
|
|
288
|
+
TSAsExpression(node) {
|
|
289
|
+
if (environment === null || hasParentAssertion(node))
|
|
290
|
+
return;
|
|
291
|
+
reportFlow(node.expression, classifyWideningTarget(node.typeAnnotation, environment), "assertion");
|
|
292
|
+
},
|
|
293
|
+
TSTypeAssertion(node) {
|
|
294
|
+
if (environment === null || hasParentAssertion(node))
|
|
295
|
+
return;
|
|
296
|
+
reportFlow(node.expression, classifyWideningTarget(node.typeAnnotation, environment), "assertion");
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
},
|
|
300
|
+
});
|
|
301
|
+
//# sourceMappingURL=no-known-value-widening.js.map
|