@blumintinc/eslint-plugin-blumint 1.17.1 → 1.17.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/lib/index.js CHANGED
@@ -217,7 +217,7 @@ function noFrontendImportsFromFunctionsPatterns(pattern) {
217
217
  module.exports = {
218
218
  meta: {
219
219
  name: '@blumintinc/eslint-plugin-blumint',
220
- version: '1.17.1',
220
+ version: '1.17.2',
221
221
  },
222
222
  parseOptions: {
223
223
  ecmaVersion: 2020,
@@ -241,6 +241,41 @@ function isTypeGuardFunction(node) {
241
241
  }
242
242
  return false;
243
243
  }
244
+ // The names below are the built-in TypeScript read-only wrapper types. When a
245
+ // function is annotated with one of these, the annotation is NOT redundant:
246
+ // TypeScript always infers the mutable concrete type (e.g. Set<T> not
247
+ // ReadonlySet<T>), so stripping the annotation silently changes the public
248
+ // return type and lets callers mutate internal state that the author intended
249
+ // to protect.
250
+ const READONLY_TYPE_NAMES = new Set([
251
+ 'ReadonlySet',
252
+ 'ReadonlyMap',
253
+ 'ReadonlyArray',
254
+ 'Readonly',
255
+ ]);
256
+ /**
257
+ * Returns true when `returnType` is a read-only widening annotation — i.e.
258
+ * one that TypeScript would NOT infer on its own and whose removal therefore
259
+ * changes the public API. Two forms are covered:
260
+ *
261
+ * TSTypeReference — ReadonlySet<T>, ReadonlyMap<K,V>, ReadonlyArray<T>,
262
+ * Readonly<T>
263
+ * TSTypeOperator — `readonly T[]` and `readonly [a, b]` tuples
264
+ */
265
+ function isReadonlyWideningReturnType(returnType) {
266
+ const typeAnnotation = returnType.typeAnnotation;
267
+ if (typeAnnotation.type === utils_1.AST_NODE_TYPES.TSTypeReference) {
268
+ const typeName = typeAnnotation.typeName;
269
+ return (typeName.type === utils_1.AST_NODE_TYPES.Identifier &&
270
+ READONLY_TYPE_NAMES.has(typeName.name));
271
+ }
272
+ // `readonly T[]` and `readonly [a, b]` are represented as TSTypeOperator
273
+ // nodes with operator === 'readonly'.
274
+ if (typeAnnotation.type === utils_1.AST_NODE_TYPES.TSTypeOperator) {
275
+ return typeAnnotation.operator === 'readonly';
276
+ }
277
+ return false;
278
+ }
244
279
  exports.noExplicitReturnType = (0, createRule_1.createRule)({
245
280
  name: 'no-explicit-return-type',
246
281
  meta: {
@@ -297,6 +332,7 @@ exports.noExplicitReturnType = (0, createRule_1.createRule)({
297
332
  if (!returnType)
298
333
  return;
299
334
  if (isTypeGuardFunction(node) ||
335
+ isReadonlyWideningReturnType(returnType) ||
300
336
  (mergedOptions.allowRecursiveFunctions && isRecursiveFunction(node))) {
301
337
  return;
302
338
  }
@@ -320,6 +356,7 @@ exports.noExplicitReturnType = (0, createRule_1.createRule)({
320
356
  return;
321
357
  }
322
358
  if (isTypeGuardFunction(node) ||
359
+ isReadonlyWideningReturnType(returnType) ||
323
360
  (mergedOptions.allowRecursiveFunctions && isRecursiveFunction(node))) {
324
361
  return;
325
362
  }
@@ -334,7 +371,8 @@ exports.noExplicitReturnType = (0, createRule_1.createRule)({
334
371
  const returnType = node.returnType;
335
372
  if (!returnType)
336
373
  return;
337
- if (isTypeGuardFunction(node)) {
374
+ if (isTypeGuardFunction(node) ||
375
+ isReadonlyWideningReturnType(returnType)) {
338
376
  return;
339
377
  }
340
378
  context.report({
@@ -366,6 +404,7 @@ exports.noExplicitReturnType = (0, createRule_1.createRule)({
366
404
  if (!returnType)
367
405
  return;
368
406
  if (isTypeGuardFunction(node.value) ||
407
+ isReadonlyWideningReturnType(returnType) ||
369
408
  (mergedOptions.allowAbstractMethodSignatures &&
370
409
  isInterfaceOrAbstractMethodSignature(node))) {
371
410
  return;
@@ -10,7 +10,12 @@ const COMMON_TYPES = [
10
10
  'Boolean',
11
11
  'Array',
12
12
  'Object',
13
- 'Function',
13
+ // 'Function' is intentionally excluded. Unlike an incidental, rot-prone data
14
+ // type (String/Number/...), a value named *Function is intrinsically and
15
+ // permanently callable, so the marker can never become misleading. Fn/Func/
16
+ // Function are function-ROLE designators (like callback/handler/predicate),
17
+ // not Hungarian type tags — compareFn/mapFn are the ECMAScript/MDN-canonical
18
+ // parameter names. See the ABBREVIATION_MARKERS note and issue #1255.
14
19
  // 'Date', too many false positives
15
20
  'RegExp',
16
21
  'Promise',
@@ -20,16 +25,11 @@ const COMMON_TYPES = [
20
25
  // Abbreviation type markers (e.g. str, arr, obj). No English word is spelled this
21
26
  // way, so their presence as a segment — even in the middle of a name — is
22
27
  // unambiguously a type tag (strName, USER_STR_NAME, ConfigArrSettings).
23
- const ABBREVIATION_MARKERS = [
24
- 'str',
25
- 'num',
26
- 'int',
27
- 'bool',
28
- 'arr',
29
- 'obj',
30
- 'fn',
31
- 'func',
32
- ];
28
+ // `fn`/`func` are deliberately excluded: they abbreviate a value's callable ROLE
29
+ // (like callback/handler/predicate), which is intrinsic and never rots, so
30
+ // checkFn/compareFn/mapFn/renderFunc are legitimate role names, not Hungarian
31
+ // type tags (#1255).
32
+ const ABBREVIATION_MARKERS = ['str', 'num', 'int', 'bool', 'arr', 'obj'];
33
33
  // Combined type markers (former Hungarian prefixes and type suffixes)
34
34
  const TYPE_MARKERS = [
35
35
  ...ABBREVIATION_MARKERS,
@@ -53,7 +53,7 @@ const SINGLE_LETTER_PREFIXES = new Set(['b', 'i']);
53
53
  // allowed compound noun PhoneNumber. Abbreviation markers (str/arr/obj/...) are
54
54
  // deliberately excluded: no English word is spelled that way, so their presence
55
55
  // as a segment is unambiguously a type tag even inside a type name.
56
- const FULL_TYPE_WORDS = new Set([...COMMON_TYPES, 'Func'].map((word) => word.toLowerCase()));
56
+ const FULL_TYPE_WORDS = new Set(COMMON_TYPES.map((word) => word.toLowerCase()));
57
57
  // Allowed descriptive suffixes that should not be flagged as Hungarian notation
58
58
  const ALLOWED_SUFFIXES = [
59
59
  'Formatted',
@@ -218,7 +218,7 @@ function splitCamelSegments(name) {
218
218
  // A TYPE name (alias/interface/class) is exempt from a full-type-word marker when
219
219
  // that marker is one clean PascalCase segment among OTHER descriptive segments —
220
220
  // i.e. the word denotes a type concept/relation, not a redundant type tag.
221
- // Examples: StringToNumber, CapitalizedString, PromiseOrValue, FuncKeys.
221
+ // Examples: StringToNumber, CapitalizedString, PromiseOrValue.
222
222
  // Abbreviation markers (str/arr/obj/...) never qualify, so genuine Hungarian type
223
223
  // names like UserStrName / ConfigArrSettings / UserObjData still fire.
224
224
  function isSemanticTypeConcept(typeName) {
@@ -177,9 +177,13 @@ exports.noTypeAssertionReturns = (0, createRule_1.createRule)({
177
177
  if (node.parent?.type === utils_1.AST_NODE_TYPES.LogicalExpression) {
178
178
  return true;
179
179
  }
180
- // Allow type assertions within method calls like array.includes()
181
- if (node.parent?.type === utils_1.AST_NODE_TYPES.CallExpression &&
182
- node.parent.callee.type === utils_1.AST_NODE_TYPES.MemberExpression) {
180
+ // Allow type assertions that are direct arguments of any call or new expression.
181
+ // The asserted value is an argument — TypeScript structurally checks it against the
182
+ // parameter type so the returned value is the call's result, not the cast itself.
183
+ // This covers method calls (obj.method(x as T)), plain calls (fn(x as T)), and
184
+ // constructors (new Ctor(x as T)) uniformly.
185
+ if (node.parent?.type === utils_1.AST_NODE_TYPES.CallExpression ||
186
+ node.parent?.type === utils_1.AST_NODE_TYPES.NewExpression) {
183
187
  return true;
184
188
  }
185
189
  // Allow type assertions within array includes checks
@@ -195,27 +199,6 @@ exports.noTypeAssertionReturns = (0, createRule_1.createRule)({
195
199
  if (isPropertyAccess(node) && isInsideConditionalStatement(node)) {
196
200
  return true;
197
201
  }
198
- // Allow type assertions in object instantiations (as constructor arguments)
199
- if (node.parent?.type === utils_1.AST_NODE_TYPES.ObjectExpression &&
200
- node.parent.parent?.type === utils_1.AST_NODE_TYPES.NewExpression) {
201
- return true;
202
- }
203
- // Allow type assertions as arguments to constructors
204
- if (node.parent?.type === utils_1.AST_NODE_TYPES.NewExpression ||
205
- (node.parent?.type === utils_1.AST_NODE_TYPES.CallExpression &&
206
- node.parent.parent?.type === utils_1.AST_NODE_TYPES.NewExpression)) {
207
- return true;
208
- }
209
- // Allow type assertions as arguments to constructor calls
210
- if (node.parent?.type === utils_1.AST_NODE_TYPES.CallExpression) {
211
- let current = node.parent;
212
- while (current?.parent) {
213
- if (current.parent.type === utils_1.AST_NODE_TYPES.NewExpression) {
214
- return true;
215
- }
216
- current = current.parent;
217
- }
218
- }
219
202
  // Allow type assertions in JSX attributes/props or object properties
220
203
  if (isInsideJSXAttributeOrObjectProperty(node)) {
221
204
  return true;
@@ -59,9 +59,6 @@ const COMMON_PREPOSITION_SUFFIXES = new Set([
59
59
  'Where',
60
60
  'When',
61
61
  'While',
62
- // Programming-specific suffixes
63
- 'Async',
64
- 'Sync',
65
62
  ]);
66
63
  /**
67
64
  * Phrasal-verb particles that fuse with a preceding past participle to form an
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blumintinc/eslint-plugin-blumint",
3
- "version": "1.17.1",
3
+ "version": "1.17.2",
4
4
  "description": "Custom eslint rules for use within BluMint",
5
5
  "author": {
6
6
  "name": "Brodie McGuire",
@@ -1,4 +1,42 @@
1
1
  [
2
+ {
3
+ "version": "1.17.2",
4
+ "date": "2026-07-02T12:29:19.590Z",
5
+ "rules": [
6
+ {
7
+ "name": "no-explicit-return-type",
8
+ "changeType": "fix",
9
+ "issues": [
10
+ 1253
11
+ ],
12
+ "summary": "exempt read-only widening return types from removal (closes #1253)"
13
+ },
14
+ {
15
+ "name": "no-hungarian",
16
+ "changeType": "fix",
17
+ "issues": [
18
+ 1255
19
+ ],
20
+ "summary": "treat Fn/Func/Function as function-role designators, not type tags (closes #1255)"
21
+ },
22
+ {
23
+ "name": "no-type-assertion-returns",
24
+ "changeType": "fix",
25
+ "issues": [
26
+ 1254
27
+ ],
28
+ "summary": "allow type assertions as call/new arguments in return position (closes #1254)"
29
+ },
30
+ {
31
+ "name": "no-unnecessary-verb-suffix",
32
+ "changeType": "fix",
33
+ "issues": [
34
+ 1252
35
+ ],
36
+ "summary": "stop flagging Async/Sync execution-model suffixes (closes #1252)"
37
+ }
38
+ ]
39
+ },
2
40
  {
3
41
  "version": "1.17.1",
4
42
  "date": "2026-07-01T22:31:34.840Z",