A
A
AltaiR2020-06-03 14:19:51
JavaScript
AltaiR, 2020-06-03 14:19:51

How to properly set up ESLint, Prettier in 2020?

Hello. I read everything I found on this topic in Google. Almost all of them are outdated or do not suit me. Here's what I got when I collected all the information. I'm building an app with create-react-app . Here is what I have in my .eslintrc.json file :

{
  "env": {
    "browser": true,
    "es6": true
  },
  "extends": [
    "airbnb",
    "plugin:jsx-a11y/recommended",
    "prettier",
    "prettier/react"
  ],
  "plugins": ["react", "jsx-a11y", "prettier"], 
  "globals": {
    "Atomics": "readonly",
    "SharedArrayBuffer": "readonly"
  },
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 2018,
    "sourceType": "module"
  },
  "rules": {
    "prettier/prettier": "error",
    "react/jsx-filename-extension": [
      1,
      {
        "extensions": [".js"]
      }
    ],
    "no-shadow": "off",
    "react/state-in-constructor": [2, "never"]
  }
}


And here's what's in the VSCode settings :
{
  "editor.formatOnSave": true,
  "[javascript]": {
    "editor.formatOnSave": false // не понятно для чего эта строка
  },
  "editor.formatOnPaste": false,
  "javascript.format.enable": false,
  "javascript.validate.enable": false,
  "files.associations": {
    "*.jsx": "javascriptreact",
    "*.js": "javascriptreact"
  },
  "emmet.syntaxProfiles": {
    "javascript": "jsx"
  },
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "prettier.disableLanguages": ["js"],
}


And everything seems to be fine. It shows a syntax error. Formats when saving, etc. But problems arise in the following scenario:
In this file, it shows me an error that I need to remove the quotes from the properties:
5ed785a8cf232240812869.png
To remove this warning, I click Quick Fix and select Disable prettier/prettier for the entire file . It adds /* eslint-disable prettier/prettier */ to the top of the file and the warning is actually gone. But when saving the file, the quotes are still removed and the following error occurs in the browser:
5ed7873fd18c1360274173.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LEXA_JA, 2020-06-03
@AltaiR-05

It looks like the eslint config was picked up by VS Code, but not by create-react-app. If prettier errors do not appear in the browser, then most likely they are. It is necessary to look towards the Advanced configuration , specifically the flag "EXTEND_ESLINT"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question