@blumintinc/eslint-plugin-blumint 1.20.58 → 1.20.60

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
@@ -223,7 +223,7 @@ function noFrontendImportsFromFunctionsPatterns(pattern) {
223
223
  module.exports = {
224
224
  meta: {
225
225
  name: '@blumintinc/eslint-plugin-blumint',
226
- version: '1.20.58',
226
+ version: '1.20.60',
227
227
  },
228
228
  parseOptions: {
229
229
  ecmaVersion: 2020,
@@ -41,19 +41,36 @@ const NON_PLURALIZABLE_SUFFIXES = [
41
41
  * the reference itself as a container.
42
42
  */
43
43
  const ARRAY_GENERIC_NAMES = new Set(['Array', 'ReadonlyArray']);
44
+ /**
45
+ * Union members that only express absence. Stripping them keeps a nullable
46
+ * container recognisable as a container: `T[]` and `T[] | null` describe the
47
+ * same collection, so they must not disagree about whether a plural name fits.
48
+ */
49
+ const NULLISH_TYPE_NODES = new Set([
50
+ utils_1.AST_NODE_TYPES.TSNullKeyword,
51
+ utils_1.AST_NODE_TYPES.TSUndefinedKeyword,
52
+ ]);
53
+ /**
54
+ * Shared budget for wrapper peeling and union recursion. Wrapper nesting is
55
+ * finite in real code; the cap only guards against a pathological cycle. Every
56
+ * peel and every descent into a union member spends one unit, so the recursion
57
+ * a union introduces stays bounded by the same constant.
58
+ */
59
+ const MAX_TYPE_DEPTH = 10;
44
60
  /**
45
61
  * Returns true when the type alias RHS resolves to a container shape — a
46
62
  * `TSArrayType` (`Foo[]`) or `TSTupleType` (`[A, B]`) — for which a plural name
47
63
  * is the correct, self-documenting choice. Sees through identity-ish wrappers
48
64
  * over the same shape: the `readonly` type operator, parenthesized types, and
49
65
  * the `Readonly<T>` utility type; `Array<T>`/`ReadonlyArray<T>` are containers
50
- * outright.
66
+ * outright. A union whose non-nullish members are all containers counts too.
67
+ *
68
+ * @param depth Budget already spent by an enclosing wrapper or union member.
51
69
  */
52
- function resolvesToContainerType(node) {
70
+ function resolvesToContainerType(node, depth = 0) {
53
71
  let current = node;
54
72
  // Fixpoint loop: peel identity wrappers until a concrete shape is reached.
55
- // Wrappers are finite; the cap only guards against a pathological cycle.
56
- for (let i = 0; i < 10; i++) {
73
+ for (let i = depth; i < MAX_TYPE_DEPTH; i++) {
57
74
  switch (current.type) {
58
75
  case utils_1.AST_NODE_TYPES.TSArrayType:
59
76
  case utils_1.AST_NODE_TYPES.TSTupleType:
@@ -66,6 +83,18 @@ function resolvesToContainerType(node) {
66
83
  current = operator.typeAnnotation;
67
84
  continue;
68
85
  }
86
+ case utils_1.AST_NODE_TYPES.TSUnionType: {
87
+ const union = current;
88
+ const substantive = union.types.filter((member) => !NULLISH_TYPE_NODES.has(member.type));
89
+ // `null | undefined` holds no collection at all.
90
+ if (substantive.length === 0)
91
+ return false;
92
+ // Requiring EVERY remaining member to be a container keeps the
93
+ // exemption conservative: a mixed union such as `Edge[] | Edge` can hold
94
+ // a single value, so a plural name there still misleads. Members recurse
95
+ // with the spent budget so nesting cannot escape the cap.
96
+ return substantive.every((member) => resolvesToContainerType(member, i + 1));
97
+ }
69
98
  case utils_1.AST_NODE_TYPES.TSTypeReference: {
70
99
  const ref = current;
71
100
  if (ref.typeName.type !== utils_1.AST_NODE_TYPES.Identifier)
@@ -2,6 +2,51 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.preferTypeOverInterface = void 0;
4
4
  const createRule_1 = require("../utils/createRule");
5
+ const utils_1 = require("@typescript-eslint/utils");
6
+ /**
7
+ * A module augmentation targets either an external module
8
+ * (`declare module 'pkg'`, whose id is a string literal) or the global scope
9
+ * (`declare global`). Declaration merging is the whole point of such a block
10
+ * and only `interface` can merge, so the `type` rewrite does not merely change
11
+ * style: it drops the augmentation and collides with the original declaration
12
+ * (TS2300 "Duplicate identifier").
13
+ *
14
+ * A plain `namespace X` — including the ambient `declare namespace X`, whose
15
+ * id is an identifier — augments nothing, so interfaces inside it stay
16
+ * reportable and a type alias works there.
17
+ */
18
+ function isModuleAugmentation(node) {
19
+ if (node.id.type === utils_1.AST_NODE_TYPES.Literal &&
20
+ typeof node.id.value === 'string') {
21
+ return true;
22
+ }
23
+ // `declare global` carries a dedicated flag, which also covers the bare
24
+ // `global { ... }` form nested inside an ambient module (that form has no
25
+ // `declare` of its own).
26
+ if (node.global === true) {
27
+ return true;
28
+ }
29
+ // Parser versions that predate the `global` flag spell the same block as an
30
+ // ambient module whose id is the `global` keyword. Requiring `declare` keeps
31
+ // an ordinary `namespace global { ... }` reportable.
32
+ return (node.declare === true &&
33
+ node.id.type === utils_1.AST_NODE_TYPES.Identifier &&
34
+ node.id.name === 'global');
35
+ }
36
+ /**
37
+ * The interface need not be a direct child of the augmentation block; it can
38
+ * sit inside a nested namespace or any other container within it, so the whole
39
+ * ancestor chain is inspected.
40
+ */
41
+ function isInsideModuleAugmentation(node) {
42
+ for (let ancestor = node.parent; ancestor; ancestor = ancestor.parent) {
43
+ if (ancestor.type === utils_1.AST_NODE_TYPES.TSModuleDeclaration &&
44
+ isModuleAugmentation(ancestor)) {
45
+ return true;
46
+ }
47
+ }
48
+ return false;
49
+ }
5
50
  exports.preferTypeOverInterface = (0, createRule_1.createRule)({
6
51
  name: 'prefer-type-over-interface',
7
52
  meta: {
@@ -22,6 +67,9 @@ exports.preferTypeOverInterface = (0, createRule_1.createRule)({
22
67
  create(context) {
23
68
  return {
24
69
  TSInterfaceDeclaration(node) {
70
+ if (isInsideModuleAugmentation(node)) {
71
+ return;
72
+ }
25
73
  context.report({
26
74
  node,
27
75
  messageId: 'preferType',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blumintinc/eslint-plugin-blumint",
3
- "version": "1.20.58",
3
+ "version": "1.20.60",
4
4
  "description": "Custom eslint rules for use within BluMint",
5
5
  "author": {
6
6
  "name": "Brodie McGuire",
@@ -1,4 +1,32 @@
1
1
  [
2
+ {
3
+ "version": "1.20.60",
4
+ "date": "2026-08-01T05:06:58.616Z",
5
+ "rules": [
6
+ {
7
+ "name": "enforce-singular-type-names",
8
+ "changeType": "fix",
9
+ "issues": [
10
+ 1550
11
+ ],
12
+ "summary": "keep the container exemption when nullable (closes #1550)"
13
+ }
14
+ ]
15
+ },
16
+ {
17
+ "version": "1.20.59",
18
+ "date": "2026-08-01T04:43:54.837Z",
19
+ "rules": [
20
+ {
21
+ "name": "prefer-type-over-interface",
22
+ "changeType": "fix",
23
+ "issues": [
24
+ 1549
25
+ ],
26
+ "summary": "exempt module augmentations (closes #1549)"
27
+ }
28
+ ]
29
+ },
2
30
  {
3
31
  "version": "1.20.58",
4
32
  "date": "2026-08-01T04:26:49.434Z",