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.
Files changed (258) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +13 -0
  2. package/dist/index.d.ts +4 -0
  3. package/dist/index.js +4 -0
  4. package/dist/plugin.d.ts +5 -0
  5. package/dist/plugin.js +18 -0
  6. package/dist/presets/core.d.ts +43 -0
  7. package/dist/presets/core.js +43 -0
  8. package/dist/presets/effect-native.d.ts +28 -0
  9. package/dist/presets/effect-native.js +28 -0
  10. package/dist/presets/full.d.ts +60 -0
  11. package/dist/presets/full.js +60 -0
  12. package/dist/presets/functional.d.ts +21 -0
  13. package/dist/presets/functional.js +21 -0
  14. package/dist/presets/index.d.ts +14 -0
  15. package/dist/presets/index.js +20 -0
  16. package/dist/presets/strict.d.ts +64 -0
  17. package/dist/presets/strict.js +64 -0
  18. package/dist/presets/v3-strict.d.ts +16 -0
  19. package/dist/presets/v3-strict.js +16 -0
  20. package/dist/presets/v3.d.ts +18 -0
  21. package/dist/presets/v3.js +18 -0
  22. package/dist/rules/_effect-context.d.ts +19 -0
  23. package/dist/rules/_effect-context.js +22 -0
  24. package/dist/rules/index.d.ts +66 -0
  25. package/dist/rules/index.js +124 -0
  26. package/dist/rules/no-arrow-ladder.d.ts +6 -0
  27. package/dist/rules/no-arrow-ladder.js +61 -0
  28. package/dist/rules/no-async-function.d.ts +6 -0
  29. package/dist/rules/no-async-function.js +46 -0
  30. package/dist/rules/no-catch-all-to-map-error.d.ts +6 -0
  31. package/dist/rules/no-catch-all-to-map-error.js +67 -0
  32. package/dist/rules/no-effect-as.d.ts +6 -0
  33. package/dist/rules/no-effect-as.js +16 -0
  34. package/dist/rules/no-effect-async.d.ts +6 -0
  35. package/dist/rules/no-effect-async.js +16 -0
  36. package/dist/rules/no-effect-bind.d.ts +6 -0
  37. package/dist/rules/no-effect-bind.js +16 -0
  38. package/dist/rules/no-effect-do.d.ts +6 -0
  39. package/dist/rules/no-effect-do.js +16 -0
  40. package/dist/rules/no-effect-fn-generator.d.ts +6 -0
  41. package/dist/rules/no-effect-fn-generator.js +30 -0
  42. package/dist/rules/no-effect-gen-adapter.d.ts +6 -0
  43. package/dist/rules/no-effect-gen-adapter.js +30 -0
  44. package/dist/rules/no-effect-map-flatten.d.ts +6 -0
  45. package/dist/rules/no-effect-map-flatten.js +53 -0
  46. package/dist/rules/no-effect-map-void.d.ts +6 -0
  47. package/dist/rules/no-effect-map-void.js +40 -0
  48. package/dist/rules/no-effect-never.d.ts +6 -0
  49. package/dist/rules/no-effect-never.js +16 -0
  50. package/dist/rules/no-effect-orElse-ladder.d.ts +6 -0
  51. package/dist/rules/no-effect-orElse-ladder.js +53 -0
  52. package/dist/rules/no-effect-succeed-string.d.ts +6 -0
  53. package/dist/rules/no-effect-succeed-string.js +30 -0
  54. package/dist/rules/no-effect-succeed-variable.d.ts +6 -0
  55. package/dist/rules/no-effect-succeed-variable.js +30 -0
  56. package/dist/rules/no-effect-succeed-void.d.ts +6 -0
  57. package/dist/rules/no-effect-succeed-void.js +33 -0
  58. package/dist/rules/no-effect-sync-console.d.ts +6 -0
  59. package/dist/rules/no-effect-sync-console.js +63 -0
  60. package/dist/rules/no-effect-sync-wrapper.d.ts +6 -0
  61. package/dist/rules/no-effect-sync-wrapper.js +37 -0
  62. package/dist/rules/no-effect-type-alias.d.ts +6 -0
  63. package/dist/rules/no-effect-type-alias.js +52 -0
  64. package/dist/rules/no-effect-wrapper-alias.d.ts +6 -0
  65. package/dist/rules/no-effect-wrapper-alias.js +69 -0
  66. package/dist/rules/no-extends-native-error.d.ts +6 -0
  67. package/dist/rules/no-extends-native-error.js +41 -0
  68. package/dist/rules/no-flatmap-ladder.d.ts +6 -0
  69. package/dist/rules/no-flatmap-ladder.js +48 -0
  70. package/dist/rules/no-fromnullable-coalesce.d.ts +6 -0
  71. package/dist/rules/no-fromnullable-coalesce.js +36 -0
  72. package/dist/rules/no-global-error-in-catch.d.ts +6 -0
  73. package/dist/rules/no-global-error-in-catch.js +75 -0
  74. package/dist/rules/no-global-error-in-failure.d.ts +6 -0
  75. package/dist/rules/no-global-error-in-failure.js +54 -0
  76. package/dist/rules/no-globals.d.ts +6 -0
  77. package/dist/rules/no-globals.js +164 -0
  78. package/dist/rules/no-if-statement.d.ts +6 -0
  79. package/dist/rules/no-if-statement.js +18 -0
  80. package/dist/rules/no-iife-wrapper.d.ts +6 -0
  81. package/dist/rules/no-iife-wrapper.js +37 -0
  82. package/dist/rules/no-inline-provide.d.ts +6 -0
  83. package/dist/rules/no-inline-provide.js +31 -0
  84. package/dist/rules/no-instanceof-schema.d.ts +6 -0
  85. package/dist/rules/no-instanceof-schema.js +35 -0
  86. package/dist/rules/no-manual-effect-channels.d.ts +6 -0
  87. package/dist/rules/no-manual-effect-channels.js +40 -0
  88. package/dist/rules/no-match-effect-branch.d.ts +6 -0
  89. package/dist/rules/no-match-effect-branch.js +64 -0
  90. package/dist/rules/no-match-void-branch.d.ts +6 -0
  91. package/dist/rules/no-match-void-branch.js +50 -0
  92. package/dist/rules/no-multiple-effect-provide.d.ts +6 -0
  93. package/dist/rules/no-multiple-effect-provide.js +45 -0
  94. package/dist/rules/no-nested-effect-call.d.ts +6 -0
  95. package/dist/rules/no-nested-effect-call.js +97 -0
  96. package/dist/rules/no-nested-effect-gen.d.ts +6 -0
  97. package/dist/rules/no-nested-effect-gen.js +46 -0
  98. package/dist/rules/no-nested-pipe.d.ts +6 -0
  99. package/dist/rules/no-nested-pipe.js +38 -0
  100. package/dist/rules/no-new-error.d.ts +6 -0
  101. package/dist/rules/no-new-error.js +39 -0
  102. package/dist/rules/no-new-promise.d.ts +6 -0
  103. package/dist/rules/no-new-promise.js +38 -0
  104. package/dist/rules/no-node-builtin-import.d.ts +6 -0
  105. package/dist/rules/no-node-builtin-import.js +61 -0
  106. package/dist/rules/no-option-as.d.ts +6 -0
  107. package/dist/rules/no-option-as.js +16 -0
  108. package/dist/rules/no-option-boolean-normalization.d.ts +6 -0
  109. package/dist/rules/no-option-boolean-normalization.js +50 -0
  110. package/dist/rules/no-positional-log-error.d.ts +6 -0
  111. package/dist/rules/no-positional-log-error.js +52 -0
  112. package/dist/rules/no-redundant-schema-tag-identifier.d.ts +6 -0
  113. package/dist/rules/no-redundant-schema-tag-identifier.js +46 -0
  114. package/dist/rules/no-return-in-arrow.d.ts +6 -0
  115. package/dist/rules/no-return-in-arrow.js +41 -0
  116. package/dist/rules/no-return-nullish.d.ts +6 -0
  117. package/dist/rules/no-return-nullish.js +47 -0
  118. package/dist/rules/no-run-in-effect-gen.d.ts +6 -0
  119. package/dist/rules/no-run-in-effect-gen.js +48 -0
  120. package/dist/rules/no-runtime-run-fork.d.ts +6 -0
  121. package/dist/rules/no-runtime-run-fork.js +19 -0
  122. package/dist/rules/no-schema-struct-with-tag.d.ts +6 -0
  123. package/dist/rules/no-schema-struct-with-tag.js +48 -0
  124. package/dist/rules/no-schema-union-of-literals.d.ts +6 -0
  125. package/dist/rules/no-schema-union-of-literals.js +35 -0
  126. package/dist/rules/no-string-sentinel-const.d.ts +6 -0
  127. package/dist/rules/no-string-sentinel-const.js +38 -0
  128. package/dist/rules/no-switch-statement.d.ts +6 -0
  129. package/dist/rules/no-switch-statement.js +16 -0
  130. package/dist/rules/no-ternary.d.ts +6 -0
  131. package/dist/rules/no-ternary.js +30 -0
  132. package/dist/rules/no-throw-statement.d.ts +6 -0
  133. package/dist/rules/no-throw-statement.js +34 -0
  134. package/dist/rules/no-try-catch.d.ts +6 -0
  135. package/dist/rules/no-try-catch.js +34 -0
  136. package/dist/rules/no-unnecessary-arrow-block.d.ts +6 -0
  137. package/dist/rules/no-unnecessary-arrow-block.js +34 -0
  138. package/dist/rules/no-unnecessary-effect-gen.d.ts +6 -0
  139. package/dist/rules/no-unnecessary-effect-gen.js +35 -0
  140. package/dist/rules/no-unnecessary-pipe-chain.d.ts +6 -0
  141. package/dist/rules/no-unnecessary-pipe-chain.js +36 -0
  142. package/dist/rules/no-unnecessary-pipe.d.ts +6 -0
  143. package/dist/rules/no-unnecessary-pipe.js +29 -0
  144. package/dist/vendor/effect-oxlint/AST.d.ts +199 -0
  145. package/dist/vendor/effect-oxlint/AST.js +214 -0
  146. package/dist/vendor/effect-oxlint/Comment.d.ts +55 -0
  147. package/dist/vendor/effect-oxlint/Comment.js +67 -0
  148. package/dist/vendor/effect-oxlint/Diagnostic.d.ts +86 -0
  149. package/dist/vendor/effect-oxlint/Diagnostic.js +115 -0
  150. package/dist/vendor/effect-oxlint/Plugin.d.ts +38 -0
  151. package/dist/vendor/effect-oxlint/Plugin.js +45 -0
  152. package/dist/vendor/effect-oxlint/Rule.d.ts +218 -0
  153. package/dist/vendor/effect-oxlint/Rule.js +309 -0
  154. package/dist/vendor/effect-oxlint/RuleContext.d.ts +77 -0
  155. package/dist/vendor/effect-oxlint/RuleContext.js +74 -0
  156. package/dist/vendor/effect-oxlint/Scope.d.ts +100 -0
  157. package/dist/vendor/effect-oxlint/Scope.js +110 -0
  158. package/dist/vendor/effect-oxlint/SourceCode.d.ts +180 -0
  159. package/dist/vendor/effect-oxlint/SourceCode.js +203 -0
  160. package/dist/vendor/effect-oxlint/Testing.d.ts +510 -0
  161. package/dist/vendor/effect-oxlint/Testing.js +963 -0
  162. package/dist/vendor/effect-oxlint/Token.d.ts +98 -0
  163. package/dist/vendor/effect-oxlint/Token.js +103 -0
  164. package/dist/vendor/effect-oxlint/Visitor.d.ts +166 -0
  165. package/dist/vendor/effect-oxlint/Visitor.js +138 -0
  166. package/dist/vendor/effect-oxlint/index.d.ts +13 -0
  167. package/dist/vendor/effect-oxlint/index.js +12 -0
  168. package/package.json +24 -5
  169. package/.effect-lsp.json +0 -60
  170. package/.oxlintrc.json +0 -33
  171. package/CHANGELOG.md +0 -55
  172. package/scripts/add-rule.ts +0 -87
  173. package/scripts/codegen.ts +0 -108
  174. package/src/index.ts +0 -9
  175. package/src/plugin.ts +0 -16
  176. package/src/presets/core.ts +0 -47
  177. package/src/presets/effect-native.ts +0 -34
  178. package/src/presets/full.ts +0 -70
  179. package/src/presets/functional.ts +0 -18
  180. package/src/presets/index.ts +0 -5
  181. package/src/presets/strict.ts +0 -77
  182. package/src/rules/_effect-context.ts +0 -28
  183. package/src/rules/index.ts +0 -72
  184. package/src/rules/no-arrow-ladder.ts +0 -70
  185. package/src/rules/no-async-function.ts +0 -47
  186. package/src/rules/no-catch-all-to-map-error.ts +0 -90
  187. package/src/rules/no-effect-as.ts +0 -14
  188. package/src/rules/no-effect-async.ts +0 -14
  189. package/src/rules/no-effect-bind.ts +0 -13
  190. package/src/rules/no-effect-do.ts +0 -14
  191. package/src/rules/no-effect-fn-generator.ts +0 -58
  192. package/src/rules/no-effect-gen-adapter.ts +0 -51
  193. package/src/rules/no-effect-map-flatten.ts +0 -82
  194. package/src/rules/no-effect-map-void.ts +0 -80
  195. package/src/rules/no-effect-never.ts +0 -14
  196. package/src/rules/no-effect-orElse-ladder.ts +0 -79
  197. package/src/rules/no-effect-succeed-string.ts +0 -52
  198. package/src/rules/no-effect-succeed-variable.ts +0 -50
  199. package/src/rules/no-effect-succeed-void.ts +0 -63
  200. package/src/rules/no-effect-sync-console.ts +0 -91
  201. package/src/rules/no-effect-sync-wrapper.ts +0 -67
  202. package/src/rules/no-effect-type-alias.ts +0 -71
  203. package/src/rules/no-effect-wrapper-alias.ts +0 -95
  204. package/src/rules/no-extends-native-error.ts +0 -54
  205. package/src/rules/no-flatmap-ladder.ts +0 -77
  206. package/src/rules/no-fromnullable-coalesce.ts +0 -62
  207. package/src/rules/no-global-error-in-catch.ts +0 -104
  208. package/src/rules/no-global-error-in-failure.ts +0 -83
  209. package/src/rules/no-globals.ts +0 -178
  210. package/src/rules/no-if-statement.ts +0 -16
  211. package/src/rules/no-iife-wrapper.ts +0 -51
  212. package/src/rules/no-inline-provide.ts +0 -41
  213. package/src/rules/no-instanceof-schema.ts +0 -42
  214. package/src/rules/no-manual-effect-channels.ts +0 -58
  215. package/src/rules/no-match-effect-branch.ts +0 -82
  216. package/src/rules/no-match-void-branch.ts +0 -72
  217. package/src/rules/no-multiple-effect-provide.ts +0 -75
  218. package/src/rules/no-nested-effect-call.ts +0 -57
  219. package/src/rules/no-nested-effect-gen.ts +0 -43
  220. package/src/rules/no-nested-pipe.ts +0 -73
  221. package/src/rules/no-new-error.ts +0 -53
  222. package/src/rules/no-new-promise.ts +0 -50
  223. package/src/rules/no-node-builtin-import.ts +0 -68
  224. package/src/rules/no-option-as.ts +0 -13
  225. package/src/rules/no-option-boolean-normalization.ts +0 -88
  226. package/src/rules/no-positional-log-error.ts +0 -76
  227. package/src/rules/no-redundant-schema-tag-identifier.ts +0 -62
  228. package/src/rules/no-return-in-arrow.ts +0 -76
  229. package/src/rules/no-return-nullish.ts +0 -80
  230. package/src/rules/no-run-in-effect-gen.ts +0 -66
  231. package/src/rules/no-runtime-run-fork.ts +0 -14
  232. package/src/rules/no-schema-struct-with-tag.ts +0 -64
  233. package/src/rules/no-schema-union-of-literals.ts +0 -48
  234. package/src/rules/no-string-sentinel-const.ts +0 -49
  235. package/src/rules/no-switch-statement.ts +0 -13
  236. package/src/rules/no-ternary.ts +0 -30
  237. package/src/rules/no-throw-statement.ts +0 -39
  238. package/src/rules/no-try-catch.ts +0 -39
  239. package/src/rules/no-unnecessary-arrow-block.ts +0 -51
  240. package/src/rules/no-unnecessary-effect-gen.ts +0 -83
  241. package/src/rules/no-unnecessary-pipe-chain.ts +0 -47
  242. package/src/rules/no-unnecessary-pipe.ts +0 -45
  243. package/src/vendor/effect-oxlint/AST.ts +0 -516
  244. package/src/vendor/effect-oxlint/Comment.ts +0 -86
  245. package/src/vendor/effect-oxlint/Diagnostic.ts +0 -199
  246. package/src/vendor/effect-oxlint/Plugin.ts +0 -71
  247. package/src/vendor/effect-oxlint/Rule.ts +0 -548
  248. package/src/vendor/effect-oxlint/RuleContext.ts +0 -144
  249. package/src/vendor/effect-oxlint/Scope.ts +0 -177
  250. package/src/vendor/effect-oxlint/SourceCode.ts +0 -377
  251. package/src/vendor/effect-oxlint/Testing.ts +0 -1227
  252. package/src/vendor/effect-oxlint/Token.ts +0 -131
  253. package/src/vendor/effect-oxlint/Visitor.ts +0 -287
  254. package/src/vendor/effect-oxlint/index.ts +0 -88
  255. package/tests/ban-rules.test.ts +0 -68
  256. package/tests/context-rules.test.ts +0 -263
  257. package/tests/pattern-rules.test.ts +0 -247
  258. 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
- });