Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .oxfmtignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pnpm-lock.yaml
.agents/skills/**
.claude/skills/**
.skills/**
tools/oxlint/anti-slop/**
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ aube run build
## Tools

- **[Oxfmt](https://oxc.rs)** formats every source and markdown file, configured by `tooling/oxc/.oxfmtrc.json`. Avoid unrelated formatting churn in pull requests.
- **[Oxlint](https://oxc.rs)** runs with type-aware checks, configured by `tooling/oxc/base.oxlintrc.json` (shared rules) and extended per workspace scope by `tooling/oxc/packages.oxlintrc.json` (adds the `node` plugin) and `tooling/oxc/apps.oxlintrc.json` (adds the `vue` plugin); both extend the base and are referenced from each package's own `lint`/`lint:fix` scripts. The base config is extended with [`@e18e/eslint-plugin`](https://github.com/e18e/eslint-plugin) for modernization, module-replacement, and performance rules.
- **[Oxlint](https://oxc.rs)** runs with type-aware checks, configured by `tooling/oxc/base.oxlintrc.json` (shared rules) and extended per workspace scope by `tooling/oxc/packages.oxlintrc.json` (adds the `node` plugin) and `tooling/oxc/apps.oxlintrc.json` (adds the `vue` plugin); both extend the base and are referenced from each package's own `lint`/`lint:fix` scripts. The base config is extended with [`@e18e/eslint-plugin`](https://github.com/e18e/eslint-plugin) for modernization, module-replacement, and performance rules, plus the vendored [`anti-slop`](https://github.com/dmmulroy/anti-slop) rules under `tools/oxlint/anti-slop` for low-evidence TypeScript patterns.
- **[Knip](https://knip.dev)** detects unused files, exports, and dependencies; per-workspace entry points are declared in `knip.jsonc`.

## Git hooks
Expand Down
9 changes: 9 additions & 0 deletions knip.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@
"@commitlint/cli",
"nano-staged",
],
// Upstream exports two dictionary helpers for its tests, which are not part of the vendored
// runtime copy.
"ignoreIssues": {
"tools/oxlint/anti-slop/shared/dictionary-types.ts": ["exports", "types"],
},
// The Oxlint plugin's default config glob (`.oxlintrc.json` at each workspace root) no longer
// matches: every workspace's `lint`/`lint:fix` script points at tooling/oxc/{packages,apps}.oxlintrc.json
// instead, which themselves extend tooling/oxc/base.oxlintrc.json.
"oxlint": {
"config": ["tooling/oxc/*.oxlintrc.json"],
},
"workspaces": {
".": {
// Loaded by Oxlint from base.oxlintrc.json as a local JavaScript plugin.
"entry": ["tools/oxlint/anti-slop/index.ts"],
},
"packages/i18n": {
// Every i18n:* script is invoked directly (`node scripts/x.ts`) from package.json rather
// than imported, so each is its own entry point. lunaria.config.ts is discovered by
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@commitlint/cli": "^21.2.1",
"@commitlint/config-conventional": "^21.2.0",
"@e18e/eslint-plugin": "^0.8.0",
"@oxlint/plugins": "^1.74.0",
"@redstardev/unplugin-version-injector": "0.0.2",
"@types/node": "^26.2.0",
"husky": "^9.1.7",
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions tooling/oxc/base.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{
"$schema": "../../node_modules/oxlint/configuration_schema.json",
"plugins": ["typescript", "import", "promise", "vitest", "unicorn", "oxc"],
"jsPlugins": ["@e18e/eslint-plugin"],
"jsPlugins": [
"@e18e/eslint-plugin",
{
"name": "anti-slop",
"specifier": "../../tools/oxlint/anti-slop/index.ts"
}
],
"categories": {
"correctness": "error",
"suspicious": "error",
Expand Down Expand Up @@ -34,7 +40,22 @@
"e18e/prefer-regex-test": "error",
"e18e/prefer-static-regex": "error",
"e18e/prefer-string-fromcharcode": "error",
"e18e/prefer-timer-args": "error"
"e18e/prefer-timer-args": "error",
"anti-slop/no-chained-type-assertions": "error",
"anti-slop/no-conditional-empty-object-spread": "off",
"anti-slop/no-known-value-widening": "off",
"anti-slop/no-module-mocking": "off",
"anti-slop/no-object-parameters": "off",
"anti-slop/no-reflect-apply": "error",
"anti-slop/no-reflect-get": "error",
"anti-slop/no-runtime-typeof": "off",
"anti-slop/no-shape-in-symbol-names": "error",
"anti-slop/no-unknown-parameters": "off",
"anti-slop/no-unknown-returns": "off",
"anti-slop/no-unknown-type-aliases": "error",
"anti-slop/no-unsafe-dictionary-type": "off",
"anti-slop/no-widen-then-assert": "error",
"anti-slop/require-safety-comment-for-type-assertion": "off"
},
"ignorePatterns": [
"**/dist/**",
Expand Down
21 changes: 21 additions & 0 deletions tools/oxlint/anti-slop/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Dillon Mulroy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 10 additions & 0 deletions tools/oxlint/anti-slop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# anti-slop

Oxlint rules that reject low-evidence TypeScript patterns, vendored from
[dmmulroy/anti-slop](https://github.com/dmmulroy/anti-slop) at `6d538555cb15` (MIT, see LICENSE).

Upstream ships these to be vendored rather than depended on, so these files are ours to edit.
`tooling/oxc/base.oxlintrc.json` loads the plugin through the existing workspace `lint` and
`lint:fix` scripts. Rules that the repository already passes are enforced; the remaining rules
stay listed as `off` until their existing findings are addressed. Re-sync this directory
deliberately when updating the upstream pin.
41 changes: 41 additions & 0 deletions tools/oxlint/anti-slop/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { eslintCompatPlugin } from "@oxlint/plugins";

import { noChainedTypeAssertionsRule } from "./rules/no-chained-type-assertions.ts";
import { noConditionalEmptyObjectSpreadRule } from "./rules/no-conditional-empty-object-spread.ts";
import { noKnownValueWideningRule } from "./rules/no-known-value-widening.ts";
import { noModuleMockingRule } from "./rules/no-module-mocking.ts";
import { noObjectParametersRule } from "./rules/no-object-parameters.ts";
import { noReflectApplyRule } from "./rules/no-reflect-apply.ts";
import { noReflectGetRule } from "./rules/no-reflect-get.ts";
import { noRuntimeTypeofRule } from "./rules/no-runtime-typeof.ts";
import { noForbiddenTermInSymbolNamesRule } from "./rules/no-shape-in-symbol-names.ts";
import { noUnknownParametersRule } from "./rules/no-unknown-parameters.ts";
import { noUnknownReturnsRule } from "./rules/no-unknown-returns.ts";
import { noUnknownTypeAliasesRule } from "./rules/no-unknown-type-aliases.ts";
import { noUnsafeDictionaryTypeRule } from "./rules/no-unsafe-dictionary-type.ts";
import { noWidenThenAssertRule } from "./rules/no-widen-then-assert.ts";
import { requireSafetyCommentForTypeAssertionRule } from "./rules/require-safety-comment-for-type-assertion.ts";

/** Generic Oxlint rules that reject low-evidence and low-signal implementation patterns. */
const antiSlopPlugin = eslintCompatPlugin({
meta: { name: "anti-slop" },
rules: {
"no-chained-type-assertions": noChainedTypeAssertionsRule,
"no-conditional-empty-object-spread": noConditionalEmptyObjectSpreadRule,
"no-known-value-widening": noKnownValueWideningRule,
"no-module-mocking": noModuleMockingRule,
"no-object-parameters": noObjectParametersRule,
"no-reflect-apply": noReflectApplyRule,
"no-reflect-get": noReflectGetRule,
"no-runtime-typeof": noRuntimeTypeofRule,
"no-unsafe-dictionary-type": noUnsafeDictionaryTypeRule,
"no-shape-in-symbol-names": noForbiddenTermInSymbolNamesRule,
"no-unknown-parameters": noUnknownParametersRule,
"no-unknown-returns": noUnknownReturnsRule,
"no-unknown-type-aliases": noUnknownTypeAliasesRule,
"no-widen-then-assert": noWidenThenAssertRule,
"require-safety-comment-for-type-assertion": requireSafetyCommentForTypeAssertionRule,
},
});

