Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kenberkeley opened this issue Nov 28, 2022 · 1 comment

Comments

@kenberkeley
Copy link

kenberkeley commented Nov 28, 2022

Cause

node.superClass.object.name === 'cdk' &&

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

  • import { Stack } from "aws-cdk-lib", or
  • Patch eslint-plugin-cdk@1.8.0 with ⬇️
- node.superClass.object.name === 'cdk' &&
+ node.superClass.object.name.toLowerCase() === 'cdk' &&
@kenberkeley kenberkeley changed the title [eslint-plugin-cdk] doesn't work if I rename the import [eslint-plugin-cdk/rules/ban-lambda-runtimes] doesn't work if I rename the import Nov 28, 2022
@kenberkeley
Copy link
Author

Same for ⬇️

if (node.object.type === AST_NODE_TYPES.MemberExpression) {
if (
hasName(node.object.object, 'lambda') &&
hasName(node.object.property, 'Runtime')
) {
checkRuntime(node.property);
}
return;
}
if (hasName(node.object, 'Runtime')) {
checkRuntime(node.property);
return;
}

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant