eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

Disallow duplicate require

Open edi9999 opened this issue 2 years ago • 9 comments

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 ?

edi9999 avatar Nov 18 '23 14:11 edi9999

Try adding commonjs: true?

ljharb avatar Nov 18 '23 15:11 ljharb

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 avatar Nov 18 '23 17:11 edi9999

Still the same issue

edi9999 avatar Nov 18 '23 17:11 edi9999

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.

edi9999 avatar Nov 18 '23 17:11 edi9999

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

ljharb avatar Nov 18 '23 20:11 ljharb

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

edi9999 avatar Nov 22 '23 20:11 edi9999

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

edi9999 avatar Nov 22 '23 20:11 edi9999

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

soryy708 avatar Sep 03 '24 20:09 soryy708

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

ljharb avatar Sep 03 '24 23:09 ljharb