export default antiSlopPlugin;
1 change: 1 addition & 0 deletions tools/oxlint/anti-slop/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "type": "module" }
77 changes: 77 additions & 0 deletions tools/oxlint/anti-slop/rules/no-chained-type-assertions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { defineRule } from "@oxlint/plugins";
import type { ESTree } from "@oxlint/plugins";

type TypeAssertionExpression = ESTree.TSAsExpression | ESTree.TSTypeAssertion;

function isTypeAssertionExpression(node: ESTree.Node): node is TypeAssertionExpression {
return node.type === "TSAsExpression" || node.type === "TSTypeAssertion";
}

function unwrapParenthesizedExpression(expression: ESTree.Expression): ESTree.Expression {
let current = expression;
while (current.type === "ParenthesizedExpression") {
current = current.expression;
}
return current;
}

function isConstAssertion(node: TypeAssertionExpression): boolean {
const { typeAnnotation } = node;
return (
typeAnnotation.type === "TSTypeReference" &&
typeAnnotation.typeName.type === "Identifier" &&
typeAnnotation.typeName.name === "const"
);
}

function isOutermostAssertionInChain(node: TypeAssertionExpression): boolean {
let current: ESTree.Expression = node;
let parent = node.parent;

while (parent.type === "ParenthesizedExpression" && parent.expression === current) {
current = parent;
parent = parent.parent;
}

return !isTypeAssertionExpression(parent) || parent.expression !== current;
}

