oxlint-plugin-effect 0.2.0 → 0.2.2
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 +14 -0
- package/dist/presets/index.js +20 -0
- package/dist/presets/strict.d.ts +64 -0
- package/dist/presets/strict.js +64 -0
- package/dist/presets/v3-strict.d.ts +16 -0
- package/dist/presets/v3-strict.js +16 -0
- package/dist/presets/v3.d.ts +18 -0
- package/dist/presets/v3.js +18 -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
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Comment type predicates and helpers for Effect-first lint rules.
|
|
3
|
-
*
|
|
4
|
-
* Oxlint comments have a `type` of `"Line"`, `"Block"`, or `"Shebang"`
|
|
5
|
-
* and a `value` string (the comment text without delimiters).
|
|
6
|
-
*
|
|
7
|
-
* @since 0.2.0
|
|
8
|
-
*/
|
|
9
|
-
import type { Comment } from '@oxlint/plugins';
|
|
10
|
-
import * as Str from 'effect/String';
|
|
11
|
-
|
|
12
|
-
// ---------------------------------------------------------------------------
|
|
13
|
-
// Type predicates
|
|
14
|
-
// ---------------------------------------------------------------------------
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Check whether a comment is a line comment (`// ...`).
|
|
18
|
-
*
|
|
19
|
-
* @since 0.2.0
|
|
20
|
-
*/
|
|
21
|
-
export const isLine = (comment: Comment): boolean => comment.type === 'Line';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Check whether a comment is a block comment (`/* ... */`).
|
|
25
|
-
*
|
|
26
|
-
* @since 0.2.0
|
|
27
|
-
*/
|
|
28
|
-
export const isBlock = (comment: Comment): boolean => comment.type === 'Block';
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Check whether a comment is a shebang (`#!/usr/bin/env node`).
|
|
32
|
-
*
|
|
33
|
-
* @since 0.2.0
|
|
34
|
-
*/
|
|
35
|
-
export const isShebang = (comment: Comment): boolean =>
|
|
36
|
-
comment.type === 'Shebang';
|
|
37
|
-
|
|
38
|
-
// ---------------------------------------------------------------------------
|
|
39
|
-
// Content helpers
|
|
40
|
-
// ---------------------------------------------------------------------------
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Get the text content of a comment (without delimiters).
|
|
44
|
-
*
|
|
45
|
-
* @since 0.2.0
|
|
46
|
-
*/
|
|
47
|
-
export const text = (comment: Comment): string => comment.value;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Check whether a comment is a JSDoc comment (`/** ... */`).
|
|
51
|
-
*
|
|
52
|
-
* A JSDoc comment is a block comment whose value starts with `*`.
|
|
53
|
-
*
|
|
54
|
-
* @since 0.2.0
|
|
55
|
-
*/
|
|
56
|
-
export const isJSDoc = (comment: Comment): boolean =>
|
|
57
|
-
comment.type === 'Block' && Str.startsWith('*')(comment.value);
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Check whether a comment is an eslint/oxlint disable directive.
|
|
61
|
-
*
|
|
62
|
-
* Matches line comments like `// eslint-disable-next-line ...`
|
|
63
|
-
* and block comments like `/* eslint-disable ... */`.
|
|
64
|
-
*
|
|
65
|
-
* @since 0.2.0
|
|
66
|
-
*/
|
|
67
|
-
export const isDisableDirective = (comment: Comment): boolean => {
|
|
68
|
-
const trimmed = Str.trim(comment.value);
|
|
69
|
-
return (
|
|
70
|
-
Str.startsWith('eslint-disable')(trimmed) ||
|
|
71
|
-
Str.startsWith('oxlint-disable')(trimmed)
|
|
72
|
-
);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Check whether a comment is an eslint/oxlint enable directive.
|
|
77
|
-
*
|
|
78
|
-
* @since 0.2.0
|
|
79
|
-
*/
|
|
80
|
-
export const isEnableDirective = (comment: Comment): boolean => {
|
|
81
|
-
const trimmed = Str.trim(comment.value);
|
|
82
|
-
return (
|
|
83
|
-
Str.startsWith('eslint-enable')(trimmed) ||
|
|
84
|
-
Str.startsWith('oxlint-enable')(trimmed)
|
|
85
|
-
);
|
|
86
|
-
};
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Structured diagnostic construction for Effect-first lint rules.
|
|
3
|
-
*
|
|
4
|
-
* Wraps the oxlint `Diagnostic` type with builder helpers.
|
|
5
|
-
*
|
|
6
|
-
* @since 0.1.0
|
|
7
|
-
*/
|
|
8
|
-
import type {
|
|
9
|
-
Diagnostic as OxlintDiagnostic,
|
|
10
|
-
DiagnosticData,
|
|
11
|
-
Fix as OxlintFix,
|
|
12
|
-
FixFn,
|
|
13
|
-
Ranged,
|
|
14
|
-
Suggestion
|
|
15
|
-
} from '@oxlint/plugins';
|
|
16
|
-
import * as Arr from 'effect/Array';
|
|
17
|
-
import { dual } from 'effect/Function';
|
|
18
|
-
import * as Option from 'effect/Option';
|
|
19
|
-
import * as P from 'effect/Predicate';
|
|
20
|
-
import * as Result from 'effect/Result';
|
|
21
|
-
|
|
22
|
-
// ---------------------------------------------------------------------------
|
|
23
|
-
// Re-exports
|
|
24
|
-
// ---------------------------------------------------------------------------
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* The raw oxlint diagnostic type.
|
|
28
|
-
*
|
|
29
|
-
* @since 0.1.0
|
|
30
|
-
*/
|
|
31
|
-
export type { OxlintDiagnostic as Diagnostic };
|
|
32
|
-
|
|
33
|
-
// ---------------------------------------------------------------------------
|
|
34
|
-
// Constructors
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Create a diagnostic with a message and node location.
|
|
39
|
-
*
|
|
40
|
-
* @since 0.1.0
|
|
41
|
-
*/
|
|
42
|
-
export const make = (opts: {
|
|
43
|
-
readonly node: Ranged;
|
|
44
|
-
readonly message: string;
|
|
45
|
-
readonly data?: DiagnosticData;
|
|
46
|
-
}): OxlintDiagnostic => ({
|
|
47
|
-
node: opts.node,
|
|
48
|
-
message: opts.message,
|
|
49
|
-
data: opts.data
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Create a diagnostic using a `messageId` from `meta.messages`.
|
|
54
|
-
*
|
|
55
|
-
* @since 0.1.0
|
|
56
|
-
*/
|
|
57
|
-
export const fromId = (opts: {
|
|
58
|
-
readonly node: Ranged;
|
|
59
|
-
readonly messageId: string;
|
|
60
|
-
readonly data?: DiagnosticData;
|
|
61
|
-
}): OxlintDiagnostic => ({
|
|
62
|
-
node: opts.node,
|
|
63
|
-
messageId: opts.messageId,
|
|
64
|
-
data: opts.data
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// ---------------------------------------------------------------------------
|
|
68
|
-
// Combinators
|
|
69
|
-
// ---------------------------------------------------------------------------
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Attach an autofix function to a diagnostic.
|
|
73
|
-
*
|
|
74
|
-
* @since 0.1.0
|
|
75
|
-
*/
|
|
76
|
-
export const withFix: {
|
|
77
|
-
(fix: FixFn): (diagnostic: OxlintDiagnostic) => OxlintDiagnostic;
|
|
78
|
-
(diagnostic: OxlintDiagnostic, fix: FixFn): OxlintDiagnostic;
|
|
79
|
-
} = dual(
|
|
80
|
-
2,
|
|
81
|
-
(diagnostic: OxlintDiagnostic, fix: FixFn): OxlintDiagnostic => ({
|
|
82
|
-
...diagnostic,
|
|
83
|
-
fix
|
|
84
|
-
})
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Attach suggestion fixes to a diagnostic.
|
|
89
|
-
*
|
|
90
|
-
* @since 0.1.0
|
|
91
|
-
*/
|
|
92
|
-
export const withSuggestions: {
|
|
93
|
-
(
|
|
94
|
-
suggestions: ReadonlyArray<Suggestion>
|
|
95
|
-
): (diagnostic: OxlintDiagnostic) => OxlintDiagnostic;
|
|
96
|
-
(
|
|
97
|
-
diagnostic: OxlintDiagnostic,
|
|
98
|
-
suggestions: ReadonlyArray<Suggestion>
|
|
99
|
-
): OxlintDiagnostic;
|
|
100
|
-
} = dual(
|
|
101
|
-
2,
|
|
102
|
-
(
|
|
103
|
-
diagnostic: OxlintDiagnostic,
|
|
104
|
-
suggestions: ReadonlyArray<Suggestion>
|
|
105
|
-
): OxlintDiagnostic => ({
|
|
106
|
-
...diagnostic,
|
|
107
|
-
suggest: Array.from(suggestions)
|
|
108
|
-
})
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
// ---------------------------------------------------------------------------
|
|
112
|
-
// Fix helpers
|
|
113
|
-
// ---------------------------------------------------------------------------
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Composable fix operations.
|
|
117
|
-
*
|
|
118
|
-
* Each function returns a `FixFn` that can be passed to `withFix`
|
|
119
|
-
* or composed via `composeFixes`.
|
|
120
|
-
*
|
|
121
|
-
* @since 0.1.0
|
|
122
|
-
*/
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Replace the text of a node or token.
|
|
126
|
-
*
|
|
127
|
-
* @since 0.1.0
|
|
128
|
-
*/
|
|
129
|
-
export const replaceText =
|
|
130
|
-
(nodeOrToken: Ranged, text: string): FixFn =>
|
|
131
|
-
(fixer) =>
|
|
132
|
-
fixer.replaceText(nodeOrToken, text);
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Insert text before a node or token.
|
|
136
|
-
*
|
|
137
|
-
* @since 0.1.0
|
|
138
|
-
*/
|
|
139
|
-
export const insertBefore =
|
|
140
|
-
(nodeOrToken: Ranged, text: string): FixFn =>
|
|
141
|
-
(fixer) =>
|
|
142
|
-
fixer.insertTextBefore(nodeOrToken, text);
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Insert text after a node or token.
|
|
146
|
-
*
|
|
147
|
-
* @since 0.1.0
|
|
148
|
-
*/
|
|
149
|
-
export const insertAfter =
|
|
150
|
-
(nodeOrToken: Ranged, text: string): FixFn =>
|
|
151
|
-
(fixer) =>
|
|
152
|
-
fixer.insertTextAfter(nodeOrToken, text);
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Remove a node or token.
|
|
156
|
-
*
|
|
157
|
-
* @since 0.1.0
|
|
158
|
-
*/
|
|
159
|
-
export const removeFix =
|
|
160
|
-
(nodeOrToken: Ranged): FixFn =>
|
|
161
|
-
(fixer) =>
|
|
162
|
-
fixer.remove(nodeOrToken);
|
|
163
|
-
|
|
164
|
-
/** @internal Type guard for an oxlint Fix value (has `range` and `text`). */
|
|
165
|
-
const isFix = (value: unknown): value is OxlintFix =>
|
|
166
|
-
P.isObject(value) && 'range' in value && 'text' in value;
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Extract fixes from a single `FixFn` result.
|
|
170
|
-
*
|
|
171
|
-
* The parameter is typed as `unknown` because oxlint's `FixFn` returns
|
|
172
|
-
* a nullable union (`Fix | Array<Fix | null> | IterableIterator<…> | null`).
|
|
173
|
-
* We guard at the boundary instead of mirroring the nullable upstream type.
|
|
174
|
-
*
|
|
175
|
-
* @internal
|
|
176
|
-
*/
|
|
177
|
-
const extractFixes = (result: unknown): ReadonlyArray<OxlintFix> => {
|
|
178
|
-
if (result === null || result === undefined) return [];
|
|
179
|
-
if (isFix(result)) return [result];
|
|
180
|
-
if (!P.isIterable(result)) return [];
|
|
181
|
-
return Arr.filterMap(Array.from(result), (item) =>
|
|
182
|
-
Option.fromNullishOr(item).pipe(
|
|
183
|
-
Option.filter(isFix),
|
|
184
|
-
Result.fromOption(() => undefined)
|
|
185
|
-
)
|
|
186
|
-
);
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Compose multiple fix functions into one.
|
|
191
|
-
*
|
|
192
|
-
* All individual fixes are collected into a single array result.
|
|
193
|
-
*
|
|
194
|
-
* @since 0.1.0
|
|
195
|
-
*/
|
|
196
|
-
export const composeFixes =
|
|
197
|
-
(...fixes: ReadonlyArray<FixFn>): FixFn =>
|
|
198
|
-
(fixer) =>
|
|
199
|
-
Arr.flatMap(fixes, (fn) => Array.from(extractFixes(fn(fixer))));
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Plugin definition and composition for Effect-first oxlint plugins.
|
|
3
|
-
*
|
|
4
|
-
* @since 0.1.0
|
|
5
|
-
*/
|
|
6
|
-
import type { CreateRule, Plugin as OxlintPlugin, Rule } from '@oxlint/plugins';
|
|
7
|
-
import * as Arr from 'effect/Array';
|
|
8
|
-
|
|
9
|
-
// ---------------------------------------------------------------------------
|
|
10
|
-
// Re-exports
|
|
11
|
-
// ---------------------------------------------------------------------------
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* The raw oxlint plugin type.
|
|
15
|
-
*
|
|
16
|
-
* @since 0.1.0
|
|
17
|
-
*/
|
|
18
|
-
export type { OxlintPlugin as Plugin };
|
|
19
|
-
|
|
20
|
-
// ---------------------------------------------------------------------------
|
|
21
|
-
// Constructor
|
|
22
|
-
// ---------------------------------------------------------------------------
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Define a typed oxlint plugin from a name and rule map.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```ts
|
|
29
|
-
* import { Plugin, Rule } from 'effect-oxlint'
|
|
30
|
-
*
|
|
31
|
-
* export default Plugin.define({
|
|
32
|
-
* name: 'my-effect-rules',
|
|
33
|
-
* rules: {
|
|
34
|
-
* 'no-throw-in-gen': myThrowRule,
|
|
35
|
-
* 'prefer-effect-fn': myFnRule,
|
|
36
|
-
* }
|
|
37
|
-
* })
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* @since 0.1.0
|
|
41
|
-
*/
|
|
42
|
-
export const define = (config: {
|
|
43
|
-
readonly name: string;
|
|
44
|
-
readonly rules: Record<string, CreateRule>;
|
|
45
|
-
}): OxlintPlugin => ({
|
|
46
|
-
meta: { name: config.name },
|
|
47
|
-
rules: config.rules
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Merge multiple plugins into one.
|
|
52
|
-
*
|
|
53
|
-
* If two plugins define a rule with the same name, the later one wins.
|
|
54
|
-
*
|
|
55
|
-
* @since 0.1.0
|
|
56
|
-
*/
|
|
57
|
-
export const merge = (
|
|
58
|
-
...plugins: ReadonlyArray<OxlintPlugin>
|
|
59
|
-
): OxlintPlugin => ({
|
|
60
|
-
meta: {
|
|
61
|
-
name: Arr.join(
|
|
62
|
-
Arr.map(plugins, (p) => p.meta?.name ?? 'unknown'),
|
|
63
|
-
'+'
|
|
64
|
-
)
|
|
65
|
-
},
|
|
66
|
-
rules: Arr.reduce<OxlintPlugin, Record<string, Rule>>(
|
|
67
|
-
plugins,
|
|
68
|
-
{},
|
|
69
|
-
(acc, p) => ({ ...acc, ...p.rules })
|
|
70
|
-
)
|
|
71
|
-
});
|