@blumintinc/eslint-plugin-blumint 1.20.58 → 1.20.59
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 +1 -1
- package/lib/rules/prefer-type-over-interface.js +48 -0
- package/package.json +1 -1
- package/release-manifest.json +14 -0
package/lib/index.js
CHANGED
|
@@ -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
package/release-manifest.json
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "1.20.59",
|
|
4
|
+
"date": "2026-08-01T04:43:54.837Z",
|
|
5
|
+
"rules": [
|
|
6
|
+
{
|
|
7
|
+
"name": "prefer-type-over-interface",
|
|
8
|
+
"changeType": "fix",
|
|
9
|
+
"issues": [
|
|
10
|
+
1549
|
|
11
|
+
],
|
|
12
|
+
"summary": "exempt module augmentations (closes #1549)"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
},
|
|
2
16
|
{
|
|
3
17
|
"version": "1.20.58",
|
|
4
18
|
"date": "2026-08-01T04:26:49.434Z",
|