@onrails/eslint-plugin 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,6 +20,7 @@ export default [
20
20
  rules: {
21
21
  "@onrails/no-promise-result": "warn",
22
22
  "@onrails/no-unsafe-unwrap": "warn",
23
+ "@onrails/no-deprecated-synonyms": "warn",
23
24
  },
24
25
  },
25
26
  ];
@@ -46,6 +47,7 @@ export default [
46
47
  |---|---|
47
48
  | `@onrails/no-promise-result` | Flags `Promise<Result<…>>` in source — public APIs should return `ResultAsync` |
48
49
  | `@onrails/no-unsafe-unwrap` | Flags `_unsafeUnwrap*` outside test files |
50
+ | `@onrails/no-deprecated-synonyms` | Flags deprecated synonyms (`chain`, `fold`, `getOrElse`, `of`, …) and suggests the canonical names |
49
51
 
50
52
  ## Caveats (v0)
51
53
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onrails/eslint-plugin",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "ESLint rules for @onrails/result boundaries — flags Promise<Result<…>> in public APIs and _unsafeUnwrap*. Replaces unmaintained eslint-plugin-neverthrow.",
5
5
  "license": "MIT",
6
6
  "author": "Alan R. Soares",
package/src/index.js CHANGED
@@ -131,6 +131,75 @@ const noUnsafeUnwrap = {
131
131
  },
132
132
  };
133
133
 
134
+ /**
135
+ * Deprecated synonym → canonical rename tables. Hand-copied from
136
+ * `@onrails/codemod` `src/boundary-spec.ts` (cross-package imports are
137
+ * forbidden); `packages/codemod/test/boundary-conformance.spec.ts` keeps the
138
+ * copies in sync with the spec and the Biome `no-deprecated-synonyms.grit`.
139
+ */
140
+
141
+ /** Flagged as `x.name(…)`. `isOk` / `isErr` map to the same-named free-function guards. */
142
+ const DEPRECATED_METHOD_RENAMES = new Map([
143
+ ["chain", "flatMap"],
144
+ ["isOk", "isOk"],
145
+ ["isErr", "isErr"],
146
+ ]);
147
+
148
+ /** Flagged as `name(…)`. */
149
+ const DEPRECATED_CALL_RENAMES = new Map([
150
+ ["fold", "match"],
151
+ ["matchResult", "match"],
152
+ ["matchMaybe", "match"],
153
+ ["getOrElse", "unwrapOr"],
154
+ ["sequenceTupleAsync", "ResultAsync.combineTuple"],
155
+ ["collect", "combine"],
156
+ ["of", "ok"],
157
+ ]);
158
+
159
+ /** @type {import('eslint').Rule.RuleModule} */
160
+ const noDeprecatedSynonyms = {
161
+ meta: {
162
+ type: "suggestion",
163
+ docs: {
164
+ description:
165
+ "Flag deprecated railway/maybe synonyms (chain, fold, getOrElse, of, …) and suggest the canonical onrails names. Matching is name-based; same-named functions from other libraries are flagged too.",
166
+ },
167
+ schema: [],
168
+ messages: {
169
+ rename: "{{name}}() is a deprecated onrails synonym — use {{canonical}}() instead.",
170
+ narrowGuard:
171
+ "Deprecated .{{name}}() method — await the ResultAsync and narrow with the {{name}}() free function instead.",
172
+ },
173
+ },
174
+ create(context) {
175
+ return {
176
+ CallExpression(node) {
177
+ const callee = node.callee;
178
+ if (callee.type === "Identifier") {
179
+ const canonical = DEPRECATED_CALL_RENAMES.get(callee.name);
180
+ if (canonical) {
181
+ context.report({
182
+ node,
183
+ messageId: "rename",
184
+ data: { name: callee.name, canonical },
185
+ });
186
+ }
187
+ return;
188
+ }
189
+ if (callee.type !== "MemberExpression" || callee.property.type !== "Identifier") return;
190
+ const name = callee.property.name;
191
+ const canonical = DEPRECATED_METHOD_RENAMES.get(name);
192
+ if (!canonical) return;
193
+ context.report(
194
+ canonical === name
195
+ ? { node, messageId: "narrowGuard", data: { name } }
196
+ : { node, messageId: "rename", data: { name, canonical } },
197
+ );
198
+ },
199
+ };
200
+ },
201
+ };
202
+
134
203
  /** @type {import('eslint').ESLint.Plugin} */
135
204
  const plugin = {
136
205
  meta: {
@@ -140,6 +209,7 @@ const plugin = {
140
209
  rules: {
141
210
  "no-promise-result": noPromiseResult,
142
211
  "no-unsafe-unwrap": noUnsafeUnwrap,
212
+ "no-deprecated-synonyms": noDeprecatedSynonyms,
143
213
  },
144
214
  };
145
215
 
@@ -153,6 +223,7 @@ export const configs = {
153
223
  rules: {
154
224
  "@onrails/result/no-promise-result": "warn",
155
225
  "@onrails/result/no-unsafe-unwrap": "warn",
226
+ "@onrails/result/no-deprecated-synonyms": "warn",
156
227
  },
157
228
  },
158
229
  };