@rc312/oxlint-rules 0.0.0-stage → 0.1.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 +43 -2
- package/dist/anti-slop/effect/index.d.ts +3 -0
- package/dist/anti-slop/effect/index.js +18 -0
- package/dist/anti-slop/effect/rules/no-manual-effect-error-tag.d.ts +1 -0
- package/dist/anti-slop/effect/rules/no-manual-effect-error-tag.js +39 -0
- package/dist/anti-slop/effect/rules/no-manual-tag-comparison.d.ts +1 -0
- package/dist/anti-slop/effect/rules/no-manual-tag-comparison.js +32 -0
- package/dist/anti-slop/effect/rules/no-manual-tagged-construction.d.ts +1 -0
- package/dist/anti-slop/effect/rules/no-manual-tagged-construction.js +27 -0
- package/dist/anti-slop/effect/rules/no-service-constructor-imports.d.ts +2 -0
- package/dist/anti-slop/effect/rules/no-service-constructor-imports.js +44 -0
- package/dist/anti-slop/effect/rules/prefer-effect-match.d.ts +1 -0
- package/dist/anti-slop/effect/rules/prefer-effect-match.js +48 -0
- package/dist/anti-slop/effect/shared/tagged-values.d.ts +8 -0
- package/dist/anti-slop/effect/shared/tagged-values.js +68 -0
- package/dist/anti-slop/index.d.ts +3 -0
- package/dist/anti-slop/index.js +44 -0
- package/dist/anti-slop/rules/no-array-filter-map.d.ts +2 -0
- package/dist/anti-slop/rules/no-array-filter-map.js +30 -0
- package/dist/anti-slop/rules/no-chained-type-assertions.d.ts +2 -0
- package/dist/anti-slop/rules/no-chained-type-assertions.js +60 -0
- package/dist/anti-slop/rules/no-conditional-empty-object-spread.d.ts +2 -0
- package/dist/anti-slop/rules/no-conditional-empty-object-spread.js +40 -0
- package/dist/anti-slop/rules/no-known-value-widening.d.ts +2 -0
- package/dist/anti-slop/rules/no-known-value-widening.js +300 -0
- package/dist/anti-slop/rules/no-module-mocking.d.ts +2 -0
- package/dist/anti-slop/rules/no-module-mocking.js +69 -0
- package/dist/anti-slop/rules/no-object-parameters.d.ts +2 -0
- package/dist/anti-slop/rules/no-object-parameters.js +56 -0
- package/dist/anti-slop/rules/no-reduce-accumulator-copy.d.ts +2 -0
- package/dist/anti-slop/rules/no-reduce-accumulator-copy.js +99 -0
- package/dist/anti-slop/rules/no-reflect-apply.d.ts +2 -0
- package/dist/anti-slop/rules/no-reflect-apply.js +25 -0
- package/dist/anti-slop/rules/no-reflect-get.d.ts +2 -0
- package/dist/anti-slop/rules/no-reflect-get.js +25 -0
- package/dist/anti-slop/rules/no-runtime-typeof.d.ts +2 -0
- package/dist/anti-slop/rules/no-runtime-typeof.js +64 -0
- package/dist/anti-slop/rules/no-shape-in-symbol-names.d.ts +2 -0
- package/dist/anti-slop/rules/no-shape-in-symbol-names.js +40 -0
- package/dist/anti-slop/rules/no-unknown-parameters.d.ts +2 -0
- package/dist/anti-slop/rules/no-unknown-parameters.js +51 -0
- package/dist/anti-slop/rules/no-unknown-returns.d.ts +2 -0
- package/dist/anti-slop/rules/no-unknown-returns.js +58 -0
- package/dist/anti-slop/rules/no-unknown-type-aliases.d.ts +2 -0
- package/dist/anti-slop/rules/no-unknown-type-aliases.js +40 -0
- package/dist/anti-slop/rules/no-unsafe-dictionary-type.d.ts +2 -0
- package/dist/anti-slop/rules/no-unsafe-dictionary-type.js +134 -0
- package/dist/anti-slop/rules/no-widen-then-assert.d.ts +2 -0
- package/dist/anti-slop/rules/no-widen-then-assert.js +270 -0
- package/dist/anti-slop/rules/require-readable-spacing.d.ts +3 -0
- package/dist/anti-slop/rules/require-readable-spacing.js +65 -0
- package/dist/anti-slop/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
- package/dist/anti-slop/rules/require-safety-comment-for-type-assertion.js +100 -0
- package/dist/anti-slop/shared/array-method.d.ts +12 -0
- package/dist/anti-slop/shared/array-method.js +84 -0
- package/dist/anti-slop/shared/dictionary-types.d.ts +20 -0
- package/dist/anti-slop/shared/dictionary-types.js +377 -0
- package/dist/anti-slop/shared/function-parameters.d.ts +8 -0
- package/dist/anti-slop/shared/function-parameters.js +40 -0
- package/dist/anti-slop/shared/lexical-type-parameters.d.ts +5 -0
- package/dist/anti-slop/shared/lexical-type-parameters.js +47 -0
- package/dist/anti-slop/shared/reflect-method.d.ts +3 -0
- package/dist/anti-slop/shared/reflect-method.js +20 -0
- package/dist/anti-slop/shared/scope.d.ts +3 -0
- package/dist/anti-slop/shared/scope.js +11 -0
- package/dist/anti-slop/shared/type-alias-resolution.d.ts +23 -0
- package/dist/anti-slop/shared/type-alias-resolution.js +162 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-ast.d.ts +27 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-ast.js +28 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.d.ts +37 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.js +703 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-options.d.ts +16 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-options.js +2 -0
- package/dist/configs/base.d.ts +28 -0
- package/dist/configs/base.js +27 -0
- package/dist/configs/effect-starter.d.ts +10 -0
- package/dist/configs/effect-starter.js +10 -0
- package/dist/configs/effect.d.ts +14 -0
- package/dist/configs/effect.js +16 -0
- package/dist/effect-starter.d.ts +3 -0
- package/dist/effect-starter.js +40 -0
- package/package.json +46 -4
- package/src/anti-slop/LICENSE +21 -0
- package/src/anti-slop/UPSTREAM.md +14 -0
- package/src/anti-slop/vendor/eslint-stylistic/LICENSE +22 -0
- package/src/anti-slop/vendor/eslint-stylistic/UPSTREAM.md +28 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ryan Callahan
|
|
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/README.md
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
-
#
|
|
1
|
+
# oxlint-rules
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Versioned Oxlint rules for Ryan Callahan’s repositories. The package exports three shareable configs and their underlying plugins.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Use Node 22.19 or newer. Install the package from npm.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
bun add -D @rc312/oxlint-rules
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`npm install -D @rc312/oxlint-rules` also works. The package declares the compatible Oxlint version as a peer dependency. This release uses Oxlint 1.88.0.
|
|
14
|
+
|
|
15
|
+
## Configure
|
|
16
|
+
|
|
17
|
+
In `oxlint.config.ts`, extend the base config and add the configs you want. With another shared config such as Ultracite, put that config first and add these after it.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import base from "@rc312/oxlint-rules";
|
|
21
|
+
import effect from "@rc312/oxlint-rules/configs/effect";
|
|
22
|
+
import effectStarter from "@rc312/oxlint-rules/configs/effect-starter";
|
|
23
|
+
import { defineConfig } from "oxlint";
|
|
24
|
+
|
|
25
|
+
export default defineConfig({
|
|
26
|
+
extends: [base, effect, effectStarter],
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
| Config | Rules enabled at `error` |
|
|
31
|
+
| --- | --- |
|
|
32
|
+
| `@rc312/oxlint-rules` | 18 code-quality and readability rules under `anti-slop/`, plus Oxlint’s built-in `oxc/no-accumulating-spread` |
|
|
33
|
+
| `@rc312/oxlint-rules/configs/effect` | Five rules for Effect code under `anti-slop-effect/` |
|
|
34
|
+
| `@rc312/oxlint-rules/configs/effect-starter` | `effect-starter/no-global-this-or-declare-module` |
|
|
35
|
+
|
|
36
|
+
To enable individual rules, register the package subpath for the plugin under `jsPlugins`. The subpaths are `/anti-slop`, `/anti-slop-effect`, and `/effect-starter`. The configs and plugins retain the rule IDs used in `effect-starter`.
|
|
37
|
+
|
|
38
|
+
## Release
|
|
39
|
+
|
|
40
|
+
Run `npm ci` and `npm test` on `main`. Use `npm version patch`, `npm version minor`, or `npm version major` to update the package and lockfile and create the matching Git tag. Run `npm publish` to build and publish to npm, then push `main` and the tag.
|
|
41
|
+
|
|
42
|
+
## Attribution
|
|
43
|
+
|
|
44
|
+
The rules were extracted from `effect-starter`. The package uses the MIT license and includes [anti-slop’s license](src/anti-slop/LICENSE), [upstream revision](src/anti-slop/UPSTREAM.md), and [ESLint Stylistic’s license](src/anti-slop/vendor/eslint-stylistic/LICENSE) for its spacing rule.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { eslintCompatPlugin } from "@oxlint/plugins";
|
|
2
|
+
import { noManualEffectErrorTagRule } from "./rules/no-manual-effect-error-tag.js";
|
|
3
|
+
import { noManualTagComparisonRule } from "./rules/no-manual-tag-comparison.js";
|
|
4
|
+
import { noManualTaggedConstructionRule } from "./rules/no-manual-tagged-construction.js";
|
|
5
|
+
import { noServiceConstructorImportsRule } from "./rules/no-service-constructor-imports.js";
|
|
6
|
+
import { preferEffectMatchRule } from "./rules/prefer-effect-match.js";
|
|
7
|
+
/** Opt-in Oxlint rules for Effect service and Layer architecture. */
|
|
8
|
+
const antiSlopEffectPlugin = eslintCompatPlugin({
|
|
9
|
+
meta: { name: "anti-slop-effect" },
|
|
10
|
+
rules: {
|
|
11
|
+
"no-manual-effect-error-tag": noManualEffectErrorTagRule,
|
|
12
|
+
"no-manual-tag-comparison": noManualTagComparisonRule,
|
|
13
|
+
"no-manual-tagged-construction": noManualTaggedConstructionRule,
|
|
14
|
+
"no-service-constructor-imports": noServiceConstructorImportsRule,
|
|
15
|
+
"prefer-effect-match": preferEffectMatchRule,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
export default antiSlopEffectPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const noManualEffectErrorTagRule: import("@oxlint/plugins").Rule;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import { isInsideBroadEffectHandler, isReasonTagMember, isTagMember, tagMemberFromComparison, } from "../shared/tagged-values.js";
|
|
3
|
+
export const noManualEffectErrorTagRule = defineRule({
|
|
4
|
+
meta: {
|
|
5
|
+
type: "problem",
|
|
6
|
+
docs: {
|
|
7
|
+
description: "Use Effect tagged error handlers instead of manually branching on `_tag` in a catch handler.",
|
|
8
|
+
},
|
|
9
|
+
messages: {
|
|
10
|
+
tag: "Use Effect.catchTag or Effect.catchTags instead of manually discriminating a tagged error in a broad Effect catch handler.",
|
|
11
|
+
reason: "Use Effect.catchReason or Effect.catchReasons instead of manually discriminating a tagged `reason` in a broad Effect catch handler.",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
createOnce(context) {
|
|
15
|
+
return {
|
|
16
|
+
BinaryExpression(node) {
|
|
17
|
+
const tagMember = tagMemberFromComparison(node);
|
|
18
|
+
if (tagMember === undefined ||
|
|
19
|
+
!isInsideBroadEffectHandler(node)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
context.report({
|
|
23
|
+
node,
|
|
24
|
+
messageId: isReasonTagMember(tagMember) ? "reason" : "tag",
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
SwitchStatement(node) {
|
|
28
|
+
if (!isTagMember(node.discriminant) ||
|
|
29
|
+
!isInsideBroadEffectHandler(node)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
context.report({
|
|
33
|
+
node,
|
|
34
|
+
messageId: isReasonTagMember(node.discriminant) ? "reason" : "tag",
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const noManualTagComparisonRule: import("@oxlint/plugins").Rule;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import { isInsideBroadEffectHandler, isTagMember, tagMemberFromComparison, } from "../shared/tagged-values.js";
|
|
3
|
+
export const noManualTagComparisonRule = defineRule({
|
|
4
|
+
meta: {
|
|
5
|
+
type: "problem",
|
|
6
|
+
docs: {
|
|
7
|
+
description: "Use Effect Match or Predicate helpers instead of manually branching on `_tag`.",
|
|
8
|
+
},
|
|
9
|
+
messages: {
|
|
10
|
+
manualComparison: "Use Match.tag/Match.tags for tagged-value branching, or Predicate.isTagged for a simple reusable predicate.",
|
|
11
|
+
manualSwitch: "Use Match.value(value).pipe(Match.tag/Match.tags/Match.tagsExhaustive) or the tagged enum `$match` helper instead of switching on `_tag`.",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
createOnce(context) {
|
|
15
|
+
return {
|
|
16
|
+
BinaryExpression(node) {
|
|
17
|
+
if (tagMemberFromComparison(node) === undefined ||
|
|
18
|
+
isInsideBroadEffectHandler(node)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
context.report({ node, messageId: "manualComparison" });
|
|
22
|
+
},
|
|
23
|
+
SwitchStatement(node) {
|
|
24
|
+
if (!isTagMember(node.discriminant) ||
|
|
25
|
+
isInsideBroadEffectHandler(node)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
context.report({ node, messageId: "manualSwitch" });
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const noManualTaggedConstructionRule: import("@oxlint/plugins").Rule;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import { isMatchPatternObject, isStringLiteral, propertyName, } from "../shared/tagged-values.js";
|
|
3
|
+
export const noManualTaggedConstructionRule = defineRule({
|
|
4
|
+
meta: {
|
|
5
|
+
type: "problem",
|
|
6
|
+
docs: {
|
|
7
|
+
description: "Construct tagged values with their existing Effect constructor instead of writing `_tag` manually.",
|
|
8
|
+
},
|
|
9
|
+
messages: {
|
|
10
|
+
manualConstruction: "Use the existing Schema tagged `.make`, tagged class/error constructor, or Data.taggedEnum variant constructor instead of writing a literal `_tag` object.",
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
createOnce(context) {
|
|
14
|
+
return {
|
|
15
|
+
ObjectExpression(node) {
|
|
16
|
+
if (isMatchPatternObject(node))
|
|
17
|
+
return;
|
|
18
|
+
const tag = node.properties.find((property) => property.type === "Property" &&
|
|
19
|
+
propertyName(property) === "_tag" &&
|
|
20
|
+
isStringLiteral(property.value));
|
|
21
|
+
if (tag !== undefined) {
|
|
22
|
+
context.report({ node: tag, messageId: "manualConstruction" });
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
const SERVICE_CONSTRUCTOR_NAME = /^make[A-Z]/u;
|
|
3
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
4
|
+
function isProjectLocalImport(source) {
|
|
5
|
+
return source.startsWith("./") || source.startsWith("../");
|
|
6
|
+
}
|
|
7
|
+
function getImportedName(specifier) {
|
|
8
|
+
if (specifier.imported.type === "Identifier")
|
|
9
|
+
return specifier.imported.name;
|
|
10
|
+
return specifier.imported.value;
|
|
11
|
+
}
|
|
12
|
+
/** Keep dependency-bearing Effect service constructors local to their owning capability modules. */
|
|
13
|
+
export const noServiceConstructorImportsRule = defineRule({
|
|
14
|
+
meta: {
|
|
15
|
+
type: "problem",
|
|
16
|
+
docs: {
|
|
17
|
+
description: "Disallow project-local make<CapabilityName> imports outside test and spec files.",
|
|
18
|
+
},
|
|
19
|
+
messages: {
|
|
20
|
+
serviceConstructorImport: '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.',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
create(context) {
|
|
24
|
+
const isTestFile = TEST_FILE.test(context.filename.replaceAll("\\", "/"));
|
|
25
|
+
return {
|
|
26
|
+
ImportDeclaration(node) {
|
|
27
|
+
if (isTestFile || !isProjectLocalImport(node.source.value))
|
|
28
|
+
return;
|
|
29
|
+
for (const specifier of node.specifiers) {
|
|
30
|
+
if (specifier.type !== "ImportSpecifier")
|
|
31
|
+
continue;
|
|
32
|
+
const importedName = getImportedName(specifier);
|
|
33
|
+
if (!SERVICE_CONSTRUCTOR_NAME.test(importedName))
|
|
34
|
+
continue;
|
|
35
|
+
context.report({
|
|
36
|
+
node: specifier,
|
|
37
|
+
messageId: "serviceConstructorImport",
|
|
38
|
+
data: { name: importedName },
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const preferEffectMatchRule: import("@oxlint/plugins").Rule;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
const equalityOperators = new Set(["==", "===", "!=", "!=="]);
|
|
3
|
+
export const preferEffectMatchRule = defineRule({
|
|
4
|
+
meta: {
|
|
5
|
+
type: "problem",
|
|
6
|
+
docs: {
|
|
7
|
+
description: "Use Match from Effect for chained literal ternaries over the same value.",
|
|
8
|
+
},
|
|
9
|
+
messages: {
|
|
10
|
+
preferMatch: "Use Match from Effect instead of a chained literal ternary.",
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
createOnce(context) {
|
|
14
|
+
const isLiteral = (node) => node.type === "Literal" ||
|
|
15
|
+
(node.type === "TemplateLiteral" && node.expressions.length === 0);
|
|
16
|
+
const comparedValue = (node) => {
|
|
17
|
+
if (node.type !== "BinaryExpression" ||
|
|
18
|
+
!equalityOperators.has(node.operator)) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
if (isLiteral(node.left))
|
|
22
|
+
return context.sourceCode.getText(node.right);
|
|
23
|
+
if (isLiteral(node.right))
|
|
24
|
+
return context.sourceCode.getText(node.left);
|
|
25
|
+
return undefined;
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
ConditionalExpression(node) {
|
|
29
|
+
if (node.parent?.type === "ConditionalExpression")
|
|
30
|
+
return;
|
|
31
|
+
const value = comparedValue(node.test);
|
|
32
|
+
if (value === undefined)
|
|
33
|
+
return;
|
|
34
|
+
let alternate = node.alternate;
|
|
35
|
+
let literalChecks = 1;
|
|
36
|
+
while (alternate.type === "ConditionalExpression") {
|
|
37
|
+
if (comparedValue(alternate.test) !== value)
|
|
38
|
+
return;
|
|
39
|
+
literalChecks += 1;
|
|
40
|
+
alternate = alternate.alternate;
|
|
41
|
+
}
|
|
42
|
+
if (literalChecks > 1) {
|
|
43
|
+
context.report({ node, messageId: "preferMatch" });
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
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;
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
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;
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
});
|