ESLint config to spot when two imports from different locations import the same name

22 Views Asked by At

I've been using ESLint for years but this is the first time I've encountered this problem. We had a merge issue where two import statements were kept in the same file that were importing from different locations, but used the same import name, e.g.

import { DuplicatedName } from "src/MyFile";

import { DuplicatedName } from "src/test/MyFile";

This caused errors when running the app, but I was surprised our lint config hadn't either warned or errored on this, given I thought we had it setup to both warn/error on unused vars and unused imports. Can anyone point me in the right direction as to which rule should actually spot this, and why our config below doesn't do that?

module.exports = { 
  parser: "@typescript-eslint/parser", 
  parserOptions: { 
    ecmaVersion: 2020, 
    sourceType: "module", 
    ecmaFeatures: { jsx: true, }, 
  }, 
  settings: { 
    react: { 
      version: "detect", 
    }, 
  }, 
  extends: ["plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
    
  plugins: ["@typescript-eslint", "simple-import-sort", "unused-imports", "prettier"], 
  rules: { 
    "react/display-name": "off", 
    "simple-import-sort/imports": "error", 
    "simple-import-sort/exports": "error", 
    "@typescript-eslint/ban-ts-comment": "off", 
    "@typescript-eslint/no-unused-vars":
   
      [ "warn", 
        { 
          argsIgnorePattern: "^_", 
          varsIgnorePattern: "^_", 
          caughtErrorsIgnorePattern: "^_", 
        }, 
      ], 
    "unused-imports/no-unused-imports": "error", 
    "@typescript-eslint/no-empty-function": "off", 
    "@typescript-eslint/no-var-requires":
"off", 
  }, 
};
0

There are 0 best solutions below