Search code examples
eslintprettier

Eslint & Prettier conflicts (eslint-config-prettier not wokring)


I have this simple example, where statements dont have semicolons. Prettier settings have the semi to false but eslint has the semi to true. I order to not have conflicts between them i installed the eslint-config-prettier. But i still get an error with the semicolons. It is supposed to prevail the prettier setting, but its does not.

var var1, var2
var1 = 3
var2 = 4
var a = { name: "" }


 "devDependencies": {
    "eslint": "^7.8.1",
    "eslint-config-prettier": "^6.11.0",
    "eslint-plugin-prettier": "^3.1.4",
    "prettier": "^2.1.1"
  }

.prettierrcc

{
  "arrowParens": "always",
  "bracketSpacing": true,
  "htmlWhitespaceSensitivity": "css",
  "insertPragma": false,
  "jsxBracketSameLine": false,
  "jsxSingleQuote": false,
  "printWidth": 86,
  "proseWrap": "preserve",
  "quoteProps": "preserve",
  "requirePragma": false,
  "semi": false,
  "singleQuote": false,
  "tabWidth": 2,
  "trailingComma": "es5",
  "useTabs": false,
  "vueIndentScriptAndStyle": false
}

.eslintrcc

{
  "root": true,
  "env": {
    "node": true
  },
  "extends": ["prettier"],
  "plugins": ["prettier"],
  "rules": {
    "semi": ["error", "always"],
    "prettier/prettier": ["error"]
  }
}

I get the following error:

/home/nick/Documents/Coding/NodeJs/simple-node/vanilla.js
  1:17  error  Missing semicolon  semi
  2:11  error  Missing semicolon  semi
  3:9   error  Missing semicolon  semi
  4:21  error  Missing semicolon  semi

Solution

  • You are overwriting the Prettier config which is indeed set to "off" by default (link to config), with a custom rule who does the opposite of what you want. Simply remove it:

      "rules": {
        "prettier/prettier": ["error"]
      }