Skip to content

[Feature]: Prefer import over require when both are present #651

@trivikr

Description

@trivikr

Self-service

  • I'd be willing to implement this feature

Problem

Some customers have been using the following to suppress maintenance mode message.

require('aws-sdk/lib/maintenance_mode_message').suppress = true;

The codemod detects this as file using require, and use requires for any new imports.

Example input:

import AWS from "aws-sdk";
require("aws-sdk/lib/maintenance_mode_message").suppress = true;

const client = new AWS.DynamoDB();

Example output:

const {
  DynamoDB
} = require("@aws-sdk/client-dynamodb");

import AWS from "aws-sdk";
require("aws-sdk/lib/maintenance_mode_message").suppress = true;

const client = new DynamoDB();

Expected output:

import { DynamoDB } from "@aws-sdk/client-dynamodb";

const client = new DynamoDB();

Solution

If both requires and imports are present for aws-sdk, prefer import.
Remove occurrences of require('aws-sdk/lib/maintenance_mode_message')

Alternatives

N/A

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions