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,177 +0,0 @@
1
- /**
2
- * Scope analysis helpers for Effect-first lint rules.
3
- *
4
- * Wraps oxlint's scope manager types (`Scope`, `Variable`, `Reference`,
5
- * `Definition`) with `Option`-returning lookups and convenience predicates.
6
- *
7
- * For scope queries that require `SourceCode` access (e.g. `getScope`,
8
- * `getDeclaredVariables`), see the `SourceCode` module which provides
9
- * effectful wrappers.
10
- *
11
- * @since 0.2.0
12
- */
13
- import type {
14
- Reference,
15
- Scope as OxlintScope,
16
- Variable
17
- } from '@oxlint/plugins';
18
- import * as Arr from 'effect/Array';
19
- import { dual, pipe } from 'effect/Function';
20
- import * as Option from 'effect/Option';
21
-
22
- // ---------------------------------------------------------------------------
23
- // Variable lookup
24
- // ---------------------------------------------------------------------------
25
-
26
- /**
27
- * Find a variable by name in a scope.
28
- *
29
- * Searches the scope's `set` (a `Map<string, Variable>`).
30
- *
31
- * @since 0.2.0
32
- */
33
- export const findVariable: {
34
- (name: string): (scope: OxlintScope) => Option.Option<Variable>;
35
- (scope: OxlintScope, name: string): Option.Option<Variable>;
36
- } = dual(
37
- 2,
38
- (scope: OxlintScope, name: string): Option.Option<Variable> =>
39
- Option.fromNullishOr(scope.set.get(name))
40
- );
41
-
42
- /**
43
- * Find a variable by name, walking up the scope chain.
44
- *
45
- * Starts at the given scope and checks each `upper` scope until found
46
- * or the global scope is exhausted.
47
- *
48
- * @since 0.2.0
49
- */
50
- export const findVariableUp: {
51
- (name: string): (scope: OxlintScope) => Option.Option<Variable>;
52
- (scope: OxlintScope, name: string): Option.Option<Variable>;
53
- } = dual(2, (scope: OxlintScope, name: string): Option.Option<Variable> => {
54
- const walk = (current: OxlintScope): Option.Option<Variable> =>
55
- pipe(
56
- Option.fromNullishOr(current.set.get(name)),
57
- Option.orElse(() =>
58
- pipe(
59
- Option.fromNullishOr(current.upper),
60
- Option.flatMap((parent) => walk(parent))
61
- )
62
- )
63
- );
64
- return walk(scope);
65
- });
66
-
67
- // ---------------------------------------------------------------------------
68
- // Variable predicates
69
- // ---------------------------------------------------------------------------
70
-
71
- /**
72
- * Check whether a variable has any read references.
73
- *
74
- * A variable is considered "used" if at least one reference reads it.
75
- *
76
- * @since 0.2.0
77
- */
78
- export const isUsed = (variable: Variable): boolean =>
79
- Arr.some(variable.references, (ref) => ref.isRead());
80
-
81
- /**
82
- * Check whether a variable has any write references.
83
- *
84
- * @since 0.2.0
85
- */
86
- export const isWritten = (variable: Variable): boolean =>
87
- Arr.some(variable.references, (ref) => ref.isWrite());
88
-
89
- /**
90
- * Check whether a variable is only read (no writes).
91
- *
92
- * @since 0.2.0
93
- */
94
- export const isReadOnly = (variable: Variable): boolean =>
95
- Arr.some(variable.references, (ref) => ref.isReadOnly());
96
-
97
- // ---------------------------------------------------------------------------
98
- // Reference helpers
99
- // ---------------------------------------------------------------------------
100
-
101
- /**
102
- * Get all references for a variable.
103
- *
104
- * @since 0.2.0
105
- */
106
- export const getReferences = (variable: Variable): ReadonlyArray<Reference> =>
107
- variable.references;
108
-
109
- /**
110
- * Get the read references for a variable.
111
- *
112
- * @since 0.2.0
113
- */
114
- export const getReadReferences = (
115
- variable: Variable
116
- ): ReadonlyArray<Reference> =>
117
- pipe(
118
- variable.references,
119
- Arr.filter((ref) => ref.isRead())
120
- );
121
-
122
- /**
123
- * Get the write references for a variable.
124
- *
125
- * @since 0.2.0
126
- */
127
- export const getWriteReferences = (
128
- variable: Variable
129
- ): ReadonlyArray<Reference> =>
130
- pipe(
131
- variable.references,
132
- Arr.filter((ref) => ref.isWrite())
133
- );
134
-
135
- // ---------------------------------------------------------------------------
136
- // Scope navigation
137
- // ---------------------------------------------------------------------------
138
-
139
- /**
140
- * Get the parent (upper) scope.
141
- *
142
- * @since 0.2.0
143
- */
144
- export const upper = (scope: OxlintScope): Option.Option<OxlintScope> =>
145
- Option.fromNullishOr(scope.upper);
146
-
147
- /**
148
- * Get the child scopes.
149
- *
150
- * @since 0.2.0
151
- */
152
- export const childScopes = (scope: OxlintScope): ReadonlyArray<OxlintScope> =>
153
- scope.childScopes;
154
-
155
- /**
156
- * Get all variables in a scope.
157
- *
158
- * @since 0.2.0
159
- */
160
- export const variables = (scope: OxlintScope): ReadonlyArray<Variable> =>
161
- scope.variables;
162
-
163
- /**
164
- * Get "through" references (unresolved in this scope).
165
- *
166
- * @since 0.2.0
167
- */
168
- export const throughReferences = (
169
- scope: OxlintScope
170
- ): ReadonlyArray<Reference> => scope.through;
171
-
172
- /**
173
- * Check whether a scope is strict mode.
174
- *
175
- * @since 0.2.0
176
- */
177
- export const isStrict = (scope: OxlintScope): boolean => scope.isStrict;
@@ -1,377 +0,0 @@
1
- /**
2
- * Effect-wrapped queries over oxlint's `SourceCode` object.
3
- *
4
- * Every method that may return `null` is lifted to `Option`. Methods
5
- * that return arrays stay as-is (empty array = no results). All
6
- * functions read from the `RuleContext` service, so they return
7
- * `Effect<T, never, RuleContext>` and can be `yield*`'d in handlers.
8
- *
9
- * @since 0.2.0
10
- */
11
- import type {
12
- Comment,
13
- ESTree,
14
- LineColumn,
15
- Range,
16
- Scope,
17
- SourceCode as OxlintSourceCode,
18
- Token,
19
- Variable
20
- } from '@oxlint/plugins';
21
- import * as Effect from 'effect/Effect';
22
- import * as Option from 'effect/Option';
23
-
24
- import { RuleContext } from './RuleContext.ts';
25
-
26
- // ---------------------------------------------------------------------------
27
- // Internal: read sourceCode from RuleContext
28
- // ---------------------------------------------------------------------------
29
-
30
- /** @internal */
31
- const withSourceCode = <A>(
32
- fn: (sc: OxlintSourceCode) => A
33
- ): Effect.Effect<A, never, RuleContext> =>
34
- Effect.service(RuleContext).pipe(Effect.map((ctx) => fn(ctx.sourceCode)));
35
-
36
- // ---------------------------------------------------------------------------
37
- // Source text
38
- // ---------------------------------------------------------------------------
39
-
40
- /**
41
- * Get the source text for a node, optionally with surrounding characters.
42
- *
43
- * When called with no arguments, returns the entire source text.
44
- * Pass an `Option<ESTree.Node>` to get text for a specific node.
45
- *
46
- * @since 0.2.0
47
- */
48
- export const getText: {
49
- (): Effect.Effect<string, never, RuleContext>;
50
- (
51
- node: Option.Option<ESTree.Node>,
52
- beforeCount?: number,
53
- afterCount?: number
54
- ): Effect.Effect<string, never, RuleContext>;
55
- } = (
56
- node?: Option.Option<ESTree.Node>,
57
- beforeCount?: number,
58
- afterCount?: number
59
- ): Effect.Effect<string, never, RuleContext> =>
60
- withSourceCode((sc) =>
61
- sc.getText(
62
- node === undefined
63
- ? null
64
- : Option.getOrElse(node, () => null as never),
65
- beforeCount,
66
- afterCount
67
- )
68
- );
69
-
70
- // ---------------------------------------------------------------------------
71
- // Ancestry
72
- // ---------------------------------------------------------------------------
73
-
74
- /**
75
- * Get the ancestor nodes of the given node, from innermost to outermost.
76
- *
77
- * Note: oxlint types `getAncestors` as returning `Node[]` where `Node`
78
- * is the base `Span` interface. At runtime these are full `ESTree.Node`
79
- * values — the cast bridges this upstream type gap at the FFI boundary.
80
- *
81
- * @since 0.2.0
82
- */
83
- export const getAncestors = (
84
- node: ESTree.Node
85
- ): Effect.Effect<ReadonlyArray<ESTree.Node>, never, RuleContext> =>
86
- withSourceCode(
87
- // oxlint-ignore(casting-awareness,avoid-any): FFI boundary —
88
- // oxlint's `Node` (Span) is structurally narrower than `ESTree.Node`
89
- // but the runtime values are full ESTree nodes.
90
- (sc) => sc.getAncestors(node) as unknown as ReadonlyArray<ESTree.Node>
91
- );
92
-
93
- // ---------------------------------------------------------------------------
94
- // Location / Range
95
- // ---------------------------------------------------------------------------
96
-
97
- /**
98
- * Get the AST node that contains the given source offset.
99
- *
100
- * Returns `Option.none()` when no node spans that offset.
101
- *
102
- * @since 0.2.0
103
- */
104
- export const getNodeByRangeIndex = (
105
- offset: number
106
- ): Effect.Effect<Option.Option<ESTree.Node>, never, RuleContext> =>
107
- withSourceCode((sc) =>
108
- Option.fromNullishOr(sc.getNodeByRangeIndex(offset))
109
- );
110
-
111
- /**
112
- * Convert a source offset (0-based) to a `{ line, column }` location.
113
- *
114
- * @since 0.2.0
115
- */
116
- export const getLocFromIndex = (
117
- offset: number
118
- ): Effect.Effect<LineColumn, never, RuleContext> =>
119
- withSourceCode((sc) => sc.getLocFromIndex(offset));
120
-
121
- /**
122
- * Convert a `{ line, column }` location to a source offset (0-based).
123
- *
124
- * @since 0.2.0
125
- */
126
- export const getIndexFromLoc = (
127
- loc: LineColumn
128
- ): Effect.Effect<number, never, RuleContext> =>
129
- withSourceCode((sc) => sc.getIndexFromLoc(loc));
130
-
131
- /**
132
- * Get the range `[start, end]` for a node or token.
133
- *
134
- * @since 0.2.0
135
- */
136
- export const getRange = (
137
- nodeOrToken: ESTree.Node | Token | Comment
138
- ): Effect.Effect<Range, never, RuleContext> =>
139
- withSourceCode((sc) => sc.getRange(nodeOrToken));
140
-
141
- // ---------------------------------------------------------------------------
142
- // Token queries (single node)
143
- // ---------------------------------------------------------------------------
144
-
145
- /**
146
- * Get the first token of a node.
147
- *
148
- * @since 0.2.0
149
- */
150
- export const getFirstToken = (
151
- node: ESTree.Node
152
- ): Effect.Effect<Option.Option<Token>, never, RuleContext> =>
153
- withSourceCode((sc) => Option.fromNullishOr(sc.getFirstToken(node)));
154
-
155
- /**
156
- * Get the last token of a node.
157
- *
158
- * @since 0.2.0
159
- */
160
- export const getLastToken = (
161
- node: ESTree.Node
162
- ): Effect.Effect<Option.Option<Token>, never, RuleContext> =>
163
- withSourceCode((sc) => Option.fromNullishOr(sc.getLastToken(node)));
164
-
165
- /**
166
- * Get all tokens for a node.
167
- *
168
- * @since 0.2.0
169
- */
170
- export const getTokens = (
171
- node: ESTree.Node
172
- ): Effect.Effect<ReadonlyArray<Token>, never, RuleContext> =>
173
- withSourceCode((sc) => sc.getTokens(node));
174
-
175
- // ---------------------------------------------------------------------------
176
- // Token queries (before / after)
177
- // ---------------------------------------------------------------------------
178
-
179
- /**
180
- * Get the token before a node or token.
181
- *
182
- * @since 0.2.0
183
- */
184
- export const getTokenBefore = (
185
- nodeOrToken: ESTree.Node | Token | Comment
186
- ): Effect.Effect<Option.Option<Token>, never, RuleContext> =>
187
- withSourceCode((sc) =>
188
- Option.fromNullishOr(sc.getTokenBefore(nodeOrToken))
189
- );
190
-
191
- /**
192
- * Get the token after a node or token.
193
- *
194
- * @since 0.2.0
195
- */
196
- export const getTokenAfter = (
197
- nodeOrToken: ESTree.Node | Token | Comment
198
- ): Effect.Effect<Option.Option<Token>, never, RuleContext> =>
199
- withSourceCode((sc) => Option.fromNullishOr(sc.getTokenAfter(nodeOrToken)));
200
-
201
- /**
202
- * Get all tokens between two nodes/tokens.
203
- *
204
- * @since 0.2.0
205
- */
206
- export const getTokensBetween = (
207
- left: ESTree.Node | Token | Comment,
208
- right: ESTree.Node | Token | Comment
209
- ): Effect.Effect<ReadonlyArray<Token>, never, RuleContext> =>
210
- withSourceCode((sc) => sc.getTokensBetween(left, right));
211
-
212
- /**
213
- * Get the first token between two nodes/tokens.
214
- *
215
- * @since 0.2.0
216
- */
217
- export const getFirstTokenBetween = (
218
- left: ESTree.Node | Token | Comment,
219
- right: ESTree.Node | Token | Comment
220
- ): Effect.Effect<Option.Option<Token>, never, RuleContext> =>
221
- withSourceCode((sc) =>
222
- Option.fromNullishOr(sc.getFirstTokenBetween(left, right))
223
- );
224
-
225
- /**
226
- * Find a token by its range start offset.
227
- *
228
- * @since 0.2.0
229
- */
230
- export const getTokenByRangeStart = (
231
- offset: number
232
- ): Effect.Effect<Option.Option<Token>, never, RuleContext> =>
233
- withSourceCode((sc) =>
234
- Option.fromNullishOr(sc.getTokenByRangeStart(offset))
235
- );
236
-
237
- // ---------------------------------------------------------------------------
238
- // Comment queries
239
- // ---------------------------------------------------------------------------
240
-
241
- /**
242
- * Get all comments in the file.
243
- *
244
- * @since 0.2.0
245
- */
246
- export const getAllComments = (): Effect.Effect<
247
- ReadonlyArray<Comment>,
248
- never,
249
- RuleContext
250
- > => withSourceCode((sc) => sc.getAllComments());
251
-
252
- /**
253
- * Get comments before a node or token.
254
- *
255
- * @since 0.2.0
256
- */
257
- export const getCommentsBefore = (
258
- nodeOrToken: ESTree.Node | Token | Comment
259
- ): Effect.Effect<ReadonlyArray<Comment>, never, RuleContext> =>
260
- withSourceCode((sc) => sc.getCommentsBefore(nodeOrToken));
261
-
262
- /**
263
- * Get comments after a node or token.
264
- *
265
- * @since 0.2.0
266
- */
267
- export const getCommentsAfter = (
268
- nodeOrToken: ESTree.Node | Token | Comment
269
- ): Effect.Effect<ReadonlyArray<Comment>, never, RuleContext> =>
270
- withSourceCode((sc) => sc.getCommentsAfter(nodeOrToken));
271
-
272
- /**
273
- * Get comments inside a node.
274
- *
275
- * @since 0.2.0
276
- */
277
- export const getCommentsInside = (
278
- node: ESTree.Node
279
- ): Effect.Effect<ReadonlyArray<Comment>, never, RuleContext> =>
280
- withSourceCode((sc) => sc.getCommentsInside(node));
281
-
282
- /**
283
- * Check whether comments exist between two nodes/tokens.
284
- *
285
- * @since 0.2.0
286
- */
287
- export const commentsExistBetween = (
288
- left: ESTree.Node | Token | Comment,
289
- right: ESTree.Node | Token | Comment
290
- ): Effect.Effect<boolean, never, RuleContext> =>
291
- withSourceCode((sc) => sc.commentsExistBetween(left, right));
292
-
293
- /**
294
- * Get the JSDoc comment for a node.
295
- *
296
- * @deprecated Upstream deprecation. Use `getCommentsBefore` instead.
297
- * @since 0.2.0
298
- */
299
- export const getJSDocComment = (
300
- node: ESTree.Node
301
- ): Effect.Effect<Option.Option<Comment>, never, RuleContext> =>
302
- withSourceCode((sc) => Option.fromNullishOr(sc.getJSDocComment(node)));
303
-
304
- // ---------------------------------------------------------------------------
305
- // Scope queries (delegated to SourceCode)
306
- // ---------------------------------------------------------------------------
307
-
308
- /**
309
- * Get the scope for a node.
310
- *
311
- * @since 0.2.0
312
- */
313
- export const getScope = (
314
- node: ESTree.Node
315
- ): Effect.Effect<Scope, never, RuleContext> =>
316
- withSourceCode((sc) => sc.getScope(node));
317
-
318
- /**
319
- * Get declared variables for a node.
320
- *
321
- * @since 0.2.0
322
- */
323
- export const getDeclaredVariables = (
324
- node: ESTree.Node
325
- ): Effect.Effect<ReadonlyArray<Variable>, never, RuleContext> =>
326
- withSourceCode((sc) => sc.getDeclaredVariables(node));
327
-
328
- /**
329
- * Check whether a node is a global reference.
330
- *
331
- * @since 0.2.0
332
- */
333
- export const isGlobalReference = (
334
- node: ESTree.Node
335
- ): Effect.Effect<boolean, never, RuleContext> =>
336
- withSourceCode((sc) => sc.isGlobalReference(node));
337
-
338
- /**
339
- * Mark a variable as used in the scope of the given node.
340
- *
341
- * @since 0.2.0
342
- */
343
- export const markVariableAsUsed = (
344
- name: string,
345
- refNode?: ESTree.Node
346
- ): Effect.Effect<boolean, never, RuleContext> =>
347
- withSourceCode((sc) => sc.markVariableAsUsed(name, refNode));
348
-
349
- // ---------------------------------------------------------------------------
350
- // Spacing
351
- // ---------------------------------------------------------------------------
352
-
353
- /**
354
- * Check whether there is a space between two nodes/tokens.
355
- *
356
- * @since 0.2.0
357
- */
358
- export const isSpaceBetween = (
359
- first: ESTree.Node | Token | Comment,
360
- second: ESTree.Node | Token | Comment
361
- ): Effect.Effect<boolean, never, RuleContext> =>
362
- withSourceCode((sc) => sc.isSpaceBetween(first, second));
363
-
364
- // ---------------------------------------------------------------------------
365
- // Lines
366
- // ---------------------------------------------------------------------------
367
-
368
- /**
369
- * Get all source lines.
370
- *
371
- * @since 0.2.0
372
- */
373
- export const getLines = (): Effect.Effect<
374
- ReadonlyArray<string>,
375
- never,
376
- RuleContext
377
- > => withSourceCode((sc) => sc.getLines());