Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring ESLint and Prettier to automatically fix 'import/no-duplicates' error in Visual Studio Code on save

I have the ESLint and Prettier extensions installed in Visual Studio Code, and I have configured the "Editor: Format on Save" option, which is working well for other errors. However, I am still encountering the "import/no-duplicates" error, and it is not being automatically fixed on save. I have already tried to resolve the issue by making changes in the .prettierrc and .eslintrc.json files, but to no avail. Can someone help me configure ESLint and Prettier to automatically fix the "import/no-duplicates" error on save in Visual Studio Code?

{
  "env": {
    "browser": true,
    "es2021": true
  },
  "extends": [
    "next/core-web-vitals",
    "plugin:react/recommended",
    "airbnb",
    "plugin:@next/next/recommended",
    "prettier"
  ],
  "overrides": [],
  "parserOptions": {
    "ecmaVersion": "latest",
    "sourceType": "module"
  },
  "plugins": ["react", "prettier", "import"],
  "rules": {
    "prettier/prettier": ["error"],
    "react/react-in-jsx-scope": "off",
    "react/prop-types": "off",
    "react/jsx-props-no-spreading": "off",
    "import/extensions": "off",
    "import/no-unresolved": [
      2,
      {
        "ignore": ["^@/", "^~~/", "^/"]
      }
    ],
    "import/no-duplicates": "error"
  }
}
{
    "singleQuote": true,
    "importOrder": ["^[./]","^components/(.*)$","^@/" ],
    "importOrderSeparation": true, 
    "importOrderSortSpecifiers": true 
}
like image 779
purple pillow Avatar asked Jan 26 '26 04:01

purple pillow


1 Answers

Get eslint plugin, add this code to your settings.json

 {  
    "editor.codeActionsOnSave": {
        "source.fixAll.eslint": true
    },
    "eslint.validate": ["javascript"]
 }

source

like image 194
Jorge Pérez Avatar answered Jan 28 '26 16:01

Jorge Pérez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!