eslint-cdk-plugin 1.0.3 → 1.0.4
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 +0 -1
- package/dist/index.cjs +193712 -0
- package/dist/index.mjs +193712 -0
- package/package.json +1 -1
- package/src/rules/no-construct-stack-suffix.ts +5 -0
- package/src/rules/no-variable-construct-id.ts +4 -0
- package/src/rules/pascal-case-construct-id.ts +5 -0
- package/src/rules/require-passing-this.ts +4 -0
- package/src/utils/parseType.ts +20 -0
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from "@typescript-eslint/utils";
|
|
7
7
|
|
|
8
8
|
import { toPascalCase } from "../utils/convertString";
|
|
9
|
+
import { getConstructorPropertyNames } from "../utils/parseType";
|
|
9
10
|
import { isConstructOrStackType } from "../utils/typeCheck";
|
|
10
11
|
|
|
11
12
|
type Context = TSESLint.RuleContext<"noConstructStackSuffix", []>;
|
|
@@ -38,6 +39,10 @@ export const noConstructStackSuffix = ESLintUtils.RuleCreator.withoutDocs({
|
|
|
38
39
|
if (!isConstructOrStackType(type) || node.arguments.length < 2) {
|
|
39
40
|
return;
|
|
40
41
|
}
|
|
42
|
+
|
|
43
|
+
const constructorPropertyNames = getConstructorPropertyNames(type);
|
|
44
|
+
if (constructorPropertyNames[1] !== "id") return;
|
|
45
|
+
|
|
41
46
|
validateConstructId(node, context);
|
|
42
47
|
},
|
|
43
48
|
};
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
TSESTree,
|
|
6
6
|
} from "@typescript-eslint/utils";
|
|
7
7
|
|
|
8
|
+
import { getConstructorPropertyNames } from "../utils/parseType";
|
|
8
9
|
import { isConstructType, isStackType } from "../utils/typeCheck";
|
|
9
10
|
|
|
10
11
|
type Context = TSESLint.RuleContext<"noVariableConstructId", []>;
|
|
@@ -40,6 +41,9 @@ export const noVariableConstructId = ESLintUtils.RuleCreator.withoutDocs({
|
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
const constructorPropertyNames = getConstructorPropertyNames(type);
|
|
45
|
+
if (constructorPropertyNames[1] !== "id") return;
|
|
46
|
+
|
|
43
47
|
validateConstructId(node, context);
|
|
44
48
|
},
|
|
45
49
|
};
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from "@typescript-eslint/utils";
|
|
7
7
|
|
|
8
8
|
import { toPascalCase } from "../utils/convertString";
|
|
9
|
+
import { getConstructorPropertyNames } from "../utils/parseType";
|
|
9
10
|
import { isConstructOrStackType } from "../utils/typeCheck";
|
|
10
11
|
|
|
11
12
|
const QUOTE_TYPE = {
|
|
@@ -45,6 +46,10 @@ export const pascalCaseConstructId = ESLintUtils.RuleCreator.withoutDocs({
|
|
|
45
46
|
if (!isConstructOrStackType(type) || node.arguments.length < 2) {
|
|
46
47
|
return;
|
|
47
48
|
}
|
|
49
|
+
|
|
50
|
+
const constructorPropertyNames = getConstructorPropertyNames(type);
|
|
51
|
+
if (constructorPropertyNames[1] !== "id") return;
|
|
52
|
+
|
|
48
53
|
validateConstructId(node, context);
|
|
49
54
|
},
|
|
50
55
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
2
2
|
|
|
3
|
+
import { getConstructorPropertyNames } from "../utils/parseType";
|
|
3
4
|
import { isConstructType, isStackType } from "../utils/typeCheck";
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -38,6 +39,9 @@ export const requirePassingThis = ESLintUtils.RuleCreator.withoutDocs({
|
|
|
38
39
|
const argument = node.arguments[0];
|
|
39
40
|
if (argument.type === AST_NODE_TYPES.ThisExpression) return;
|
|
40
41
|
|
|
42
|
+
const constructorPropertyNames = getConstructorPropertyNames(type);
|
|
43
|
+
if (constructorPropertyNames[0] !== "scope") return;
|
|
44
|
+
|
|
41
45
|
context.report({
|
|
42
46
|
node,
|
|
43
47
|
messageId: "requirePassingThis",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isClassDeclaration, isConstructorDeclaration, Type } from "typescript";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parses type to get the property names of the class constructor.
|
|
5
|
+
* @returns The property names of the class constructor.
|
|
6
|
+
*/
|
|
7
|
+
export const getConstructorPropertyNames = (type: Type): string[] => {
|
|
8
|
+
const declarations = type.symbol?.declarations;
|
|
9
|
+
if (!declarations?.length) return [];
|
|
10
|
+
|
|
11
|
+
const classDeclaration = declarations[0];
|
|
12
|
+
if (!isClassDeclaration(classDeclaration)) return [];
|
|
13
|
+
|
|
14
|
+
const constructor = classDeclaration.members.find((member) =>
|
|
15
|
+
isConstructorDeclaration(member)
|
|
16
|
+
);
|
|
17
|
+
if (!constructor?.parameters.length) return [];
|
|
18
|
+
|
|
19
|
+
return constructor.parameters.map((param) => param.name.getText());
|
|
20
|
+
};
|