Skip to content

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

@kenberkeley

Description

@kenberkeley

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' &&

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions