@onrails/eslint-plugin 0.1.1 → 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.1",
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
@@ -94,11 +94,13 @@ const noUnsafeUnwrap = {
94
94
  meta: {
95
95
  type: "suggestion",
96
96
  docs: {
97
- description: "Discourage _unsafeUnwrap / _unsafeUnwrapErr outside tests.",
97
+ description:
98
+ "Discourage _unsafeUnwrap / _unsafeUnwrapErr and unwrapOk / unwrapErr / unwrap outside tests. Matching is name-based; same-named functions from other libraries are flagged too.",
98
99
  },
99
100
  schema: [],
100
101
  messages: {
101
- unsafe: "Avoid _unsafeUnwrap* — use match(), resolve(), or yieldResult() in tryGen.",
102
+ unsafe:
103
+ "Avoid _unsafeUnwrap* and unwrap* outside tests — use match(), resolve(), or yieldResult() in tryGen.",
102
104
  },
103
105
  },
104
106
  create(context) {
@@ -115,6 +117,85 @@ const noUnsafeUnwrap = {
115
117
  context.report({ node, messageId: "unsafe" });
116
118
  }
117
119
  },
120
+ CallExpression(node) {
121
+ if (
122
+ node.callee.type === "Identifier" &&
123
+ (node.callee.name === "unwrapOk" ||
124
+ node.callee.name === "unwrapErr" ||
125
+ node.callee.name === "unwrap")
126
+ ) {
127
+ context.report({ node, messageId: "unsafe" });
128
+ }
129
+ },
130
+ };
131
+ },
132
+ };
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
+ },
118
199
  };
119
200
  },
120
201
  };
@@ -128,6 +209,7 @@ const plugin = {
128
209
  rules: {
129
210
  "no-promise-result": noPromiseResult,
130
211
  "no-unsafe-unwrap": noUnsafeUnwrap,
212
+ "no-deprecated-synonyms": noDeprecatedSynonyms,
131
213
  },
132
214
  };
133
215
 
@@ -141,6 +223,7 @@ export const configs = {
141
223
  rules: {
142
224
  "@onrails/result/no-promise-result": "warn",
143
225
  "@onrails/result/no-unsafe-unwrap": "warn",
226
+ "@onrails/result/no-deprecated-synonyms": "warn",
144
227
  },
145
228
  },
146
229
  };