@imapps/oxc-config 0.0.0-stage → 7.0.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/README.md +65 -2
- package/anti-slop/LICENSE +21 -0
- package/anti-slop/UPSTREAM-IMAPPS.md +11 -0
- package/anti-slop/index.ts +47 -0
- package/anti-slop/rules/no-array-filter-map.ts +28 -0
- package/anti-slop/rules/no-chained-type-assertions.ts +77 -0
- package/anti-slop/rules/no-conditional-empty-object-spread.ts +49 -0
- package/anti-slop/rules/no-known-value-widening.ts +415 -0
- package/anti-slop/rules/no-module-mocking.ts +80 -0
- package/anti-slop/rules/no-object-parameters.ts +83 -0
- package/anti-slop/rules/no-reduce-accumulator-copy.ts +109 -0
- package/anti-slop/rules/no-reflect-apply.ts +28 -0
- package/anti-slop/rules/no-reflect-get.ts +28 -0
- package/anti-slop/rules/no-runtime-typeof.ts +77 -0
- package/anti-slop/rules/no-shape-in-symbol-names.ts +46 -0
- package/anti-slop/rules/no-unknown-parameters.ts +69 -0
- package/anti-slop/rules/no-unknown-returns.ts +82 -0
- package/anti-slop/rules/no-unknown-type-aliases.ts +54 -0
- package/anti-slop/rules/no-unsafe-dictionary-type.ts +154 -0
- package/anti-slop/rules/no-widen-then-assert.ts +366 -0
- package/anti-slop/rules/require-readable-spacing.ts +80 -0
- package/anti-slop/rules/require-safety-comment-for-type-assertion.ts +131 -0
- package/anti-slop/shared/array-method.ts +94 -0
- package/anti-slop/shared/dictionary-types.ts +515 -0
- package/anti-slop/shared/function-parameters.ts +49 -0
- package/anti-slop/shared/lexical-type-parameters.ts +61 -0
- package/anti-slop/shared/reflect-method.ts +24 -0
- package/anti-slop/shared/scope.ts +15 -0
- package/anti-slop/shared/type-alias-resolution.ts +250 -0
- package/anti-slop/vendor/eslint-stylistic/LICENSE +22 -0
- package/anti-slop/vendor/eslint-stylistic/UPSTREAM.md +28 -0
- package/anti-slop/vendor/eslint-stylistic/padding-line-ast.ts +51 -0
- package/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.ts +929 -0
- package/anti-slop/vendor/eslint-stylistic/padding-line-options.d.ts +87 -0
- package/build/anti-slop.js +2569 -0
- package/build/anti-slop.js.map +1 -0
- package/build/oxfmt.d.ts +24 -0
- package/build/oxfmt.js +37 -0
- package/build/oxfmt.js.map +1 -0
- package/build/oxlint.d.ts +44 -0
- package/build/oxlint.js +57 -0
- package/build/oxlint.js.map +1 -0
- package/package.json +52 -4
package/README.md
CHANGED
|
@@ -1,3 +1,66 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @imapps/oxc-config
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared [Oxlint](https://oxc.rs/docs/guide/usage/linter) and [Oxfmt](https://oxc.rs/docs/guide/usage/formatter)
|
|
4
|
+
configuration for IM Apps projects, including the vendored [anti-slop](https://github.com/dmmulroy/anti-slop) lint rules.
|
|
5
|
+
|
|
6
|
+
JS plugins in Oxlint are alpha and not semver-stable, so `oxlint`, `@oxlint/plugins` and `oxfmt` are exact-pinned peer dependencies.
|
|
7
|
+
Install the same versions in the consuming repo.
|
|
8
|
+
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
- Node `>=22.18`: Oxlint and Oxfmt load `oxlint.config.ts` / `oxfmt.config.ts` through Node's built-in TypeScript type stripping, which is only on by default from 22.18.
|
|
12
|
+
- `oxlint`, `@oxlint/plugins` and `oxfmt` must be installed at the **exact** versions pinned in this package's `peerDependencies` (`1.90.0`, `1.90.0`, `0.75.0` at the time of writing). The JS plugin API is alpha, so any other version is unsupported; npm rejects a mismatch and bun only warns.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
bun add -d @imapps/oxc-config oxlint@1.90.0 @oxlint/plugins@1.90.0 oxfmt@0.75.0
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`oxlint.config.ts`:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { defineConfig } from 'oxlint';
|
|
24
|
+
import oxlintConfig from '@imapps/oxc-config/oxlint';
|
|
25
|
+
|
|
26
|
+
export default defineConfig({ ...oxlintConfig });
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`oxfmt.config.ts`:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import oxfmtConfig from '@imapps/oxc-config/oxfmt';
|
|
33
|
+
|
|
34
|
+
export default oxfmtConfig;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Scripts:
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"lint": "oxlint && oxfmt --check",
|
|
42
|
+
"lint:fix": "oxlint --fix && oxfmt && oxlint",
|
|
43
|
+
"format": "oxfmt"
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## What is included
|
|
48
|
+
|
|
49
|
+
- Lint: `correctness` category, `typescript`/`oxc`/`jsx-a11y` plugins, `prefer-const`, `prefer-template`,
|
|
50
|
+
`eqeqeq` (warn), `typescript/no-explicit-any` (warn, off in `*.test.*`/`*.spec.*`), `oxc/no-accumulating-spread`,
|
|
51
|
+
and the 18 generic anti-slop rules at `error`. Agent directories (`.claude`, `.omp`, `.pi`, ...), `.worktrees` and the vendored plugin are ignored.
|
|
52
|
+
- Format: 4-space indent, width 120, single quotes, semicolons, `es5` trailing commas, `always` arrow parens,
|
|
53
|
+
2-space JSON, `sortImports` on, `sortPackageJson` off (key order is meaningful, e.g. `exports` conditions).
|
|
54
|
+
|
|
55
|
+
## Layout
|
|
56
|
+
|
|
57
|
+
- `src/oxlint.ts`, `src/oxfmt.ts`: the config objects.
|
|
58
|
+
- `anti-slop/`: vendored plugin source (see `anti-slop/UPSTREAM-IMAPPS.md`).
|
|
59
|
+
- Everything is built with `tsup` into `build/`; the package exports only built JS because Node cannot load `.ts` from `node_modules`.
|
|
60
|
+
|
|
61
|
+
## Development
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
bun run build
|
|
65
|
+
bun run test # builds, then lints fixtures with the built config
|
|
66
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dillon Mulroy
|
|
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.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Upstream
|
|
2
|
+
|
|
3
|
+
Vendored from https://github.com/dmmulroy/anti-slop at commit `13909c9e07590f5a85d93c62712259fe14a883f7`
|
|
4
|
+
via `skills/install-anti-slop/scripts/install.mjs`.
|
|
5
|
+
|
|
6
|
+
Changes from upstream: the `effect/` rule group was removed (no IM Apps repo uses `effect`). Everything else is unmodified.
|
|
7
|
+
|
|
8
|
+
This directory is the source of truth for the plugin; `tsup` bundles `anti-slop/index.ts` into `build/anti-slop.js`,
|
|
9
|
+
which is what the `@imapps/oxc-config/anti-slop` specifier resolves to (Node refuses to type-strip `.ts` under `node_modules`).
|
|
10
|
+
|
|
11
|
+
The upstream MIT `LICENSE` is included unmodified as `anti-slop/LICENSE`.
|
|
@@ -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
|
+
});
|