adamantite 0.44.0 → 0.46.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 +413 -122
- package/dist/index.js +638 -57
- package/dist/oxlint.js +1 -0
- package/dist/presets/analyze.js +1 -0
- package/dist/presets/lint/{react-doctor.d.ts → architecture.d.ts} +1 -1
- package/dist/presets/lint/architecture.js +8 -0
- package/dist/presets/lint/core.js +0 -1
- package/dist/presets/lint/effect.js +26 -1
- package/dist/presets/lint/jest.d.ts +13 -0
- package/dist/presets/lint/jest.js +88 -68
- package/dist/presets/lint/plugin/glob.d.ts +7 -0
- package/dist/presets/lint/plugin/glob.js +48 -0
- package/dist/presets/lint/plugin/imports.d.ts +4 -0
- package/dist/presets/lint/plugin/imports.js +4 -1
- package/dist/presets/lint/plugin/index.d.ts +3 -0
- package/dist/presets/lint/plugin/index.js +14 -8
- package/dist/presets/lint/plugin/options.d.ts +5 -5
- package/dist/presets/lint/plugin/options.js +19 -7
- package/dist/presets/lint/plugin/resolver.d.ts +8 -0
- package/dist/presets/lint/plugin/resolver.js +79 -0
- package/dist/presets/lint/plugin/rules/import-owners.d.ts +67 -0
- package/dist/presets/lint/plugin/rules/import-owners.js +310 -0
- package/dist/presets/lint/plugin/rules/layers.d.ts +136 -0
- package/dist/presets/lint/plugin/rules/layers.js +479 -0
- package/dist/presets/lint/plugin/rules/no-query-data-in-state.js +1 -1
- package/dist/presets/lint/plugin/rules/no-react-state-hooks.d.ts +0 -5
- package/dist/presets/lint/plugin/rules/no-react-state-hooks.js +3 -47
- package/dist/presets/lint/plugin/rules/query-from-loader.js +2 -2
- package/dist/presets/lint/plugin/rules/require-suppression-reason.d.ts +5 -0
- package/dist/presets/lint/plugin/rules/require-suppression-reason.js +32 -0
- package/dist/presets/lint/react-strict.js +22 -2
- package/dist/presets/lint/strict.js +35 -2
- package/dist/presets/lint/{antislop.d.ts → tailwind.d.ts} +1 -1
- package/dist/presets/lint/{shadcn.js → tailwind.js} +1 -1
- package/dist/presets/lint/vendor/antislop/license.md +26 -1
- package/dist/presets/lint/vendor/antislop/plugin.d.mts +3 -0
- package/dist/presets/lint/vendor/antislop/plugin.mjs +940 -31
- package/dist/presets/lint/vendor/antislop-effect/license.md +27 -0
- package/dist/presets/lint/vendor/antislop-effect/plugin.d.mts +17 -0
- package/dist/presets/lint/vendor/antislop-effect/plugin.mjs +579 -0
- package/dist/presets/lint/vitest.d.ts +13 -0
- package/dist/presets/lint/vitest.js +111 -91
- package/dist/presets/{lint → rules}/custom.d.ts +3 -20
- package/dist/presets/{lint → rules}/custom.js +50 -46
- package/dist/presets/rules/folder.d.ts +34 -0
- package/dist/presets/rules/folder.js +52 -0
- package/dist/presets/rules/index.d.ts +2 -9
- package/dist/presets/rules/index.js +1 -29
- package/dist/presets/rules/load.d.ts +8 -0
- package/dist/presets/rules/load.js +29 -0
- package/dist/presets/rules/plugin.d.ts +3 -0
- package/dist/presets/rules/plugin.js +1 -0
- package/dist/presets/rules/testing.d.ts +2 -0
- package/dist/presets/rules/testing.js +14 -0
- package/dist/presets/tsconfig.json +3 -0
- package/dist/runtime-CVZPDpfE.js +11 -0
- package/package.json +79 -18
- package/skills/adamantite/SKILL.md +112 -200
- package/skills/adamantite/references/custom-rules.md +120 -0
- package/skills/adamantite/references/lint-rules.md +158 -0
- package/skills/adamantite/references/setup.md +64 -0
- package/dist/presets/lint/antislop.js +0 -28
- package/dist/presets/lint/react-doctor.js +0 -20
- package/dist/presets/lint/shadcn.d.ts +0 -5
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# anti-slop-effect license
|
|
2
|
+
|
|
3
|
+
The bundled `plugin.mjs` is a build of
|
|
4
|
+
[anti-slop-effect](https://github.com/dmmulroy/anti-slop) at commit 13909c9e07590f5a85d93c62712259fe14a883f7,
|
|
5
|
+
with its dependencies (MIT) inlined.
|
|
6
|
+
|
|
7
|
+
MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2026 Dillon Mulroy
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Generated by scripts/vendor-plugins.ts — do not edit by hand.
|
|
2
|
+
interface VendoredPluginRule {
|
|
3
|
+
readonly create: (context: object) => Record<string, never>
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare const vendoredPlugin: {
|
|
7
|
+
readonly meta: { readonly name: string }
|
|
8
|
+
readonly rules: {
|
|
9
|
+
readonly "no-manual-effect-error-tag": VendoredPluginRule
|
|
10
|
+
readonly "no-manual-tag-comparison": VendoredPluginRule
|
|
11
|
+
readonly "no-manual-tagged-construction": VendoredPluginRule
|
|
12
|
+
readonly "no-service-constructor-imports": VendoredPluginRule
|
|
13
|
+
readonly "prefer-effect-match": VendoredPluginRule
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default vendoredPlugin
|
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
// Vendored build of the anti-slop-effect oxlint plugin.
|
|
2
|
+
// Source: https://github.com/dmmulroy/anti-slop (MIT) at commit 13909c9e07590f5a85d93c62712259fe14a883f7.
|
|
3
|
+
// Its dependencies (MIT) are inlined so this file is self-contained.
|
|
4
|
+
// See license.md for the full license text.
|
|
5
|
+
// Patched with scripts/vendor-patches/anti-slop-effect/no-manual-tagged-construction-constructor-input.patch.
|
|
6
|
+
//
|
|
7
|
+
// Generated by scripts/vendor-plugins.ts — do not edit by hand.
|
|
8
|
+
//#region node_modules/.pnpm/@oxlint+plugins@1.78.0/node_modules/@oxlint/plugins/index.js
|
|
9
|
+
/**
|
|
10
|
+
* Define a rule.
|
|
11
|
+
*
|
|
12
|
+
* No-op function, just to provide type safety. Input is passed through unchanged.
|
|
13
|
+
*
|
|
14
|
+
* @param rule - Rule to define
|
|
15
|
+
* @returns Same rule as passed in
|
|
16
|
+
*/
|
|
17
|
+
function defineRule(rule) {
|
|
18
|
+
return rule;
|
|
19
|
+
}
|
|
20
|
+
const EMPTY_VISITOR = {};
|
|
21
|
+
/**
|
|
22
|
+
* Convert a plugin which used Oxlint's `createOnce` API to also work with ESLint.
|
|
23
|
+
*
|
|
24
|
+
* If any of the plugin's rules use the Oxlint alternative `createOnce` API,
|
|
25
|
+
* add ESLint-compatible `create` methods to those rules, which delegate to `createOnce`.
|
|
26
|
+
* This makes the plugin compatible with ESLint.
|
|
27
|
+
*
|
|
28
|
+
* The `plugin` object passed in is mutated in-place.
|
|
29
|
+
*
|
|
30
|
+
* @param plugin - Plugin to convert
|
|
31
|
+
* @returns Plugin with all rules having `create` method
|
|
32
|
+
* @throws {Error} If `plugin` is not an object, or `plugin.rules` is not an object
|
|
33
|
+
*/
|
|
34
|
+
function eslintCompatPlugin(plugin) {
|
|
35
|
+
if (typeof plugin != "object" || !plugin) throw Error("Plugin must be an object");
|
|
36
|
+
let { rules } = plugin;
|
|
37
|
+
if (typeof rules != "object" || !rules) throw Error("Plugin must have an object as `rules` property");
|
|
38
|
+
let afterHooksState = new AfterHooksState();
|
|
39
|
+
for (let ruleName in rules) Object.hasOwn(rules, ruleName) && convertRule(rules[ruleName], afterHooksState);
|
|
40
|
+
return plugin;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Class containing state for tracking if any `after` hooks for a plugin's rules need to be called.
|
|
44
|
+
*
|
|
45
|
+
* # Aims
|
|
46
|
+
*
|
|
47
|
+
* Aims are:
|
|
48
|
+
* 1. `after` hook of each rule runs after all other AST visit functions, and CFG event handlers.
|
|
49
|
+
* 2. `after` hooks for *all* a plugin's rules run after *all* that plugin's rules have completed visiting AST.
|
|
50
|
+
* 3. `after` hooks for *all* a plugin's rules run before *any* of plugin's rules begin linting another file.
|
|
51
|
+
* 4. In the case of an error during AST traversal, `after` hooks are always still run.
|
|
52
|
+
*
|
|
53
|
+
* The above exactly matches the behavior when running a `createOnce` rule in Oxlint.
|
|
54
|
+
*
|
|
55
|
+
* # Why this is important
|
|
56
|
+
*
|
|
57
|
+
* All the complication comes from ensuring `after` hooks run even after an error during AST traversal.
|
|
58
|
+
*
|
|
59
|
+
* In ESLint CLI, an error will crash the process, so it doesn't particularly matter if `after` hooks run or not,
|
|
60
|
+
* but language servers will typically swallow errors, and keep the process running.
|
|
61
|
+
*
|
|
62
|
+
* Rules using `before` and `after` hooks will often rely on both hooks running in a predictable order,
|
|
63
|
+
* to maintain some internal state. For example, they may use `before` and `after` hooks to maintain a per-file
|
|
64
|
+
* cache of data which is shared between rules. The cache use case is why rule (2) above is important.
|
|
65
|
+
*
|
|
66
|
+
* Below is an example of using `before` and `after` hooks to maintain a per-file cache, shared between rules.
|
|
67
|
+
* It relies on all `before` hooks running before any rule starts visiting the AST,
|
|
68
|
+
* and all `after` hooks running after all rules have finished visiting the AST.
|
|
69
|
+
*
|
|
70
|
+
* ```ts
|
|
71
|
+
* let cache: Data | null = null;
|
|
72
|
+
*
|
|
73
|
+
* let numRunningRules = 0;
|
|
74
|
+
*
|
|
75
|
+
* const setupCache = (context) => {
|
|
76
|
+
* if (cache === null) cache = new Data(context);
|
|
77
|
+
* numRunningRules++;
|
|
78
|
+
* };
|
|
79
|
+
*
|
|
80
|
+
* const teardownCache = () => {
|
|
81
|
+
* numRunningRules--;
|
|
82
|
+
* if (numRunningRules === 0) cache = null;
|
|
83
|
+
* };
|
|
84
|
+
*
|
|
85
|
+
* const rule1 = {
|
|
86
|
+
* createOnce(context) {
|
|
87
|
+
* return {
|
|
88
|
+
* before() {
|
|
89
|
+
* setupCache(context);
|
|
90
|
+
* },
|
|
91
|
+
* Identifier(node) {
|
|
92
|
+
* // Use `cache`
|
|
93
|
+
* },
|
|
94
|
+
* after: teardownCache,
|
|
95
|
+
* };
|
|
96
|
+
* },
|
|
97
|
+
* };
|
|
98
|
+
*
|
|
99
|
+
* const rule2 = {
|
|
100
|
+
* // Same as above
|
|
101
|
+
* };
|
|
102
|
+
*
|
|
103
|
+
* const rule3 = {
|
|
104
|
+
* // Same as above
|
|
105
|
+
* };
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* If `after` hooks did not always run, the next lint run could get stale state, and malfunction.
|
|
109
|
+
* If `after` hooks ran in the wrong order (e.g. after some `before` hooks for next file),
|
|
110
|
+
* `numRunningRules` would never get to 0, and cache would never be cleared.
|
|
111
|
+
*
|
|
112
|
+
* Note that because all rules run together in a single AST traversal, if a rule from plugin X throws an error,
|
|
113
|
+
* it can disrupt rules from plugin Y. This would make it hard to debug.
|
|
114
|
+
*
|
|
115
|
+
* # Mechanism
|
|
116
|
+
*
|
|
117
|
+
* ## Initialization
|
|
118
|
+
*
|
|
119
|
+
* Rules with an `after` hook register themselves by:
|
|
120
|
+
*
|
|
121
|
+
* 1. Calling `registerResetFunction` to register a function to run `after` hook and clean up internal state.
|
|
122
|
+
* This call adds the reset fn to `resetFunctions`, and adds `AFTER_HOOK_INACTIVE` to `pendingStates`.
|
|
123
|
+
* 2. Adding an `onCodePathEnd` CFG event handler to the visitor which calls `ruleFinished` at end of AST traversal.
|
|
124
|
+
*
|
|
125
|
+
* ## Per-file setup
|
|
126
|
+
*
|
|
127
|
+
* Before linting a file, `create` will call `setupAfterHook` which is created by `createContextAndVisitor`.
|
|
128
|
+
* This registers that the `after` hook for the rule needs to run, by setting `pendingStates[ruleIndex]`
|
|
129
|
+
* to `AFTER_HOOK_PENDING`, and incrementing `pendingCount`.
|
|
130
|
+
*
|
|
131
|
+
* If a cleanup microtask has not been scheduled yet, one is scheduled now (see reason below).
|
|
132
|
+
*
|
|
133
|
+
* ## Normal operation
|
|
134
|
+
*
|
|
135
|
+
* AST traversal for each rule ends with `ruleFinished` hook being called from `onCodePathEnd` CFG event handler.
|
|
136
|
+
* It increments `lintFinishedCount`. If `lintFinishedCount` equals `pendingCount`, all rules have finished linting
|
|
137
|
+
* the file, and `reset` is called, which calls all the pending `after` hooks.
|
|
138
|
+
*
|
|
139
|
+
* ## Error handling
|
|
140
|
+
*
|
|
141
|
+
* If an error is thrown during AST traversal, we ensure that `after` hooks are still run by 2 mechanisms:
|
|
142
|
+
*
|
|
143
|
+
* ### 1. Next microtick
|
|
144
|
+
*
|
|
145
|
+
* Before any rules began linting files, a microtask was scheduled, which runs on next micro-tick.
|
|
146
|
+
* All language servers we're aware of run each lint task in a separate tick, so this microtask will run in next tick
|
|
147
|
+
* after a linting run, before the next lint task starts.
|
|
148
|
+
*
|
|
149
|
+
* If the linting run completed successfully, the microtask does nothing.
|
|
150
|
+
*
|
|
151
|
+
* But if an error was thrown during AST traversal, this will be visible from the state of `pendingCount`.
|
|
152
|
+
* The microtask will run any `after` hooks which need to be run, and reset state to reflect that there are
|
|
153
|
+
* no more pending `after` hooks.
|
|
154
|
+
*
|
|
155
|
+
* ### 2. Fallback: Next lint run
|
|
156
|
+
*
|
|
157
|
+
* Before linting any file, the state of `pendingCount` is checked.
|
|
158
|
+
* If any `after` hooks are still pending, they are run immediately.
|
|
159
|
+
* They're run before the `context` objects in `createOnce` closures are updated to the next file,
|
|
160
|
+
* so they run with access to the old `context` object from the last file.
|
|
161
|
+
*
|
|
162
|
+
* This fallback should not be required, but it's included as "belt and braces", to handle if any language server
|
|
163
|
+
* or other environment running ESLint programmatically, does not pause a tick between linting runs.
|
|
164
|
+
*/
|
|
165
|
+
var AfterHooksState = class {
|
|
166
|
+
resetFunctions = [];
|
|
167
|
+
pendingStates = [];
|
|
168
|
+
pendingCount = 0;
|
|
169
|
+
lintFinishedCount = 0;
|
|
170
|
+
resetIsScheduled = !1;
|
|
171
|
+
sourceCode = null;
|
|
172
|
+
resetMicrotask = this.resetMicrotaskImpl.bind(this);
|
|
173
|
+
/**
|
|
174
|
+
* Register a function to run `after` hook for a rule, and reset state.
|
|
175
|
+
* @param reset - Function to run `after` hook and reset state
|
|
176
|
+
* @returns Index of rule
|
|
177
|
+
*/
|
|
178
|
+
registerResetFunction(reset) {
|
|
179
|
+
let { pendingStates } = this, index = pendingStates.length;
|
|
180
|
+
return pendingStates.push(0), this.resetFunctions.push(reset), index;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Register that a rule with `after` hook has completed linting a file.
|
|
184
|
+
* Called by `onCodePathEnd` CFG event handler which is added to visitor for rules with `after` hooks.
|
|
185
|
+
*
|
|
186
|
+
* If all rules with an `after` hook which needs to be run have completed linting the file, run all `after` hooks.
|
|
187
|
+
*/
|
|
188
|
+
ruleFinished() {
|
|
189
|
+
this.lintFinishedCount++, this.lintFinishedCount === this.pendingCount && this.reset(!1);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Call all reset functions where corresponding entry in `pendingStates` is `AFTER_HOOK_PENDING`.
|
|
193
|
+
* Should only be called when some `after` hooks are pending.
|
|
194
|
+
*
|
|
195
|
+
* @param ignoreErrors - `true` to catch and silently ignore any errors which occur in `after` hooks.
|
|
196
|
+
* `false` to throw them,
|
|
197
|
+
* @throws {unknown} If `ignoreErrors` is `false` and an error occurs in any `after` hooks.
|
|
198
|
+
*/
|
|
199
|
+
reset(ignoreErrors) {
|
|
200
|
+
this.pendingCount;
|
|
201
|
+
let { resetFunctions, pendingStates } = this, hooksLen = pendingStates.length, hasError = !1, error;
|
|
202
|
+
for (let i = 0; i < hooksLen; i++) if (pendingStates[i] !== 0) {
|
|
203
|
+
pendingStates[i] = 0;
|
|
204
|
+
try {
|
|
205
|
+
resetFunctions[i]();
|
|
206
|
+
} catch (e) {
|
|
207
|
+
hasError === !1 && (hasError = !0, error = e);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (this.pendingCount = 0, this.lintFinishedCount = 0, this.sourceCode = null, hasError === !0 && ignoreErrors === !1) throw error;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Schedule a microtask to run `reset` functions.
|
|
214
|
+
*/
|
|
215
|
+
scheduleReset() {
|
|
216
|
+
queueMicrotask(this.resetMicrotask), this.resetIsScheduled = !0;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Function which is scheduled as the cleanup microtask.
|
|
220
|
+
* `scheduleReset` uses `resetMicrotask` which is this method bound to `this`.
|
|
221
|
+
*/
|
|
222
|
+
resetMicrotaskImpl() {
|
|
223
|
+
this.resetIsScheduled = !1, this.pendingCount !== 0 && this.reset(!0);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* Convert a rule.
|
|
228
|
+
*
|
|
229
|
+
* The `rule` object passed in is mutated in-place.
|
|
230
|
+
*
|
|
231
|
+
* @param rule - Rule to convert
|
|
232
|
+
* @param afterHooksState - State of `after` hooks
|
|
233
|
+
* @throws {Error} If `rule` is not an object
|
|
234
|
+
*/
|
|
235
|
+
function convertRule(rule, afterHooksState) {
|
|
236
|
+
if (typeof rule != "object" || !rule) throw Error("Rule must be an object");
|
|
237
|
+
if ("create" in rule) return;
|
|
238
|
+
let context = null, visitor, beforeHook, setupAfterHook;
|
|
239
|
+
rule.create = (eslintContext) => {
|
|
240
|
+
context === null && ({context, visitor, beforeHook, setupAfterHook} = createContextAndVisitor(rule, afterHooksState));
|
|
241
|
+
let eslintFileContext = Object.getPrototypeOf(eslintContext);
|
|
242
|
+
if (setupAfterHook !== null) {
|
|
243
|
+
let { sourceCode } = eslintFileContext;
|
|
244
|
+
afterHooksState.sourceCode !== sourceCode && (afterHooksState.sourceCode = sourceCode, afterHooksState.pendingCount !== 0 && afterHooksState.reset(!0));
|
|
245
|
+
}
|
|
246
|
+
return Object.defineProperties(context, {
|
|
247
|
+
id: { value: eslintContext.id },
|
|
248
|
+
options: { value: eslintContext.options },
|
|
249
|
+
report: { value: eslintContext.report }
|
|
250
|
+
}), Object.setPrototypeOf(context, eslintFileContext), beforeHook !== null && beforeHook() === !1 ? EMPTY_VISITOR : (setupAfterHook !== null && (setupAfterHook(eslintFileContext.sourceCode.ast), afterHooksState.resetIsScheduled === !1 && afterHooksState.scheduleReset()), visitor);
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
const FILE_CONTEXT = Object.freeze({
|
|
254
|
+
get filename() {
|
|
255
|
+
throw Error("Cannot access `context.filename` in `createOnce`");
|
|
256
|
+
},
|
|
257
|
+
getFilename() {
|
|
258
|
+
throw Error("Cannot call `context.getFilename` in `createOnce`");
|
|
259
|
+
},
|
|
260
|
+
get physicalFilename() {
|
|
261
|
+
throw Error("Cannot access `context.physicalFilename` in `createOnce`");
|
|
262
|
+
},
|
|
263
|
+
getPhysicalFilename() {
|
|
264
|
+
throw Error("Cannot call `context.getPhysicalFilename` in `createOnce`");
|
|
265
|
+
},
|
|
266
|
+
get cwd() {
|
|
267
|
+
throw Error("Cannot access `context.cwd` in `createOnce`");
|
|
268
|
+
},
|
|
269
|
+
getCwd() {
|
|
270
|
+
throw Error("Cannot call `context.getCwd` in `createOnce`");
|
|
271
|
+
},
|
|
272
|
+
get sourceCode() {
|
|
273
|
+
throw Error("Cannot access `context.sourceCode` in `createOnce`");
|
|
274
|
+
},
|
|
275
|
+
getSourceCode() {
|
|
276
|
+
throw Error("Cannot call `context.getSourceCode` in `createOnce`");
|
|
277
|
+
},
|
|
278
|
+
get languageOptions() {
|
|
279
|
+
throw Error("Cannot access `context.languageOptions` in `createOnce`");
|
|
280
|
+
},
|
|
281
|
+
get settings() {
|
|
282
|
+
throw Error("Cannot access `context.settings` in `createOnce`");
|
|
283
|
+
},
|
|
284
|
+
extend(extension) {
|
|
285
|
+
return Object.freeze(Object.assign(Object.create(this), extension));
|
|
286
|
+
},
|
|
287
|
+
get parserOptions() {
|
|
288
|
+
throw Error("Cannot access `context.parserOptions` in `createOnce`");
|
|
289
|
+
},
|
|
290
|
+
get parserPath() {
|
|
291
|
+
throw Error("Cannot access `context.parserPath` in `createOnce`");
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
/**
|
|
295
|
+
* Call `createOnce` method of rule, and return `Context`, `Visitor`, and `beforeHook` (if any).
|
|
296
|
+
*
|
|
297
|
+
* @param rule - Rule with `createOnce` method
|
|
298
|
+
* @param afterHooksState - State of `after` hooks
|
|
299
|
+
* @returns Object with `context`, `visitor`, and `beforeHook` properties,
|
|
300
|
+
* and `setupAfterHook` function if visitor has an `after` hook
|
|
301
|
+
*/
|
|
302
|
+
function createContextAndVisitor(rule, afterHooksState) {
|
|
303
|
+
let { createOnce } = rule;
|
|
304
|
+
if (createOnce == null) throw Error("Rules must define either a `create` or `createOnce` method");
|
|
305
|
+
if (typeof createOnce != "function") throw Error("Rule `createOnce` property must be a function");
|
|
306
|
+
let context = Object.create(FILE_CONTEXT, {
|
|
307
|
+
id: {
|
|
308
|
+
value: null,
|
|
309
|
+
enumerable: !0,
|
|
310
|
+
configurable: !0
|
|
311
|
+
},
|
|
312
|
+
options: {
|
|
313
|
+
value: null,
|
|
314
|
+
enumerable: !0,
|
|
315
|
+
configurable: !0
|
|
316
|
+
},
|
|
317
|
+
report: {
|
|
318
|
+
value() {
|
|
319
|
+
throw Error("Cannot report errors in `createOnce`");
|
|
320
|
+
},
|
|
321
|
+
enumerable: !0,
|
|
322
|
+
configurable: !0
|
|
323
|
+
}
|
|
324
|
+
}), { before: beforeHook, after: afterHook, ...visitor } = createOnce.call(rule, context);
|
|
325
|
+
if (beforeHook === void 0) beforeHook = null;
|
|
326
|
+
else if (beforeHook !== null && typeof beforeHook != "function") throw Error("`before` property of visitor must be a function if defined");
|
|
327
|
+
let setupAfterHook = null;
|
|
328
|
+
if (afterHook != null) {
|
|
329
|
+
if (typeof afterHook != "function") throw Error("`after` property of visitor must be a function if defined");
|
|
330
|
+
let program = null, ruleIndex = afterHooksState.registerResetFunction(() => {
|
|
331
|
+
program = null, afterHook();
|
|
332
|
+
});
|
|
333
|
+
setupAfterHook = (ast) => {
|
|
334
|
+
program = ast, afterHooksState.pendingStates[ruleIndex] = 1, afterHooksState.pendingCount++;
|
|
335
|
+
};
|
|
336
|
+
let onCodePathEnd = visitor.onCodePathEnd;
|
|
337
|
+
visitor.onCodePathEnd = onCodePathEnd == null ? function(_codePath, node) {
|
|
338
|
+
node === program && afterHooksState.ruleFinished();
|
|
339
|
+
} : function(codePath, node) {
|
|
340
|
+
onCodePathEnd.call(this, codePath, node), node === program && afterHooksState.ruleFinished();
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
return {
|
|
344
|
+
context,
|
|
345
|
+
visitor,
|
|
346
|
+
beforeHook,
|
|
347
|
+
setupAfterHook
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
//#endregion
|
|
351
|
+
//#region src/effect/shared/tagged-values.ts
|
|
352
|
+
const equalityOperators$1 = /* @__PURE__ */ new Set([
|
|
353
|
+
"==",
|
|
354
|
+
"===",
|
|
355
|
+
"!=",
|
|
356
|
+
"!=="
|
|
357
|
+
]);
|
|
358
|
+
const broadEffectCatchMethods = /* @__PURE__ */ new Set([
|
|
359
|
+
"catch",
|
|
360
|
+
"catchAll",
|
|
361
|
+
"catchIf"
|
|
362
|
+
]);
|
|
363
|
+
const isStringLiteral = (node) => node?.type === "Literal" && typeof node.value === "string";
|
|
364
|
+
const isTagMember = (node) => node?.type === "MemberExpression" && (!node.computed && node.property.type === "Identifier" && node.property.name === "_tag" || node.computed && isStringLiteral(node.property) && node.property.value === "_tag");
|
|
365
|
+
const tagMemberFromComparison = (node) => {
|
|
366
|
+
if (!equalityOperators$1.has(node.operator)) return void 0;
|
|
367
|
+
if (isTagMember(node.left) && isStringLiteral(node.right)) return node.left;
|
|
368
|
+
if (isTagMember(node.right) && isStringLiteral(node.left)) return node.right;
|
|
369
|
+
};
|
|
370
|
+
const isBroadEffectCatchCall = (node) => node?.type === "CallExpression" && node.callee.type === "MemberExpression" && node.callee.object.type === "Identifier" && node.callee.object.name === "Effect" && !node.callee.computed && node.callee.property.type === "Identifier" && broadEffectCatchMethods.has(node.callee.property.name);
|
|
371
|
+
const isInsideBroadEffectHandler = (node) => {
|
|
372
|
+
let current = node.parent;
|
|
373
|
+
while (current !== null && current !== void 0) {
|
|
374
|
+
if (current.type === "ArrowFunctionExpression" || current.type === "FunctionExpression") return isBroadEffectCatchCall(current.parent) && current.parent.arguments.includes(current);
|
|
375
|
+
current = current.parent;
|
|
376
|
+
}
|
|
377
|
+
return false;
|
|
378
|
+
};
|
|
379
|
+
const isReasonTagMember = (node) => node.object.type === "MemberExpression" && (!node.object.computed && node.object.property.type === "Identifier" && node.object.property.name === "reason" || node.object.computed && isStringLiteral(node.object.property) && node.object.property.value === "reason");
|
|
380
|
+
const propertyName = (property) => {
|
|
381
|
+
if (!property.computed && property.key.type === "Identifier") return property.key.name;
|
|
382
|
+
if (property.key.type === "Literal" && typeof property.key.value === "string") return property.key.value;
|
|
383
|
+
};
|
|
384
|
+
const isMatchPatternObject = (node) => {
|
|
385
|
+
const call = node.parent;
|
|
386
|
+
if (call?.type !== "CallExpression" || !call.arguments.includes(node)) return false;
|
|
387
|
+
const callee = call.callee;
|
|
388
|
+
return callee.type === "MemberExpression" && callee.object.type === "Identifier" && callee.object.name === "Match" && !callee.computed && callee.property.type === "Identifier" && (callee.property.name === "when" || callee.property.name === "not");
|
|
389
|
+
};
|
|
390
|
+
//#endregion
|
|
391
|
+
//#region src/effect/rules/no-manual-effect-error-tag.ts
|
|
392
|
+
const noManualEffectErrorTagRule = defineRule({
|
|
393
|
+
meta: {
|
|
394
|
+
type: "problem",
|
|
395
|
+
docs: { description: "Use Effect tagged error handlers instead of manually branching on `_tag` in a catch handler." },
|
|
396
|
+
messages: {
|
|
397
|
+
tag: "Use Effect.catchTag or Effect.catchTags instead of manually discriminating a tagged error in a broad Effect catch handler.",
|
|
398
|
+
reason: "Use Effect.catchReason or Effect.catchReasons instead of manually discriminating a tagged `reason` in a broad Effect catch handler."
|
|
399
|
+
}
|
|
400
|
+
},
|
|
401
|
+
createOnce(context) {
|
|
402
|
+
return {
|
|
403
|
+
BinaryExpression(node) {
|
|
404
|
+
const tagMember = tagMemberFromComparison(node);
|
|
405
|
+
if (tagMember === void 0 || !isInsideBroadEffectHandler(node)) return;
|
|
406
|
+
context.report({
|
|
407
|
+
node,
|
|
408
|
+
messageId: isReasonTagMember(tagMember) ? "reason" : "tag"
|
|
409
|
+
});
|
|
410
|
+
},
|
|
411
|
+
SwitchStatement(node) {
|
|
412
|
+
if (!isTagMember(node.discriminant) || !isInsideBroadEffectHandler(node)) return;
|
|
413
|
+
context.report({
|
|
414
|
+
node,
|
|
415
|
+
messageId: isReasonTagMember(node.discriminant) ? "reason" : "tag"
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
//#endregion
|
|
422
|
+
//#region src/effect/rules/no-manual-tag-comparison.ts
|
|
423
|
+
const noManualTagComparisonRule = defineRule({
|
|
424
|
+
meta: {
|
|
425
|
+
type: "problem",
|
|
426
|
+
docs: { description: "Use Effect Match or Predicate helpers instead of manually branching on `_tag`." },
|
|
427
|
+
messages: {
|
|
428
|
+
manualComparison: "Use Match.tag/Match.tags for tagged-value branching, or Predicate.isTagged for a simple reusable predicate.",
|
|
429
|
+
manualSwitch: "Use Match.value(value).pipe(Match.tag/Match.tags/Match.tagsExhaustive) or the tagged enum `$match` helper instead of switching on `_tag`."
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
createOnce(context) {
|
|
433
|
+
return {
|
|
434
|
+
BinaryExpression(node) {
|
|
435
|
+
if (tagMemberFromComparison(node) === void 0 || isInsideBroadEffectHandler(node)) return;
|
|
436
|
+
context.report({
|
|
437
|
+
node,
|
|
438
|
+
messageId: "manualComparison"
|
|
439
|
+
});
|
|
440
|
+
},
|
|
441
|
+
SwitchStatement(node) {
|
|
442
|
+
if (!isTagMember(node.discriminant) || isInsideBroadEffectHandler(node)) return;
|
|
443
|
+
context.report({
|
|
444
|
+
node,
|
|
445
|
+
messageId: "manualSwitch"
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
//#endregion
|
|
452
|
+
//#region src/effect/rules/no-manual-tagged-construction.ts
|
|
453
|
+
/**
|
|
454
|
+
* Effect constructors whose input carries `_tag` as data, such as the error
|
|
455
|
+
* code of a `SystemError`. An object passed to one of them already goes
|
|
456
|
+
* through its Effect constructor.
|
|
457
|
+
*/
|
|
458
|
+
const TAG_INPUT_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
459
|
+
"CookiesErrorReason",
|
|
460
|
+
"HeaderParseErrorReason",
|
|
461
|
+
"MultipartErrorReason",
|
|
462
|
+
"SystemError",
|
|
463
|
+
"systemError"
|
|
464
|
+
]);
|
|
465
|
+
const calleeName = (callee) => {
|
|
466
|
+
if (callee.type === "Identifier") return callee.name;
|
|
467
|
+
if (callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier") return callee.property.name;
|
|
468
|
+
};
|
|
469
|
+
const isTagInputConstructorArgument = (node) => {
|
|
470
|
+
const call = node.parent;
|
|
471
|
+
if (call?.type !== "CallExpression" && call?.type !== "NewExpression" || !call.arguments.includes(node)) return false;
|
|
472
|
+
const name = calleeName(call.callee);
|
|
473
|
+
return name !== void 0 && TAG_INPUT_CONSTRUCTORS.has(name);
|
|
474
|
+
};
|
|
475
|
+
const noManualTaggedConstructionRule = defineRule({
|
|
476
|
+
meta: {
|
|
477
|
+
type: "problem",
|
|
478
|
+
docs: { description: "Construct tagged values with their existing Effect constructor instead of writing `_tag` manually." },
|
|
479
|
+
messages: { manualConstruction: "Use the existing Schema tagged `.make`, tagged class/error constructor, or Data.taggedEnum variant constructor instead of writing a literal `_tag` object." }
|
|
480
|
+
},
|
|
481
|
+
createOnce(context) {
|
|
482
|
+
return { ObjectExpression(node) {
|
|
483
|
+
if (isMatchPatternObject(node) || isTagInputConstructorArgument(node)) return;
|
|
484
|
+
const tag = node.properties.find((property) => property.type === "Property" && propertyName(property) === "_tag" && isStringLiteral(property.value));
|
|
485
|
+
if (tag !== void 0) context.report({
|
|
486
|
+
node: tag,
|
|
487
|
+
messageId: "manualConstruction"
|
|
488
|
+
});
|
|
489
|
+
} };
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
//#endregion
|
|
493
|
+
//#region src/effect/rules/no-service-constructor-imports.ts
|
|
494
|
+
const SERVICE_CONSTRUCTOR_NAME = /^make[A-Z]/u;
|
|
495
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
496
|
+
function isProjectLocalImport(source) {
|
|
497
|
+
return source.startsWith("./") || source.startsWith("../");
|
|
498
|
+
}
|
|
499
|
+
function getImportedName(specifier) {
|
|
500
|
+
if (specifier.imported.type === "Identifier") return specifier.imported.name;
|
|
501
|
+
return specifier.imported.value;
|
|
502
|
+
}
|
|
503
|
+
/** Keep dependency-bearing Effect service constructors local to their owning capability modules. */
|
|
504
|
+
const noServiceConstructorImportsRule = defineRule({
|
|
505
|
+
meta: {
|
|
506
|
+
type: "problem",
|
|
507
|
+
docs: { description: "Disallow project-local make<CapabilityName> imports outside test and spec files." },
|
|
508
|
+
messages: { 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." }
|
|
509
|
+
},
|
|
510
|
+
create(context) {
|
|
511
|
+
const isTestFile = TEST_FILE.test(context.filename.replaceAll("\\", "/"));
|
|
512
|
+
return { ImportDeclaration(node) {
|
|
513
|
+
if (isTestFile || !isProjectLocalImport(node.source.value)) return;
|
|
514
|
+
for (const specifier of node.specifiers) {
|
|
515
|
+
if (specifier.type !== "ImportSpecifier") continue;
|
|
516
|
+
const importedName = getImportedName(specifier);
|
|
517
|
+
if (!SERVICE_CONSTRUCTOR_NAME.test(importedName)) continue;
|
|
518
|
+
context.report({
|
|
519
|
+
node: specifier,
|
|
520
|
+
messageId: "serviceConstructorImport",
|
|
521
|
+
data: { name: importedName }
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
} };
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
//#endregion
|
|
528
|
+
//#region src/effect/rules/prefer-effect-match.ts
|
|
529
|
+
const equalityOperators = /* @__PURE__ */ new Set([
|
|
530
|
+
"==",
|
|
531
|
+
"===",
|
|
532
|
+
"!=",
|
|
533
|
+
"!=="
|
|
534
|
+
]);
|
|
535
|
+
//#endregion
|
|
536
|
+
//#region src/effect/index.ts
|
|
537
|
+
/** Opt-in Oxlint rules for Effect service and Layer architecture. */
|
|
538
|
+
const antiSlopEffectPlugin = eslintCompatPlugin({
|
|
539
|
+
meta: { name: "anti-slop-effect" },
|
|
540
|
+
rules: {
|
|
541
|
+
"no-manual-effect-error-tag": noManualEffectErrorTagRule,
|
|
542
|
+
"no-manual-tag-comparison": noManualTagComparisonRule,
|
|
543
|
+
"no-manual-tagged-construction": noManualTaggedConstructionRule,
|
|
544
|
+
"no-service-constructor-imports": noServiceConstructorImportsRule,
|
|
545
|
+
"prefer-effect-match": defineRule({
|
|
546
|
+
meta: {
|
|
547
|
+
type: "problem",
|
|
548
|
+
docs: { description: "Use Match from Effect for chained literal ternaries over the same value." },
|
|
549
|
+
messages: { preferMatch: "Use Match from Effect instead of a chained literal ternary." }
|
|
550
|
+
},
|
|
551
|
+
createOnce(context) {
|
|
552
|
+
const isLiteral = (node) => node.type === "Literal" || node.type === "TemplateLiteral" && node.expressions.length === 0;
|
|
553
|
+
const comparedValue = (node) => {
|
|
554
|
+
if (node.type !== "BinaryExpression" || !equalityOperators.has(node.operator)) return;
|
|
555
|
+
if (isLiteral(node.left)) return context.sourceCode.getText(node.right);
|
|
556
|
+
if (isLiteral(node.right)) return context.sourceCode.getText(node.left);
|
|
557
|
+
};
|
|
558
|
+
return { ConditionalExpression(node) {
|
|
559
|
+
if (node.parent?.type === "ConditionalExpression") return;
|
|
560
|
+
const value = comparedValue(node.test);
|
|
561
|
+
if (value === void 0) return;
|
|
562
|
+
let alternate = node.alternate;
|
|
563
|
+
let literalChecks = 1;
|
|
564
|
+
while (alternate.type === "ConditionalExpression") {
|
|
565
|
+
if (comparedValue(alternate.test) !== value) return;
|
|
566
|
+
literalChecks += 1;
|
|
567
|
+
alternate = alternate.alternate;
|
|
568
|
+
}
|
|
569
|
+
if (literalChecks > 1) context.report({
|
|
570
|
+
node,
|
|
571
|
+
messageId: "preferMatch"
|
|
572
|
+
});
|
|
573
|
+
} };
|
|
574
|
+
}
|
|
575
|
+
})
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
//#endregion
|
|
579
|
+
export { antiSlopEffectPlugin as default };
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { OxlintConfig } from "oxlint";
|
|
2
2
|
//#region presets/lint/vitest.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The files that Vitest runs as tests by default. The preset applies its rules only to these files.
|
|
5
|
+
* To change the files or a rule, use the preset in an override of your own instead of `extends`:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import vitest, { testFiles } from "adamantite/lint/vitest"
|
|
9
|
+
*
|
|
10
|
+
* export default defineConfig({
|
|
11
|
+
* overrides: [{ files: testFiles, plugins: vitest.plugins, rules: { ...vitest.rules } }],
|
|
12
|
+
* })
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare const testFiles: string[];
|
|
3
16
|
declare const config: OxlintConfig;
|
|
4
17
|
//#endregion
|
|
5
18
|
export { config as default };
|