function isForbiddenAssertionChain(node: TypeAssertionExpression): boolean {
let assertionCount = 0;
let hasNonConstAssertion = false;
let current: ESTree.Expression = node;

while (isTypeAssertionExpression(current)) {
assertionCount += 1;
hasNonConstAssertion ||= !isConstAssertion(current);
current = unwrapParenthesizedExpression(current.expression);
}

return assertionCount > 1 && hasNonConstAssertion;
}

/** Disallow nested TypeScript type assertions, while permitting chains made only of const assertions. */
export const noChainedTypeAssertionsRule = defineRule({
meta: {
type: "problem",
docs: {
description:
"Disallow chained TypeScript as and angle-bracket assertions, including parenthesized chains.",
},
messages: {
chained:
"This assertion chain discards type evidence. Keep the original precise type, or parse untrusted input at its boundary before narrowing it.",
},
},
createOnce(context) {
const checkTypeAssertion = (node: TypeAssertionExpression) => {
if (!isOutermostAssertionInChain(node) || !isForbiddenAssertionChain(node)) return;
context.report({ node, messageId: "chained" });
};

return {
TSAsExpression: checkTypeAssertion,
TSTypeAssertion: checkTypeAssertion,
};
},
});
49 changes: 49 additions & 0 deletions tools/oxlint/anti-slop/rules/no-conditional-empty-object-spread.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { defineRule } from "@oxlint/plugins";
import type { ESTree } from "@oxlint/plugins";

function unwrapParentheses(node: ESTree.Expression): ESTree.Expression {
let current = node;
while (current.type === "ParenthesizedExpression") {
current = current.expression;
}
return current;
}

function isEmptyObjectExpression(node: ESTree.Expression): boolean {
return node.type === "ObjectExpression" && node.properties.length === 0;
}

function isConditionalEmptyObjectSpread(node: ESTree.Expression): boolean {
const conditional = unwrapParentheses(node);
return (
conditional.type === "ConditionalExpression" &&
(isEmptyObjectExpression(conditional.consequent) ||
isEmptyObjectExpression(conditional.alternate))
);
}

/** Ban conditional empty-object spreads without changing their omission semantics. */
export const noConditionalEmptyObjectSpreadRule = defineRule({
meta: {
type: "suggestion",
docs: {
description:
"Disallow object spreads that conditionally spread an empty object to omit fields.",
},
messages: {
avoid:
"This conditional spread hides property omission behind an empty object. Build the object in separate statements and add the property only when present.",
},
},
createOnce(context) {
return {
SpreadElement(node) {
if (node.parent.type !== "ObjectExpression") return;

if (isConditionalEmptyObjectSpread(node.argument)) {
context.report({ node, messageId: "avoid" });
}
},
};
},
});
Loading
Loading