Does the Eslint option of "enforce code style" add any behavior when we are already using Prettier?

Asked

Viewed 339 times

2

When we perform eslint --init, we first come across the following question:

inserir a descrição da imagem aqui

I performed two tests, one selecting "To check syntax and find problems" and other using "To check syntax, find problems, and enforce code style", for this last option I still chose the Style Guide Standard. In the final tests I obtained the same behavior for stylization and linting.

My question is: because it is using prettier with eslint-config-prettier and eslint-plugin-prettier, still it is recommended to select "To check syntax, find problems, and enforce code style"? From what I could understand analyzing the project, when using Prettier this would be unnecessary since the Prettier by default is already adhering to Style Guide Standard, but I’m still not sure if this reasoning is correct.

My file .eslintrc.json:

{
  "env": {
    "es6": true,
    "node": true
  },
  "extends": [
    "standard",
    "prettier"
  ],
  "globals": {
    "Atomics": "readonly",
    "SharedArrayBuffer": "readonly"
  },
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 2018,
    "sourceType": "module"
  },
  "plugins": [
    "prettier"
  ],
  "rules": {
    "prettier/prettier": "error"
  }
}

1 answer

4


It is not really necessary, since Prettier is already responsible for formatting the code, that is, making changes to the "style" of the code. Such as, for example:

  • Semicolon (optional in most cases);
  • Indentation;
  • Type of quotation marks to be used (single, double...);
  • And more options.

Thus, there is no need to make Eslint would end up formatting the code, playing the role of Prettier. There is even eslint-config-prettier, which disables all Eslint rules that conflict with Prettier:

Turns off all Rules that are unnecessary or Might Conflict with Prettier.

And, regarding the title of the question, "The Eslint option of "enforce code style" adds some behavior when we are already using Prettier?", yes, by making Eslint also responsible for code style, some rules will be added that may even conflict with Prettier. It is for this, moreover, that the aforementioned eslint-config-prettier.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.