eslint-plugin-awscdk 4.3.2 → 4.3.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/dist/index.cjs +804 -551
- package/dist/index.d.cts +59 -59
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +59 -59
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +803 -550
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/core/ast-node/finder/enclosing-class.ts +12 -0
- package/src/rules/no-variable-construct-id.ts +15 -0
- package/src/rules/require-passing-this.ts +8 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-awscdk",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.3",
|
|
4
4
|
"description": "eslint plugin for AWS CDK projects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aws",
|
|
@@ -51,15 +51,15 @@
|
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@eslint/js": "^10.0.1",
|
|
54
|
-
"@secretlint/secretlint-rule-preset-recommend": "^
|
|
54
|
+
"@secretlint/secretlint-rule-preset-recommend": "^13.0.0",
|
|
55
55
|
"@types/node": "^24.10.13",
|
|
56
56
|
"@typescript-eslint/parser": "^8.58.0",
|
|
57
57
|
"@typescript-eslint/rule-tester": "^8.58.0",
|
|
58
58
|
"@typescript-eslint/utils": "^8.58.0",
|
|
59
59
|
"@voidzero-dev/vite-plus-core": "^0.1.11",
|
|
60
60
|
"eslint": "^10.0.0",
|
|
61
|
-
"secretlint": "^
|
|
62
|
-
"typescript": "^
|
|
61
|
+
"secretlint": "^13.0.0",
|
|
62
|
+
"typescript": "^6.0.2",
|
|
63
63
|
"typescript-eslint": "^8.58.0",
|
|
64
64
|
"vite-plus": "^0.1.11"
|
|
65
65
|
},
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/utils";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Find the enclosing ClassDeclaration from a given node
|
|
5
|
+
* @param node The node to start searching from
|
|
6
|
+
* @returns The enclosing ClassDeclaration or undefined if not found
|
|
7
|
+
*/
|
|
8
|
+
export const findEnclosingClass = (node: TSESTree.Node): TSESTree.ClassDeclaration | undefined => {
|
|
9
|
+
if (!node.parent) return undefined;
|
|
10
|
+
if (node.parent.type === AST_NODE_TYPES.ClassDeclaration) return node.parent;
|
|
11
|
+
return findEnclosingClass(node.parent);
|
|
12
|
+
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { AST_NODE_TYPES, ESLintUtils, TSESLint, TSESTree } from "@typescript-eslint/utils";
|
|
2
2
|
|
|
3
|
+
import { findEnclosingClass } from "../core/ast-node/finder/enclosing-class";
|
|
3
4
|
import { isConstructType } from "../core/cdk-construct/type-checker/is-construct";
|
|
5
|
+
import { isConstructOrStackType } from "../core/cdk-construct/type-checker/is-construct-or-stack";
|
|
4
6
|
import { findConstructorPropertyNames } from "../core/ts-type/finder/constructor-property-name";
|
|
5
7
|
import { createRule } from "../shared/create-rule";
|
|
6
8
|
|
|
@@ -32,6 +34,13 @@ export const noVariableConstructId = createRule({
|
|
|
32
34
|
|
|
33
35
|
if (!isConstructType(type) || node.arguments.length < 2) return;
|
|
34
36
|
|
|
37
|
+
// NOTE: Skip when inside a class that is not Construct/Stack
|
|
38
|
+
const enclosingClass = findEnclosingClass(node);
|
|
39
|
+
const enclosingClassType = enclosingClass
|
|
40
|
+
? parserServices.getTypeAtLocation(enclosingClass)
|
|
41
|
+
: undefined;
|
|
42
|
+
if (enclosingClassType && !isConstructOrStackType(enclosingClassType)) return;
|
|
43
|
+
|
|
35
44
|
const constructorPropertyNames = findConstructorPropertyNames(type);
|
|
36
45
|
if (constructorPropertyNames[1] !== "id") return;
|
|
37
46
|
|
|
@@ -96,6 +105,12 @@ const shouldSkipIdValidation = (node: TSESTree.Node): boolean => {
|
|
|
96
105
|
return true;
|
|
97
106
|
}
|
|
98
107
|
|
|
108
|
+
// Constructs in standalone functions (outside of classes) are intended to be called
|
|
109
|
+
// multiple times with different IDs
|
|
110
|
+
if (current.type === AST_NODE_TYPES.FunctionDeclaration) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
|
|
99
114
|
current = current.parent;
|
|
100
115
|
}
|
|
101
116
|
return false;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { AST_NODE_TYPES, ESLintUtils, TSESLint } from "@typescript-eslint/utils";
|
|
2
2
|
|
|
3
|
+
import { findEnclosingClass } from "../core/ast-node/finder/enclosing-class";
|
|
3
4
|
import { isConstructType } from "../core/cdk-construct/type-checker/is-construct";
|
|
5
|
+
import { isConstructOrStackType } from "../core/cdk-construct/type-checker/is-construct-or-stack";
|
|
4
6
|
import { findConstructorPropertyNames } from "../core/ts-type/finder/constructor-property-name";
|
|
5
7
|
import { createRule } from "../shared/create-rule";
|
|
6
8
|
|
|
@@ -53,6 +55,12 @@ export const requirePassingThis = createRule({
|
|
|
53
55
|
|
|
54
56
|
if (!isConstructType(type) || !node.arguments.length) return;
|
|
55
57
|
|
|
58
|
+
// NOTE: Only flag when inside a Construct/Stack class where `this` is available
|
|
59
|
+
const enclosingClass = findEnclosingClass(node);
|
|
60
|
+
if (!enclosingClass) return;
|
|
61
|
+
const enclosingClassType = parserServices.getTypeAtLocation(enclosingClass);
|
|
62
|
+
if (!isConstructOrStackType(enclosingClassType)) return;
|
|
63
|
+
|
|
56
64
|
const argument = node.arguments[0];
|
|
57
65
|
|
|
58
66
|
// NOTE: If the first argument is already `this`, it's valid
|