eslint-cdk-plugin 1.0.4 → 1.0.5

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 CHANGED
@@ -193779,19 +193779,18 @@ const getConstructorPropertyNames = (type) => {
193779
193779
  return constructor.parameters.map((param) => param.name.getText());
193780
193780
  };
193781
193781
 
193782
- const isConstructOrStackType = (type) => {
193782
+ const isConstructOrStackType = (type, ignoredClasses = ["App", "Stage"]) => {
193783
+ if (ignoredClasses.includes(type.symbol?.name ?? "")) return false;
193783
193784
  return isTargetSuperClassType(
193784
193785
  type,
193785
193786
  ["Construct", "Stack"],
193786
193787
  isConstructOrStackType
193787
193788
  );
193788
193789
  };
193789
- const isConstructType = (type) => {
193790
+ const isConstructType = (type, ignoredClasses = ["App", "Stage", "Stack"]) => {
193791
+ if (ignoredClasses.includes(type.symbol?.name ?? "")) return false;
193790
193792
  return isTargetSuperClassType(type, ["Construct"], isConstructType);
193791
193793
  };
193792
- const isStackType = (type) => {
193793
- return isTargetSuperClassType(type, ["Stack"], isStackType);
193794
- };
193795
193794
  const isTargetSuperClassType = (type, targetSuperClasses, typeCheckFunction) => {
193796
193795
  if (!type.symbol) return false;
193797
193796
  if (targetSuperClasses.some((suffix) => type.symbol.name.endsWith(suffix))) {
@@ -194317,9 +194316,7 @@ const noVariableConstructId = utils.ESLintUtils.RuleCreator.withoutDocs({
194317
194316
  return {
194318
194317
  NewExpression(node) {
194319
194318
  const type = parserServices.getTypeAtLocation(node);
194320
- if (!isConstructType(type) || isStackType(type) || node.arguments.length < 2) {
194321
- return;
194322
- }
194319
+ if (!isConstructType(type) || node.arguments.length < 2) return;
194323
194320
  const constructorPropertyNames = getConstructorPropertyNames(type);
194324
194321
  if (constructorPropertyNames[1] !== "id") return;
194325
194322
  validateConstructId$1(node, context);
@@ -194423,9 +194420,7 @@ const requirePassingThis = utils.ESLintUtils.RuleCreator.withoutDocs({
194423
194420
  return {
194424
194421
  NewExpression(node) {
194425
194422
  const type = parserServices.getTypeAtLocation(node);
194426
- if (!isConstructType(type) || isStackType(type) || !node.arguments.length) {
194427
- return;
194428
- }
194423
+ if (!isConstructType(type) || !node.arguments.length) return;
194429
194424
  const argument = node.arguments[0];
194430
194425
  if (argument.type === utils.AST_NODE_TYPES.ThisExpression) return;
194431
194426
  const constructorPropertyNames = getConstructorPropertyNames(type);
package/dist/index.mjs CHANGED
@@ -193756,19 +193756,18 @@ const getConstructorPropertyNames = (type) => {
193756
193756
  return constructor.parameters.map((param) => param.name.getText());
193757
193757
  };
193758
193758
 
193759
- const isConstructOrStackType = (type) => {
193759
+ const isConstructOrStackType = (type, ignoredClasses = ["App", "Stage"]) => {
193760
+ if (ignoredClasses.includes(type.symbol?.name ?? "")) return false;
193760
193761
  return isTargetSuperClassType(
193761
193762
  type,
193762
193763
  ["Construct", "Stack"],
193763
193764
  isConstructOrStackType
193764
193765
  );
193765
193766
  };
193766
- const isConstructType = (type) => {
193767
+ const isConstructType = (type, ignoredClasses = ["App", "Stage", "Stack"]) => {
193768
+ if (ignoredClasses.includes(type.symbol?.name ?? "")) return false;
193767
193769
  return isTargetSuperClassType(type, ["Construct"], isConstructType);
193768
193770
  };
193769
- const isStackType = (type) => {
193770
- return isTargetSuperClassType(type, ["Stack"], isStackType);
193771
- };
193772
193771
  const isTargetSuperClassType = (type, targetSuperClasses, typeCheckFunction) => {
193773
193772
  if (!type.symbol) return false;
193774
193773
  if (targetSuperClasses.some((suffix) => type.symbol.name.endsWith(suffix))) {
@@ -194294,9 +194293,7 @@ const noVariableConstructId = ESLintUtils.RuleCreator.withoutDocs({
194294
194293
  return {
194295
194294
  NewExpression(node) {
194296
194295
  const type = parserServices.getTypeAtLocation(node);
194297
- if (!isConstructType(type) || isStackType(type) || node.arguments.length < 2) {
194298
- return;
194299
- }
194296
+ if (!isConstructType(type) || node.arguments.length < 2) return;
194300
194297
  const constructorPropertyNames = getConstructorPropertyNames(type);
194301
194298
  if (constructorPropertyNames[1] !== "id") return;
194302
194299
  validateConstructId$1(node, context);
@@ -194400,9 +194397,7 @@ const requirePassingThis = ESLintUtils.RuleCreator.withoutDocs({
194400
194397
  return {
194401
194398
  NewExpression(node) {
194402
194399
  const type = parserServices.getTypeAtLocation(node);
194403
- if (!isConstructType(type) || isStackType(type) || !node.arguments.length) {
194404
- return;
194405
- }
194400
+ if (!isConstructType(type) || !node.arguments.length) return;
194406
194401
  const argument = node.arguments[0];
194407
194402
  if (argument.type === AST_NODE_TYPES.ThisExpression) return;
194408
194403
  const constructorPropertyNames = getConstructorPropertyNames(type);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-cdk-plugin",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "eslint plugin for AWS CDK projects",
5
5
  "main": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -6,7 +6,7 @@ import {
6
6
  } from "@typescript-eslint/utils";
7
7
 
8
8
  import { getConstructorPropertyNames } from "../utils/parseType";
9
- import { isConstructType, isStackType } from "../utils/typeCheck";
9
+ import { isConstructType } from "../utils/typeCheck";
10
10
 
11
11
  type Context = TSESLint.RuleContext<"noVariableConstructId", []>;
12
12
 
@@ -33,13 +33,7 @@ export const noVariableConstructId = ESLintUtils.RuleCreator.withoutDocs({
33
33
  NewExpression(node) {
34
34
  const type = parserServices.getTypeAtLocation(node);
35
35
 
36
- if (
37
- !isConstructType(type) ||
38
- isStackType(type) ||
39
- node.arguments.length < 2
40
- ) {
41
- return;
42
- }
36
+ if (!isConstructType(type) || node.arguments.length < 2) return;
43
37
 
44
38
  const constructorPropertyNames = getConstructorPropertyNames(type);
45
39
  if (constructorPropertyNames[1] !== "id") return;
@@ -1,7 +1,7 @@
1
1
  import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
2
2
 
3
3
  import { getConstructorPropertyNames } from "../utils/parseType";
4
- import { isConstructType, isStackType } from "../utils/typeCheck";
4
+ import { isConstructType } from "../utils/typeCheck";
5
5
 
6
6
  /**
7
7
  * Enforces that `this` is passed to the constructor
@@ -28,13 +28,7 @@ export const requirePassingThis = ESLintUtils.RuleCreator.withoutDocs({
28
28
  NewExpression(node) {
29
29
  const type = parserServices.getTypeAtLocation(node);
30
30
 
31
- if (
32
- !isConstructType(type) ||
33
- isStackType(type) ||
34
- !node.arguments.length
35
- ) {
36
- return;
37
- }
31
+ if (!isConstructType(type) || !node.arguments.length) return;
38
32
 
39
33
  const argument = node.arguments[0];
40
34
  if (argument.type === AST_NODE_TYPES.ThisExpression) return;
@@ -5,9 +5,14 @@ type SuperClassType = "Construct" | "Stack";
5
5
  /**
6
6
  * Check if the type extends Construct or Stack
7
7
  * @param type - The type to check
8
+ * @param ignoredClasses - Classes that inherit from Construct Class or Stack Class but do not want to be treated as Construct Class or Stack Class
8
9
  * @returns True if the type extends Construct or Stack, otherwise false
9
10
  */
10
- export const isConstructOrStackType = (type: Type): boolean => {
11
+ export const isConstructOrStackType = (
12
+ type: Type,
13
+ ignoredClasses: readonly string[] = ["App", "Stage"] as const
14
+ ): boolean => {
15
+ if (ignoredClasses.includes(type.symbol?.name ?? "")) return false;
11
16
  return isTargetSuperClassType(
12
17
  type,
13
18
  ["Construct", "Stack"],
@@ -18,21 +23,17 @@ export const isConstructOrStackType = (type: Type): boolean => {
18
23
  /**
19
24
  * Check if the type extends Construct
20
25
  * @param type - The type to check
26
+ * @param ignoredClasses - Classes that inherit from Construct Class but do not want to be treated as Construct Class
21
27
  * @returns True if the type extends Construct, otherwise false
22
28
  */
23
- export const isConstructType = (type: Type): boolean => {
29
+ export const isConstructType = (
30
+ type: Type,
31
+ ignoredClasses: readonly string[] = ["App", "Stage", "Stack"] as const
32
+ ): boolean => {
33
+ if (ignoredClasses.includes(type.symbol?.name ?? "")) return false;
24
34
  return isTargetSuperClassType(type, ["Construct"], isConstructType);
25
35
  };
26
36
 
27
- /**
28
- * Check if the type extends Stack
29
- * @param type - The type to check
30
- * @returns True if the type extends Stack, otherwise false
31
- */
32
- export const isStackType = (type: Type): boolean => {
33
- return isTargetSuperClassType(type, ["Stack"], isStackType);
34
- };
35
-
36
37
  /**
37
38
  * Check if the type extends target super class
38
39
  * @param type - The type to check