hupe1980 / cdkdx

Zero-config CLI for aws cdk development
MIT License
38 stars 8 forks source link

[eslint-plugin-cdk/rules/ban-lambda-runtimes] doesn't work if I rename the import #39

Open kenberkeley opened 1 year ago

kenberkeley commented 1 year ago

Cause

https://github.com/hupe1980/cdkdx/blob/28df1ba253bd250c854fc1d94edc9a830e85fd94/packages/eslint-plugin-cdk/src/utils/cdk.ts#L20

This line of code ⬆️ enforces we use the name cdk to import "all" from aws-cdk-lib.

e.g.

import * as cdk from "aws-cdk-lib" // ✅ works!
import * as Cdk from "aws-cdk-lib" // ❌ doesn't work!

Reason

You might be curious why I would wanna use other import names like Cdk. Well, let's take a look at React:

// 😌
import * as React from "react"
<React.Fragment />
React.useState()

// 🥴
import * as react from "react"
<react.Fragment />
react.useState()

From the above example, we can see that capitalizing the name of import "all" makes more sense.

Workaround

- node.superClass.object.name === 'cdk' &&
+ node.superClass.object.name.toLowerCase() === 'cdk' &&
kenberkeley commented 1 year ago

Same for ⬇️

https://github.com/hupe1980/cdkdx/blob/28df1ba253bd250c854fc1d94edc9a830e85fd94/packages/eslint-plugin-cdk/src/rules/ban-lambda-runtimes.ts#L74-L87

We can not assume all the developers would write import { Runtime } from "aws-cdk-lib/aws-lambda". What if somebody writes import { Runtime as LambdaRuntime } from "aws-cdk-lib/aws-lambda" to void this rule check?