Skip to content

Disallow duplicate require #2925

Open
@edi9999

Description

@edi9999

I have following code :

const { addCellToRow } = require("./cell-utils.js");
const { setCellValue, findCell, createCell } = require("./cell-utils.js");

Both require are using the same path, and should thus be grouped.

I've tried to enable this in my .eslintrc :

"import/no-duplicates": ["error", {"prefer-inline": true}],

But it didn't have any effect.

Are there any rules that can catch this ?

Activity

ljharb

ljharb commented on Nov 18, 2023

@ljharb
Member

Try adding commonjs: true?

edi9999

edi9999 commented on Nov 18, 2023

@edi9999
Author

Do you mean, in my .eslintrc,

  "env": {
    "node": true,
    "commonjs": true,
    "mocha": true
  },

I've tried just that and it didn't change anything.

edi9999

edi9999 commented on Nov 18, 2023

@edi9999
Author

Still the same issue

edi9999

edi9999 commented on Nov 18, 2023

@edi9999
Author

I've also tried : "import/no-unresolved": [2, {commonjs: true, amd: true}],,

and also :

   "import/no-duplicates": [
      "error",
      { "prefer-inline": true, "commonjs": true }
    ],

But both didn't work.

ljharb

ljharb commented on Nov 18, 2023

@ljharb
Member

The latter is what I meant; if that doesn't work, then it seems like a good enhancement PR to make to the rule.

edi9999

edi9999 commented on Nov 22, 2023

@edi9999
Author

I confirm that it doesn't work with the latter either.

edi9999

edi9999 commented on Nov 22, 2023

@edi9999
Author

I'm sorry I won't have much time to work on this issue.

linked a pull request that will close this issue on Nov 26, 2023
soryy708

soryy708 commented on Sep 3, 2024

@soryy708
Collaborator

Doesn't that overlap with ESLint's existing no-duplicate-imports rule?

ljharb

ljharb commented on Sep 3, 2024

@ljharb
Member

Yes, by design - that rule can't take advantage of custom resolvers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @ljharb@edi9999@soryy708

      Issue actions

        Disallow duplicate require · Issue #2925 · import-js/eslint-plugin-import