oxlint-plugin-effect 0.2.0 → 0.2.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/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/plugin.d.ts +5 -0
- package/dist/plugin.js +18 -0
- package/dist/presets/core.d.ts +43 -0
- package/dist/presets/core.js +43 -0
- package/dist/presets/effect-native.d.ts +28 -0
- package/dist/presets/effect-native.js +28 -0
- package/dist/presets/full.d.ts +60 -0
- package/dist/presets/full.js +60 -0
- package/dist/presets/functional.d.ts +21 -0
- package/dist/presets/functional.js +21 -0
- package/dist/presets/index.d.ts +13 -0
- package/dist/presets/index.js +18 -0
- package/dist/presets/strict.d.ts +69 -0
- package/dist/presets/strict.js +69 -0
- package/dist/presets/v3.d.ts +15 -0
- package/dist/presets/v3.js +15 -0
- package/dist/rules/_effect-context.d.ts +19 -0
- package/dist/rules/_effect-context.js +22 -0
- package/dist/rules/index.d.ts +66 -0
- package/dist/rules/index.js +124 -0
- package/dist/rules/no-arrow-ladder.d.ts +6 -0
- package/dist/rules/no-arrow-ladder.js +61 -0
- package/dist/rules/no-async-function.d.ts +6 -0
- package/dist/rules/no-async-function.js +46 -0
- package/dist/rules/no-catch-all-to-map-error.d.ts +6 -0
- package/dist/rules/no-catch-all-to-map-error.js +67 -0
- package/dist/rules/no-effect-as.d.ts +6 -0
- package/dist/rules/no-effect-as.js +16 -0
- package/dist/rules/no-effect-async.d.ts +6 -0
- package/dist/rules/no-effect-async.js +16 -0
- package/dist/rules/no-effect-bind.d.ts +6 -0
- package/dist/rules/no-effect-bind.js +16 -0
- package/dist/rules/no-effect-do.d.ts +6 -0
- package/dist/rules/no-effect-do.js +16 -0
- package/dist/rules/no-effect-fn-generator.d.ts +6 -0
- package/dist/rules/no-effect-fn-generator.js +30 -0
- package/dist/rules/no-effect-gen-adapter.d.ts +6 -0
- package/dist/rules/no-effect-gen-adapter.js +30 -0
- package/dist/rules/no-effect-map-flatten.d.ts +6 -0
- package/dist/rules/no-effect-map-flatten.js +53 -0
- package/dist/rules/no-effect-map-void.d.ts +6 -0
- package/dist/rules/no-effect-map-void.js +40 -0
- package/dist/rules/no-effect-never.d.ts +6 -0
- package/dist/rules/no-effect-never.js +16 -0
- package/dist/rules/no-effect-orElse-ladder.d.ts +6 -0
- package/dist/rules/no-effect-orElse-ladder.js +53 -0
- package/dist/rules/no-effect-succeed-string.d.ts +6 -0
- package/dist/rules/no-effect-succeed-string.js +30 -0
- package/dist/rules/no-effect-succeed-variable.d.ts +6 -0
- package/dist/rules/no-effect-succeed-variable.js +30 -0
- package/dist/rules/no-effect-succeed-void.d.ts +6 -0
- package/dist/rules/no-effect-succeed-void.js +33 -0
- package/dist/rules/no-effect-sync-console.d.ts +6 -0
- package/dist/rules/no-effect-sync-console.js +63 -0
- package/dist/rules/no-effect-sync-wrapper.d.ts +6 -0
- package/dist/rules/no-effect-sync-wrapper.js +37 -0
- package/dist/rules/no-effect-type-alias.d.ts +6 -0
- package/dist/rules/no-effect-type-alias.js +52 -0
- package/dist/rules/no-effect-wrapper-alias.d.ts +6 -0
- package/dist/rules/no-effect-wrapper-alias.js +69 -0
- package/dist/rules/no-extends-native-error.d.ts +6 -0
- package/dist/rules/no-extends-native-error.js +41 -0
- package/dist/rules/no-flatmap-ladder.d.ts +6 -0
- package/dist/rules/no-flatmap-ladder.js +48 -0
- package/dist/rules/no-fromnullable-coalesce.d.ts +6 -0
- package/dist/rules/no-fromnullable-coalesce.js +36 -0
- package/dist/rules/no-global-error-in-catch.d.ts +6 -0
- package/dist/rules/no-global-error-in-catch.js +75 -0
- package/dist/rules/no-global-error-in-failure.d.ts +6 -0
- package/dist/rules/no-global-error-in-failure.js +54 -0
- package/dist/rules/no-globals.d.ts +6 -0
- package/dist/rules/no-globals.js +164 -0
- package/dist/rules/no-if-statement.d.ts +6 -0
- package/dist/rules/no-if-statement.js +18 -0
- package/dist/rules/no-iife-wrapper.d.ts +6 -0
- package/dist/rules/no-iife-wrapper.js +37 -0
- package/dist/rules/no-inline-provide.d.ts +6 -0
- package/dist/rules/no-inline-provide.js +31 -0
- package/dist/rules/no-instanceof-schema.d.ts +6 -0
- package/dist/rules/no-instanceof-schema.js +35 -0
- package/dist/rules/no-manual-effect-channels.d.ts +6 -0
- package/dist/rules/no-manual-effect-channels.js +40 -0
- package/dist/rules/no-match-effect-branch.d.ts +6 -0
- package/dist/rules/no-match-effect-branch.js +64 -0
- package/dist/rules/no-match-void-branch.d.ts +6 -0
- package/dist/rules/no-match-void-branch.js +50 -0
- package/dist/rules/no-multiple-effect-provide.d.ts +6 -0
- package/dist/rules/no-multiple-effect-provide.js +45 -0
- package/dist/rules/no-nested-effect-call.d.ts +6 -0
- package/dist/rules/no-nested-effect-call.js +97 -0
- package/dist/rules/no-nested-effect-gen.d.ts +6 -0
- package/dist/rules/no-nested-effect-gen.js +46 -0
- package/dist/rules/no-nested-pipe.d.ts +6 -0
- package/dist/rules/no-nested-pipe.js +38 -0
- package/dist/rules/no-new-error.d.ts +6 -0
- package/dist/rules/no-new-error.js +39 -0
- package/dist/rules/no-new-promise.d.ts +6 -0
- package/dist/rules/no-new-promise.js +38 -0
- package/dist/rules/no-node-builtin-import.d.ts +6 -0
- package/dist/rules/no-node-builtin-import.js +61 -0
- package/dist/rules/no-option-as.d.ts +6 -0
- package/dist/rules/no-option-as.js +16 -0
- package/dist/rules/no-option-boolean-normalization.d.ts +6 -0
- package/dist/rules/no-option-boolean-normalization.js +50 -0
- package/dist/rules/no-positional-log-error.d.ts +6 -0
- package/dist/rules/no-positional-log-error.js +52 -0
- package/dist/rules/no-redundant-schema-tag-identifier.d.ts +6 -0
- package/dist/rules/no-redundant-schema-tag-identifier.js +46 -0
- package/dist/rules/no-return-in-arrow.d.ts +6 -0
- package/dist/rules/no-return-in-arrow.js +41 -0
- package/dist/rules/no-return-nullish.d.ts +6 -0
- package/dist/rules/no-return-nullish.js +47 -0
- package/dist/rules/no-run-in-effect-gen.d.ts +6 -0
- package/dist/rules/no-run-in-effect-gen.js +48 -0
- package/dist/rules/no-runtime-run-fork.d.ts +6 -0
- package/dist/rules/no-runtime-run-fork.js +19 -0
- package/dist/rules/no-schema-struct-with-tag.d.ts +6 -0
- package/dist/rules/no-schema-struct-with-tag.js +48 -0
- package/dist/rules/no-schema-union-of-literals.d.ts +6 -0
- package/dist/rules/no-schema-union-of-literals.js +35 -0
- package/dist/rules/no-string-sentinel-const.d.ts +6 -0
- package/dist/rules/no-string-sentinel-const.js +38 -0
- package/dist/rules/no-switch-statement.d.ts +6 -0
- package/dist/rules/no-switch-statement.js +16 -0
- package/dist/rules/no-ternary.d.ts +6 -0
- package/dist/rules/no-ternary.js +30 -0
- package/dist/rules/no-throw-statement.d.ts +6 -0
- package/dist/rules/no-throw-statement.js +34 -0
- package/dist/rules/no-try-catch.d.ts +6 -0
- package/dist/rules/no-try-catch.js +34 -0
- package/dist/rules/no-unnecessary-arrow-block.d.ts +6 -0
- package/dist/rules/no-unnecessary-arrow-block.js +34 -0
- package/dist/rules/no-unnecessary-effect-gen.d.ts +6 -0
- package/dist/rules/no-unnecessary-effect-gen.js +35 -0
- package/dist/rules/no-unnecessary-pipe-chain.d.ts +6 -0
- package/dist/rules/no-unnecessary-pipe-chain.js +36 -0
- package/dist/rules/no-unnecessary-pipe.d.ts +6 -0
- package/dist/rules/no-unnecessary-pipe.js +29 -0
- package/dist/vendor/effect-oxlint/AST.d.ts +199 -0
- package/dist/vendor/effect-oxlint/AST.js +214 -0
- package/dist/vendor/effect-oxlint/Comment.d.ts +55 -0
- package/dist/vendor/effect-oxlint/Comment.js +67 -0
- package/dist/vendor/effect-oxlint/Diagnostic.d.ts +86 -0
- package/dist/vendor/effect-oxlint/Diagnostic.js +115 -0
- package/dist/vendor/effect-oxlint/Plugin.d.ts +38 -0
- package/dist/vendor/effect-oxlint/Plugin.js +45 -0
- package/dist/vendor/effect-oxlint/Rule.d.ts +218 -0
- package/dist/vendor/effect-oxlint/Rule.js +309 -0
- package/dist/vendor/effect-oxlint/RuleContext.d.ts +77 -0
- package/dist/vendor/effect-oxlint/RuleContext.js +74 -0
- package/dist/vendor/effect-oxlint/Scope.d.ts +100 -0
- package/dist/vendor/effect-oxlint/Scope.js +110 -0
- package/dist/vendor/effect-oxlint/SourceCode.d.ts +180 -0
- package/dist/vendor/effect-oxlint/SourceCode.js +203 -0
- package/dist/vendor/effect-oxlint/Testing.d.ts +510 -0
- package/dist/vendor/effect-oxlint/Testing.js +963 -0
- package/dist/vendor/effect-oxlint/Token.d.ts +98 -0
- package/dist/vendor/effect-oxlint/Token.js +103 -0
- package/dist/vendor/effect-oxlint/Visitor.d.ts +166 -0
- package/dist/vendor/effect-oxlint/Visitor.js +138 -0
- package/dist/vendor/effect-oxlint/index.d.ts +13 -0
- package/dist/vendor/effect-oxlint/index.js +12 -0
- package/package.json +24 -5
- package/.effect-lsp.json +0 -60
- package/.oxlintrc.json +0 -33
- package/CHANGELOG.md +0 -55
- package/scripts/add-rule.ts +0 -87
- package/scripts/codegen.ts +0 -108
- package/src/index.ts +0 -9
- package/src/plugin.ts +0 -16
- package/src/presets/core.ts +0 -47
- package/src/presets/effect-native.ts +0 -34
- package/src/presets/full.ts +0 -70
- package/src/presets/functional.ts +0 -18
- package/src/presets/index.ts +0 -5
- package/src/presets/strict.ts +0 -77
- package/src/rules/_effect-context.ts +0 -28
- package/src/rules/index.ts +0 -72
- package/src/rules/no-arrow-ladder.ts +0 -70
- package/src/rules/no-async-function.ts +0 -47
- package/src/rules/no-catch-all-to-map-error.ts +0 -90
- package/src/rules/no-effect-as.ts +0 -14
- package/src/rules/no-effect-async.ts +0 -14
- package/src/rules/no-effect-bind.ts +0 -13
- package/src/rules/no-effect-do.ts +0 -14
- package/src/rules/no-effect-fn-generator.ts +0 -58
- package/src/rules/no-effect-gen-adapter.ts +0 -51
- package/src/rules/no-effect-map-flatten.ts +0 -82
- package/src/rules/no-effect-map-void.ts +0 -80
- package/src/rules/no-effect-never.ts +0 -14
- package/src/rules/no-effect-orElse-ladder.ts +0 -79
- package/src/rules/no-effect-succeed-string.ts +0 -52
- package/src/rules/no-effect-succeed-variable.ts +0 -50
- package/src/rules/no-effect-succeed-void.ts +0 -63
- package/src/rules/no-effect-sync-console.ts +0 -91
- package/src/rules/no-effect-sync-wrapper.ts +0 -67
- package/src/rules/no-effect-type-alias.ts +0 -71
- package/src/rules/no-effect-wrapper-alias.ts +0 -95
- package/src/rules/no-extends-native-error.ts +0 -54
- package/src/rules/no-flatmap-ladder.ts +0 -77
- package/src/rules/no-fromnullable-coalesce.ts +0 -62
- package/src/rules/no-global-error-in-catch.ts +0 -104
- package/src/rules/no-global-error-in-failure.ts +0 -83
- package/src/rules/no-globals.ts +0 -178
- package/src/rules/no-if-statement.ts +0 -16
- package/src/rules/no-iife-wrapper.ts +0 -51
- package/src/rules/no-inline-provide.ts +0 -41
- package/src/rules/no-instanceof-schema.ts +0 -42
- package/src/rules/no-manual-effect-channels.ts +0 -58
- package/src/rules/no-match-effect-branch.ts +0 -82
- package/src/rules/no-match-void-branch.ts +0 -72
- package/src/rules/no-multiple-effect-provide.ts +0 -75
- package/src/rules/no-nested-effect-call.ts +0 -57
- package/src/rules/no-nested-effect-gen.ts +0 -43
- package/src/rules/no-nested-pipe.ts +0 -73
- package/src/rules/no-new-error.ts +0 -53
- package/src/rules/no-new-promise.ts +0 -50
- package/src/rules/no-node-builtin-import.ts +0 -68
- package/src/rules/no-option-as.ts +0 -13
- package/src/rules/no-option-boolean-normalization.ts +0 -88
- package/src/rules/no-positional-log-error.ts +0 -76
- package/src/rules/no-redundant-schema-tag-identifier.ts +0 -62
- package/src/rules/no-return-in-arrow.ts +0 -76
- package/src/rules/no-return-nullish.ts +0 -80
- package/src/rules/no-run-in-effect-gen.ts +0 -66
- package/src/rules/no-runtime-run-fork.ts +0 -14
- package/src/rules/no-schema-struct-with-tag.ts +0 -64
- package/src/rules/no-schema-union-of-literals.ts +0 -48
- package/src/rules/no-string-sentinel-const.ts +0 -49
- package/src/rules/no-switch-statement.ts +0 -13
- package/src/rules/no-ternary.ts +0 -30
- package/src/rules/no-throw-statement.ts +0 -39
- package/src/rules/no-try-catch.ts +0 -39
- package/src/rules/no-unnecessary-arrow-block.ts +0 -51
- package/src/rules/no-unnecessary-effect-gen.ts +0 -83
- package/src/rules/no-unnecessary-pipe-chain.ts +0 -47
- package/src/rules/no-unnecessary-pipe.ts +0 -45
- package/src/vendor/effect-oxlint/AST.ts +0 -516
- package/src/vendor/effect-oxlint/Comment.ts +0 -86
- package/src/vendor/effect-oxlint/Diagnostic.ts +0 -199
- package/src/vendor/effect-oxlint/Plugin.ts +0 -71
- package/src/vendor/effect-oxlint/Rule.ts +0 -548
- package/src/vendor/effect-oxlint/RuleContext.ts +0 -144
- package/src/vendor/effect-oxlint/Scope.ts +0 -177
- package/src/vendor/effect-oxlint/SourceCode.ts +0 -377
- package/src/vendor/effect-oxlint/Testing.ts +0 -1227
- package/src/vendor/effect-oxlint/Token.ts +0 -131
- package/src/vendor/effect-oxlint/Visitor.ts +0 -287
- package/src/vendor/effect-oxlint/index.ts +0 -88
- package/tests/ban-rules.test.ts +0 -68
- package/tests/context-rules.test.ts +0 -263
- package/tests/pattern-rules.test.ts +0 -247
- package/tsconfig.json +0 -15
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import * as Arr from "effect/Array";
|
|
3
|
+
import { dual } from "effect/Function";
|
|
4
|
+
import * as Option from "effect/Option";
|
|
5
|
+
import * as P from "effect/Predicate";
|
|
6
|
+
import * as Result from "effect/Result";
|
|
7
|
+
//#region src/vendor/effect-oxlint/Diagnostic.ts
|
|
8
|
+
var Diagnostic_exports = /* @__PURE__ */ __exportAll({
|
|
9
|
+
composeFixes: () => composeFixes,
|
|
10
|
+
fromId: () => fromId,
|
|
11
|
+
insertAfter: () => insertAfter,
|
|
12
|
+
insertBefore: () => insertBefore,
|
|
13
|
+
make: () => make,
|
|
14
|
+
removeFix: () => removeFix,
|
|
15
|
+
replaceText: () => replaceText,
|
|
16
|
+
withFix: () => withFix,
|
|
17
|
+
withSuggestions: () => withSuggestions
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Create a diagnostic with a message and node location.
|
|
21
|
+
*
|
|
22
|
+
* @since 0.1.0
|
|
23
|
+
*/
|
|
24
|
+
const make = (opts) => ({
|
|
25
|
+
node: opts.node,
|
|
26
|
+
message: opts.message,
|
|
27
|
+
data: opts.data
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Create a diagnostic using a `messageId` from `meta.messages`.
|
|
31
|
+
*
|
|
32
|
+
* @since 0.1.0
|
|
33
|
+
*/
|
|
34
|
+
const fromId = (opts) => ({
|
|
35
|
+
node: opts.node,
|
|
36
|
+
messageId: opts.messageId,
|
|
37
|
+
data: opts.data
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Attach an autofix function to a diagnostic.
|
|
41
|
+
*
|
|
42
|
+
* @since 0.1.0
|
|
43
|
+
*/
|
|
44
|
+
const withFix = dual(2, (diagnostic, fix) => ({
|
|
45
|
+
...diagnostic,
|
|
46
|
+
fix
|
|
47
|
+
}));
|
|
48
|
+
/**
|
|
49
|
+
* Attach suggestion fixes to a diagnostic.
|
|
50
|
+
*
|
|
51
|
+
* @since 0.1.0
|
|
52
|
+
*/
|
|
53
|
+
const withSuggestions = dual(2, (diagnostic, suggestions) => ({
|
|
54
|
+
...diagnostic,
|
|
55
|
+
suggest: Array.from(suggestions)
|
|
56
|
+
}));
|
|
57
|
+
/**
|
|
58
|
+
* Composable fix operations.
|
|
59
|
+
*
|
|
60
|
+
* Each function returns a `FixFn` that can be passed to `withFix`
|
|
61
|
+
* or composed via `composeFixes`.
|
|
62
|
+
*
|
|
63
|
+
* @since 0.1.0
|
|
64
|
+
*/
|
|
65
|
+
/**
|
|
66
|
+
* Replace the text of a node or token.
|
|
67
|
+
*
|
|
68
|
+
* @since 0.1.0
|
|
69
|
+
*/
|
|
70
|
+
const replaceText = (nodeOrToken, text) => (fixer) => fixer.replaceText(nodeOrToken, text);
|
|
71
|
+
/**
|
|
72
|
+
* Insert text before a node or token.
|
|
73
|
+
*
|
|
74
|
+
* @since 0.1.0
|
|
75
|
+
*/
|
|
76
|
+
const insertBefore = (nodeOrToken, text) => (fixer) => fixer.insertTextBefore(nodeOrToken, text);
|
|
77
|
+
/**
|
|
78
|
+
* Insert text after a node or token.
|
|
79
|
+
*
|
|
80
|
+
* @since 0.1.0
|
|
81
|
+
*/
|
|
82
|
+
const insertAfter = (nodeOrToken, text) => (fixer) => fixer.insertTextAfter(nodeOrToken, text);
|
|
83
|
+
/**
|
|
84
|
+
* Remove a node or token.
|
|
85
|
+
*
|
|
86
|
+
* @since 0.1.0
|
|
87
|
+
*/
|
|
88
|
+
const removeFix = (nodeOrToken) => (fixer) => fixer.remove(nodeOrToken);
|
|
89
|
+
/** @internal Type guard for an oxlint Fix value (has `range` and `text`). */
|
|
90
|
+
const isFix = (value) => P.isObject(value) && "range" in value && "text" in value;
|
|
91
|
+
/**
|
|
92
|
+
* Extract fixes from a single `FixFn` result.
|
|
93
|
+
*
|
|
94
|
+
* The parameter is typed as `unknown` because oxlint's `FixFn` returns
|
|
95
|
+
* a nullable union (`Fix | Array<Fix | null> | IterableIterator<…> | null`).
|
|
96
|
+
* We guard at the boundary instead of mirroring the nullable upstream type.
|
|
97
|
+
*
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
const extractFixes = (result) => {
|
|
101
|
+
if (result === null || result === void 0) return [];
|
|
102
|
+
if (isFix(result)) return [result];
|
|
103
|
+
if (!P.isIterable(result)) return [];
|
|
104
|
+
return Arr.filterMap(Array.from(result), (item) => Option.fromNullishOr(item).pipe(Option.filter(isFix), Result.fromOption(() => void 0)));
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Compose multiple fix functions into one.
|
|
108
|
+
*
|
|
109
|
+
* All individual fixes are collected into a single array result.
|
|
110
|
+
*
|
|
111
|
+
* @since 0.1.0
|
|
112
|
+
*/
|
|
113
|
+
const composeFixes = (...fixes) => (fixer) => Arr.flatMap(fixes, (fn) => Array.from(extractFixes(fn(fixer))));
|
|
114
|
+
//#endregion
|
|
115
|
+
export { Diagnostic_exports, composeFixes, fromId, insertAfter, insertBefore, make, removeFix, replaceText, withFix, withSuggestions };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { CreateRule, Plugin as OxlintPlugin } from "@oxlint/plugins";
|
|
2
|
+
|
|
3
|
+
//#region src/vendor/effect-oxlint/Plugin.d.ts
|
|
4
|
+
declare namespace Plugin_d_exports {
|
|
5
|
+
export { OxlintPlugin as Plugin, define, merge };
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Define a typed oxlint plugin from a name and rule map.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { Plugin, Rule } from 'effect-oxlint'
|
|
13
|
+
*
|
|
14
|
+
* export default Plugin.define({
|
|
15
|
+
* name: 'my-effect-rules',
|
|
16
|
+
* rules: {
|
|
17
|
+
* 'no-throw-in-gen': myThrowRule,
|
|
18
|
+
* 'prefer-effect-fn': myFnRule,
|
|
19
|
+
* }
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @since 0.1.0
|
|
24
|
+
*/
|
|
25
|
+
declare const define: (config: {
|
|
26
|
+
readonly name: string;
|
|
27
|
+
readonly rules: Record<string, CreateRule>;
|
|
28
|
+
}) => OxlintPlugin;
|
|
29
|
+
/**
|
|
30
|
+
* Merge multiple plugins into one.
|
|
31
|
+
*
|
|
32
|
+
* If two plugins define a rule with the same name, the later one wins.
|
|
33
|
+
*
|
|
34
|
+
* @since 0.1.0
|
|
35
|
+
*/
|
|
36
|
+
declare const merge: (...plugins: ReadonlyArray<OxlintPlugin>) => OxlintPlugin;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { type OxlintPlugin as Plugin, Plugin_d_exports, define, merge };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import * as Arr from "effect/Array";
|
|
3
|
+
//#region src/vendor/effect-oxlint/Plugin.ts
|
|
4
|
+
var Plugin_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
define: () => define,
|
|
6
|
+
merge: () => merge
|
|
7
|
+
});
|
|
8
|
+
/**
|
|
9
|
+
* Define a typed oxlint plugin from a name and rule map.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { Plugin, Rule } from 'effect-oxlint'
|
|
14
|
+
*
|
|
15
|
+
* export default Plugin.define({
|
|
16
|
+
* name: 'my-effect-rules',
|
|
17
|
+
* rules: {
|
|
18
|
+
* 'no-throw-in-gen': myThrowRule,
|
|
19
|
+
* 'prefer-effect-fn': myFnRule,
|
|
20
|
+
* }
|
|
21
|
+
* })
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @since 0.1.0
|
|
25
|
+
*/
|
|
26
|
+
const define = (config) => ({
|
|
27
|
+
meta: { name: config.name },
|
|
28
|
+
rules: config.rules
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* Merge multiple plugins into one.
|
|
32
|
+
*
|
|
33
|
+
* If two plugins define a rule with the same name, the later one wins.
|
|
34
|
+
*
|
|
35
|
+
* @since 0.1.0
|
|
36
|
+
*/
|
|
37
|
+
const merge = (...plugins) => ({
|
|
38
|
+
meta: { name: Arr.join(Arr.map(plugins, (p) => p.meta?.name ?? "unknown"), "+") },
|
|
39
|
+
rules: Arr.reduce(plugins, {}, (acc, p) => ({
|
|
40
|
+
...acc,
|
|
41
|
+
...p.rules
|
|
42
|
+
}))
|
|
43
|
+
});
|
|
44
|
+
//#endregion
|
|
45
|
+
export { Plugin_exports, define, merge };
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { RuleContext } from "./RuleContext.js";
|
|
2
|
+
import { EffectVisitor } from "./Visitor.js";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
import { CreateRule, RuleDocs, RuleMeta } from "@oxlint/plugins";
|
|
6
|
+
|
|
7
|
+
//#region src/vendor/effect-oxlint/Rule.d.ts
|
|
8
|
+
declare namespace Rule_d_exports {
|
|
9
|
+
export { BanSpec, EffectVersion, RuleConfig, banCallOf, banImport, banMember, banMultiple, banNewExpr, banStatement, define, meta };
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Configuration object for `Rule.define`.
|
|
13
|
+
*
|
|
14
|
+
* @since 0.1.0
|
|
15
|
+
*/
|
|
16
|
+
interface RuleConfig<Options = undefined> {
|
|
17
|
+
/** Rule name (used for tracing spans). */
|
|
18
|
+
readonly name: string;
|
|
19
|
+
/** Oxlint rule metadata. */
|
|
20
|
+
readonly meta: RuleMeta;
|
|
21
|
+
/**
|
|
22
|
+
* Optional Schema for rule options.
|
|
23
|
+
*
|
|
24
|
+
* When provided, the first element of the raw JSON options array
|
|
25
|
+
* is decoded at `create` time against this schema.
|
|
26
|
+
*/
|
|
27
|
+
readonly options?: Schema.Decoder<Options> | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* The create generator.
|
|
30
|
+
*
|
|
31
|
+
* Receives decoded options and returns an `EffectVisitor`.
|
|
32
|
+
* Runs inside an Effect context where `RuleContext` is available.
|
|
33
|
+
*
|
|
34
|
+
* May `yield* Ref.make(...)` for state, `yield* RuleContext` for
|
|
35
|
+
* context access, and return a visitor built with `Visitor.*` helpers.
|
|
36
|
+
*/
|
|
37
|
+
readonly create: (options: Options) => Effect.gen.Return<EffectVisitor, never, RuleContext>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Define an Effect-first oxlint lint rule.
|
|
41
|
+
*
|
|
42
|
+
* The `create` generator runs once per file via `Effect.runSync`.
|
|
43
|
+
* Each visitor handler is also executed via `Effect.runSync` per node.
|
|
44
|
+
* `Ref`-based state created in `create` persists across handler calls
|
|
45
|
+
* via closure.
|
|
46
|
+
*
|
|
47
|
+
* `Effect.runSync` is used here at the runtime boundary — the bridge
|
|
48
|
+
* between oxlint's synchronous plugin API and our Effect world.
|
|
49
|
+
*
|
|
50
|
+
* @since 0.1.0
|
|
51
|
+
*/
|
|
52
|
+
declare const define: <Options = undefined>(config: RuleConfig<Options>) => CreateRule;
|
|
53
|
+
/**
|
|
54
|
+
* Which Effect version a rule applies to.
|
|
55
|
+
*
|
|
56
|
+
* Stored on `meta.docs.effectVersion` so preset authors can filter rules
|
|
57
|
+
* per project. Default `both`, meaning the rule is version-agnostic.
|
|
58
|
+
*
|
|
59
|
+
* @since 0.2.0
|
|
60
|
+
*/
|
|
61
|
+
type EffectVersion = 'v3' | 'v4' | 'both';
|
|
62
|
+
/**
|
|
63
|
+
* Build `RuleMeta` with sensible defaults.
|
|
64
|
+
*
|
|
65
|
+
* @since 0.1.0
|
|
66
|
+
*/
|
|
67
|
+
declare const meta: (opts: {
|
|
68
|
+
readonly type: "problem" | "suggestion" | "layout";
|
|
69
|
+
readonly description: string;
|
|
70
|
+
readonly fixable?: "code" | "whitespace" | undefined;
|
|
71
|
+
readonly hasSuggestions?: boolean | undefined;
|
|
72
|
+
readonly messages?: Record<string, string> | undefined;
|
|
73
|
+
readonly docs?: RuleDocs | undefined;
|
|
74
|
+
readonly effectVersion?: EffectVersion | undefined;
|
|
75
|
+
}) => RuleMeta;
|
|
76
|
+
/**
|
|
77
|
+
* Create a rule that bans `obj.prop` member expression access.
|
|
78
|
+
*
|
|
79
|
+
* Replaces the common `memberExprRule` utility pattern.
|
|
80
|
+
*
|
|
81
|
+
* @since 0.1.0
|
|
82
|
+
*/
|
|
83
|
+
declare const banMember: (obj: string, prop: string | ReadonlyArray<string>, opts: {
|
|
84
|
+
readonly message: string;
|
|
85
|
+
readonly meta?: {
|
|
86
|
+
readonly type?: "problem" | "suggestion";
|
|
87
|
+
readonly effectVersion?: EffectVersion;
|
|
88
|
+
} | undefined;
|
|
89
|
+
}) => CreateRule;
|
|
90
|
+
/**
|
|
91
|
+
* Create a rule that bans imports matching a source string or predicate.
|
|
92
|
+
*
|
|
93
|
+
* Replaces the common `importRule` utility pattern.
|
|
94
|
+
*
|
|
95
|
+
* @since 0.1.0
|
|
96
|
+
*/
|
|
97
|
+
declare const banImport: (source: string | ((source: string) => boolean), opts: {
|
|
98
|
+
readonly message: string;
|
|
99
|
+
readonly meta?: {
|
|
100
|
+
readonly type?: "problem" | "suggestion";
|
|
101
|
+
readonly effectVersion?: EffectVersion;
|
|
102
|
+
} | undefined;
|
|
103
|
+
}) => CreateRule;
|
|
104
|
+
/**
|
|
105
|
+
* Create a rule that bans bare identifier call expressions.
|
|
106
|
+
*
|
|
107
|
+
* Matches `CallExpression` nodes whose callee is an identifier in
|
|
108
|
+
* the given list (e.g. `fetch()`, `useState()`, `readFileSync()`).
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* // Ban a single call
|
|
113
|
+
* Rule.banCallOf('fetch', { message: 'Use Effect HTTP client' })
|
|
114
|
+
*
|
|
115
|
+
* // Ban multiple calls
|
|
116
|
+
* Rule.banCallOf(['useState', 'useEffect'], { message: 'Use Effect' })
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @since 0.2.0
|
|
120
|
+
*/
|
|
121
|
+
declare const banCallOf: (name: string | ReadonlyArray<string>, opts: {
|
|
122
|
+
readonly message: string;
|
|
123
|
+
readonly meta?: {
|
|
124
|
+
readonly type?: "problem" | "suggestion";
|
|
125
|
+
readonly effectVersion?: EffectVersion;
|
|
126
|
+
} | undefined;
|
|
127
|
+
}) => CreateRule;
|
|
128
|
+
/**
|
|
129
|
+
* Create a rule that bans `new` expressions with the given callee name.
|
|
130
|
+
*
|
|
131
|
+
* Matches `NewExpression` nodes whose callee is an identifier in
|
|
132
|
+
* the given list (e.g. `new Date()`, `new Error()`).
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* // Ban a single constructor
|
|
137
|
+
* Rule.banNewExpr('Date', { message: 'Use Clock service' })
|
|
138
|
+
*
|
|
139
|
+
* // Ban multiple constructors
|
|
140
|
+
* Rule.banNewExpr(['Error', 'TypeError'], { message: 'Use tagged errors' })
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @since 0.2.0
|
|
144
|
+
*/
|
|
145
|
+
declare const banNewExpr: (name: string | ReadonlyArray<string>, opts: {
|
|
146
|
+
readonly message: string;
|
|
147
|
+
readonly meta?: {
|
|
148
|
+
readonly type?: "problem" | "suggestion";
|
|
149
|
+
readonly effectVersion?: EffectVersion;
|
|
150
|
+
} | undefined;
|
|
151
|
+
}) => CreateRule;
|
|
152
|
+
/**
|
|
153
|
+
* Create a rule that bans a specific statement type.
|
|
154
|
+
*
|
|
155
|
+
* @since 0.1.0
|
|
156
|
+
*/
|
|
157
|
+
declare const banStatement: (nodeType: string, opts: {
|
|
158
|
+
readonly message: string;
|
|
159
|
+
readonly meta?: {
|
|
160
|
+
readonly type?: "problem" | "suggestion";
|
|
161
|
+
readonly effectVersion?: EffectVersion;
|
|
162
|
+
} | undefined;
|
|
163
|
+
}) => CreateRule;
|
|
164
|
+
/**
|
|
165
|
+
* A single ban specification. Each spec carries its own message so
|
|
166
|
+
* diagnostics are specific to the exact pattern matched.
|
|
167
|
+
*
|
|
168
|
+
* @since 0.3.0
|
|
169
|
+
*/
|
|
170
|
+
type BanSpec = {
|
|
171
|
+
readonly type: 'member';
|
|
172
|
+
readonly object: string;
|
|
173
|
+
readonly property: string | ReadonlyArray<string>;
|
|
174
|
+
readonly message: string;
|
|
175
|
+
} | {
|
|
176
|
+
readonly type: 'call';
|
|
177
|
+
readonly name: string | ReadonlyArray<string>;
|
|
178
|
+
readonly message: string;
|
|
179
|
+
} | {
|
|
180
|
+
readonly type: 'new';
|
|
181
|
+
readonly name: string | ReadonlyArray<string>;
|
|
182
|
+
readonly message: string;
|
|
183
|
+
} | {
|
|
184
|
+
readonly type: 'import';
|
|
185
|
+
readonly source: string | ((source: string) => boolean);
|
|
186
|
+
readonly message: string;
|
|
187
|
+
} | {
|
|
188
|
+
readonly type: 'statement';
|
|
189
|
+
readonly nodeType: string;
|
|
190
|
+
readonly message: string;
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Create a rule that bans multiple patterns, each with its own message.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* Rule.banMultiple({
|
|
198
|
+
* name: "no-global-date",
|
|
199
|
+
* meta: { type: "suggestion" },
|
|
200
|
+
* specs: [
|
|
201
|
+
* { type: "new", name: "Date", message: "Avoid new Date(). Use Clock service." },
|
|
202
|
+
* { type: "member", object: "Date", property: "now", message: "Avoid Date.now(). Use Clock service." },
|
|
203
|
+
* ],
|
|
204
|
+
* })
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* @since 0.3.0
|
|
208
|
+
*/
|
|
209
|
+
declare const banMultiple: (config: {
|
|
210
|
+
readonly name: string;
|
|
211
|
+
readonly meta?: {
|
|
212
|
+
readonly type?: "problem" | "suggestion";
|
|
213
|
+
readonly effectVersion?: EffectVersion;
|
|
214
|
+
} | undefined;
|
|
215
|
+
readonly specs: ReadonlyArray<BanSpec>;
|
|
216
|
+
}) => CreateRule;
|
|
217
|
+
//#endregion
|
|
218
|
+
export { BanSpec, EffectVersion, RuleConfig, Rule_d_exports, banCallOf, banImport, banMember, banMultiple, banNewExpr, banStatement, define, meta };
|