@timmo001/oxlint-rules 0.1.0 → 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/package.json +1 -1
- package/vendor/anti-slop/README.md +0 -299
package/package.json
CHANGED
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
# anti-slop
|
|
2
|
-
|
|
3
|
-
[](https://skills.sh/dmmulroy/anti-slop)
|
|
4
|
-
|
|
5
|
-
Opinionated Oxlint rules that reject low-evidence and low-signal TypeScript and JavaScript patterns.
|
|
6
|
-
|
|
7
|
-
Anti-slop is first and foremost the ruleset I use with my work, projects, and team. It reflects my preferences and taste rather than attempting to be a universal coding standard.
|
|
8
|
-
|
|
9
|
-
**This project is meant to be vendored**, not treated as a fixed npm dependency. There is no official npm package. Copy the rules into your repository, read them, and change them to match your team's standards. The bundled agent skill handles the initial copy and configuration; after that, the vendored files are yours to maintain and make your own. Community-maintained forks and packages are welcome, but their compatibility and release lifecycle belong to their maintainers.
|
|
10
|
-
|
|
11
|
-
## Install with an agent skill
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
npx skills add dmmulroy/anti-slop --skill install-anti-slop
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Then ask your coding agent to install or configure anti-slop in the current repository. The skill copies the plugin, installs compatible Oxlint dependencies—matching an existing Oxlint version when present—merges the plugin into the existing lint configuration, enables every generic rule, and validates the result. In repositories that depend directly on Effect, it also enables the opt-in Effect rule group.
|
|
18
|
-
|
|
19
|
-
To inspect available skills first:
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
npx skills add dmmulroy/anti-slop --list
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Manual local installation
|
|
26
|
-
|
|
27
|
-
Copy `src/` into the target repository, for example at `tools/oxlint/anti-slop/`. If the repository already uses `oxlint`, install `@oxlint/plugins` at exactly the resolved Oxlint version. Otherwise, install the same current version of both packages. Keep both versions exact so upgrades move them together.
|
|
28
|
-
|
|
29
|
-
Register the copied entry point in `oxlint.config.ts`:
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
import { defineConfig } from "oxlint";
|
|
33
|
-
|
|
34
|
-
export default defineConfig({
|
|
35
|
-
ignorePatterns: [
|
|
36
|
-
".agent/**",
|
|
37
|
-
".agents/**",
|
|
38
|
-
".claude/**",
|
|
39
|
-
".codex/**",
|
|
40
|
-
".continue/**",
|
|
41
|
-
".cursor/**",
|
|
42
|
-
".gemini/**",
|
|
43
|
-
".opencode/**",
|
|
44
|
-
".pi/**",
|
|
45
|
-
".roo/**",
|
|
46
|
-
".windsurf/**",
|
|
47
|
-
"tools/oxlint/anti-slop/**",
|
|
48
|
-
],
|
|
49
|
-
jsPlugins: [
|
|
50
|
-
{ name: "anti-slop", specifier: "./tools/oxlint/anti-slop/index.ts" },
|
|
51
|
-
],
|
|
52
|
-
rules: {
|
|
53
|
-
"anti-slop/no-chained-type-assertions": "error",
|
|
54
|
-
"anti-slop/no-conditional-empty-object-spread": "error",
|
|
55
|
-
"anti-slop/no-known-value-widening": "error",
|
|
56
|
-
"anti-slop/no-module-mocking": "error",
|
|
57
|
-
"anti-slop/no-object-parameters": "error",
|
|
58
|
-
"anti-slop/no-reflect-apply": "error",
|
|
59
|
-
"anti-slop/no-reflect-get": "error",
|
|
60
|
-
"anti-slop/no-runtime-typeof": "error",
|
|
61
|
-
"anti-slop/no-shape-in-symbol-names": "error",
|
|
62
|
-
"anti-slop/no-unknown-parameters": "error",
|
|
63
|
-
"anti-slop/no-unknown-returns": "error",
|
|
64
|
-
"anti-slop/no-unknown-type-aliases": "error",
|
|
65
|
-
"anti-slop/no-unsafe-dictionary-type": "error",
|
|
66
|
-
"anti-slop/no-widen-then-assert": "error",
|
|
67
|
-
"anti-slop/require-safety-comment-for-type-assertion": "error"
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
The same `ignorePatterns`, `jsPlugins`, and rules work under `lint` in a Vite+ config. Merge the ignore patterns into Vite+'s `fmt.ignorePatterns` as well so `vp check` does not reformat installed agent assets or the vendored plugin. Preserve existing ignores and add any other project-local agent tooling directories detected in the repository; do not broadly ignore every dot-directory.
|
|
73
|
-
|
|
74
|
-
### Optional Effect rules
|
|
75
|
-
|
|
76
|
-
Effect-specific rules live in a separate plugin so projects that do not use Effect do not inherit Effect architecture policy. Register the Effect entry point only in repositories that use Effect:
|
|
77
|
-
|
|
78
|
-
```ts
|
|
79
|
-
export default defineConfig({
|
|
80
|
-
jsPlugins: [
|
|
81
|
-
{ name: "anti-slop", specifier: "./tools/oxlint/anti-slop/index.ts" },
|
|
82
|
-
{
|
|
83
|
-
name: "anti-slop-effect",
|
|
84
|
-
specifier: "./tools/oxlint/anti-slop/effect/index.ts"
|
|
85
|
-
}
|
|
86
|
-
],
|
|
87
|
-
rules: {
|
|
88
|
-
"anti-slop-effect/no-service-constructor-imports": "error"
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
## Rules
|
|
94
|
-
|
|
95
|
-
### Generic rules
|
|
96
|
-
|
|
97
|
-
- `no-chained-type-assertions` — rejects nested `as` and angle-bracket assertions that fabricate evidence; chains made only of `as const` remain valid.
|
|
98
|
-
- `no-conditional-empty-object-spread` — reports object spreads that use a conditional `{}` branch to omit fields. It intentionally has no autofix because omission is not equivalent to assigning `undefined`.
|
|
99
|
-
- `no-known-value-widening` — rejects known expressions flowing into explicit `unknown`, `object`, anonymous-object, or open-dictionary targets, including known arguments passed to local `unknown` type predicates. Empty dictionary accumulators and finite-key `Record` targets remain valid.
|
|
100
|
-
- `no-module-mocking` — rejects Vitest and Jest `mock`, `doMock`, and `unstable_mockModule` calls in favor of real dependency seams.
|
|
101
|
-
- `no-object-parameters` — rejects `object`, unions containing it, and scoped or transparent generic aliases that resolve to it on function inputs.
|
|
102
|
-
- `no-reflect-apply` — rejects global `Reflect.apply` in favor of typed function calls.
|
|
103
|
-
- `no-reflect-get` — rejects global `Reflect.get` in favor of typed property access or boundary parsing.
|
|
104
|
-
- `no-runtime-typeof` — requires boundary parsing instead of ad hoc `typeof` narrowing. Existence probes against the string `"undefined"` are allowed, and type predicates can be enabled explicitly.
|
|
105
|
-
- `no-shape-in-symbol-names` — rejects the case-insensitive substring `shape` in locally owned symbol names while allowing static member names such as Zod's `schema.shape` that cannot be renamed locally.
|
|
106
|
-
- `no-unknown-parameters` — rejects `unknown` and unions containing it on function inputs except the explicit `cause` convention and the exact subject of a type predicate.
|
|
107
|
-
- `no-unknown-returns` — rejects explicit function contracts that resolve to `unknown`, `Promise<unknown>`, or `PromiseLike<unknown>`, including scoped and transparent generic aliases.
|
|
108
|
-
- `no-unknown-type-aliases` — rejects scoped and transparent generic aliases whose resolved type is `unknown`.
|
|
109
|
-
- `no-unsafe-dictionary-type` — rejects dictionary value contracts based on `unknown`, `any`, `object`, `{}`, and semantic equivalents. Generic constraints such as `T extends Record<string, unknown>` are allowed.
|
|
110
|
-
- `no-widen-then-assert` — rejects immutable local flows that widen known evidence to `unknown`, `any`, `object`, or a broad record and later assert it back to a narrower type.
|
|
111
|
-
- `require-safety-comment-for-type-assertion` — requires each non-const assertion to have a nearby, non-empty invariant justification. Marker prefixes are configurable and default to `SAFETY`.
|
|
112
|
-
|
|
113
|
-
### Effect rules
|
|
114
|
-
|
|
115
|
-
- `no-service-constructor-imports` — rejects named `make<CapabilityName>` imports from relative project modules outside `*.test.*` and `*.spec.*` files. Runtime callers should import the owning Layer and yield the contextual service instead. Package and path-alias imports, default imports, and static constructors such as `WorkspaceName.make` are outside the rule.
|
|
116
|
-
|
|
117
|
-
### Analysis boundaries
|
|
118
|
-
|
|
119
|
-
The rules use Oxlint's ESTree and lexical-scope APIs rather than a TypeScript type checker. They resolve same-file aliases—including block-scoped aliases, forward references, and transparent generic aliases—but do not infer imported type definitions or cross-file call signatures. Rules that inspect calls therefore document when enforcement is intentionally local.
|
|
120
|
-
|
|
121
|
-
## Violation examples
|
|
122
|
-
|
|
123
|
-
Each snippet below is rejected by the named rule.
|
|
124
|
-
|
|
125
|
-
### `no-chained-type-assertions`
|
|
126
|
-
|
|
127
|
-
```ts
|
|
128
|
-
const user = input as object as User;
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
### `no-conditional-empty-object-spread`
|
|
132
|
-
|
|
133
|
-
```ts
|
|
134
|
-
const options = {
|
|
135
|
-
...(timeout !== undefined ? { timeout } : {}),
|
|
136
|
-
};
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### `no-known-value-widening`
|
|
140
|
-
|
|
141
|
-
```ts
|
|
142
|
-
const handlers: Record<string, Handler> = {
|
|
143
|
-
start: startHandler,
|
|
144
|
-
};
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
This discards the known `start` key. Preserve inference or use `satisfies Record<string, Handler>` instead.
|
|
148
|
-
|
|
149
|
-
Known values must not be widened back to `unknown` through a local type predicate:
|
|
150
|
-
|
|
151
|
-
```ts
|
|
152
|
-
function isUser(value: unknown): value is User {
|
|
153
|
-
return UserSchema.safeParse(value).success;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
declare const user: User;
|
|
157
|
-
isUser(user);
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
Call the predicate at the unparsed boundary, while the argument is still `unknown`.
|
|
161
|
-
|
|
162
|
-
### `no-module-mocking`
|
|
163
|
-
|
|
164
|
-
```ts
|
|
165
|
-
vi.mock("./user-store");
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
### `no-object-parameters`
|
|
169
|
-
|
|
170
|
-
```ts
|
|
171
|
-
function save(value: object) {}
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
### `no-reflect-apply`
|
|
175
|
-
|
|
176
|
-
```ts
|
|
177
|
-
const value = Reflect.apply(operation, owner, args);
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
### `no-reflect-get`
|
|
181
|
-
|
|
182
|
-
```ts
|
|
183
|
-
const value = Reflect.get(owner, key);
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
### `no-runtime-typeof`
|
|
187
|
-
|
|
188
|
-
```ts
|
|
189
|
-
if (typeof input === "string") {
|
|
190
|
-
useName(input);
|
|
191
|
-
}
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
Schema-free projects can permit `typeof` checks directly inside type predicate and
|
|
195
|
-
assertion functions while continuing to reject ad hoc checks elsewhere:
|
|
196
|
-
|
|
197
|
-
```json
|
|
198
|
-
{
|
|
199
|
-
"anti-slop/no-runtime-typeof": [
|
|
200
|
-
"error",
|
|
201
|
-
{ "allowInTypeGuards": true }
|
|
202
|
-
]
|
|
203
|
-
}
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
The option defaults to `false`. Existence probes such as `typeof document === "undefined"` are always allowed because they establish whether a binding exists rather than narrow its representation.
|
|
207
|
-
|
|
208
|
-
### `no-shape-in-symbol-names`
|
|
209
|
-
|
|
210
|
-
```ts
|
|
211
|
-
interface UserShape {
|
|
212
|
-
id: string;
|
|
213
|
-
}
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
Static member reads such as `schema.shape` are allowed because the member name belongs to the value's owner and cannot be renamed locally.
|
|
217
|
-
|
|
218
|
-
### Effect: `no-service-constructor-imports`
|
|
219
|
-
|
|
220
|
-
```ts
|
|
221
|
-
import { makeIssueService } from "./issue-service.ts";
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
Import the owning Layer and yield `IssueService` instead. Focused `*.test.*` and `*.spec.*` files may import the constructor directly.
|
|
225
|
-
|
|
226
|
-
### `no-unknown-parameters`
|
|
227
|
-
|
|
228
|
-
```ts
|
|
229
|
-
function handle(input: unknown) {}
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
A type predicate may accept `unknown` for the parameter it narrows; other `unknown`
|
|
233
|
-
parameters on the same function remain rejected.
|
|
234
|
-
|
|
235
|
-
### `no-unknown-returns`
|
|
236
|
-
|
|
237
|
-
```ts
|
|
238
|
-
function loadUser(): unknown {
|
|
239
|
-
return input;
|
|
240
|
-
}
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
### `no-unknown-type-aliases`
|
|
244
|
-
|
|
245
|
-
```ts
|
|
246
|
-
type ExternalValue = unknown;
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
### `no-unsafe-dictionary-type`
|
|
250
|
-
|
|
251
|
-
```ts
|
|
252
|
-
type Metadata = Record<string, unknown>;
|
|
253
|
-
type OtherMetadata = { [key: string]: object };
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
### `no-widen-then-assert`
|
|
257
|
-
|
|
258
|
-
```ts
|
|
259
|
-
const loaded: User = loadUser();
|
|
260
|
-
const stored: unknown = loaded;
|
|
261
|
-
const user = stored as User;
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
### `require-safety-comment-for-type-assertion`
|
|
265
|
-
|
|
266
|
-
```ts
|
|
267
|
-
const userId = value as UserId;
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
Add a specific justification immediately before a necessary assertion:
|
|
271
|
-
|
|
272
|
-
```ts
|
|
273
|
-
// SAFETY: parseUserId validated the identifier before branding it.
|
|
274
|
-
const userId = value as UserId;
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
`SAFETY` remains the default marker. Comments immediately above exported declarations are recognized. Repositories with an established convention can configure one or more alternatives; every marker must still be followed by a colon and a non-empty justification:
|
|
278
|
-
|
|
279
|
-
```json
|
|
280
|
-
{
|
|
281
|
-
"anti-slop/require-safety-comment-for-type-assertion": [
|
|
282
|
-
"error",
|
|
283
|
-
{ "markers": ["INVARIANT", "SAFETY"] }
|
|
284
|
-
]
|
|
285
|
-
}
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
## Development
|
|
289
|
-
|
|
290
|
-
```bash
|
|
291
|
-
pnpm install
|
|
292
|
-
pnpm check
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
`src/` is canonical. After changing production source, run `pnpm sync:skill-assets`; CI checks that the skill's bundled copy remains identical. `pnpm check` runs Oxlint, every RuleTester suite, TypeScript typechecking, and the skill-asset drift check.
|
|
296
|
-
|
|
297
|
-
## License
|
|
298
|
-
|
|
299
|
-
MIT
|