Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert `··` prettier/prettier

I have a project that has both prettier and eslint installed. The problem is that when I save a file eslint automatically changes the format of the file and it seems some rules conflict with prettier. What is the solution?

This is prettier formatting: enter image description here

When saved, the file changes to: enter image description here

Also this is eslintrc file

{
  "parser": "@typescript-eslint/parser",
  "extends": [
    "plugin:react/recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:prettier/recommended",
    "prettier/@typescript-eslint"
  ],
  "rules": {
    "@typescript-eslint/explicit-function-return-type": "off",
    "@typescript-eslint/no-explicit-any": "off",
    "@typescript-eslint/ban-ts-ignore": "off",
    "@typescript-eslint/interface-name-prefix": "off",
    "@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }]
  },
  "overrides": [
    {
      "files": ["**/*.tsx"],
      "rules": {
        "react/prop-types": "off"
      }
    }
  ],
  "settings": {
    "react": {
      "version": "detect"
    }
  },
  "ignorePatterns": ["coverage/", "node_modules/", "src/serviceWorker.ts"]
}
like image 249
Saber Avatar asked Jul 31 '20 17:07

Saber


People also ask

How do I fix Prettier Prettier error?

This error is related to Windows Line endings being different from Unix ones. Try running npx prettier --write . on your project's directory. This command will tell prettier to fix simple errors (such as this one) when found.

What is Printwidth Prettier?

Print WidthSpecify the line length that the printer will wrap on. For readability we recommend against using more than 80 characters: In code styleguides, maximum line length rules are often set to 100 or 120. However, when humans write code, they don't strive to reach the maximum number of columns on every line.


2 Answers

Not fully configuring ESlint and Prettier can cause a myriad of issues. To avoid all of them follow the steps mentioned in How to use Prettier with ESLint and TypeScript in VSCode , also remove any extra setting in config files for ESlint, Prettier and setting.json for VScod that might override other rules.

Important: Based on the answer here: Uninstall prettier-eslint extension.

like image 138
Saber Avatar answered Oct 14 '22 17:10

Saber


.prettierrc

{
  "printWidth": 160
}
like image 40
weiya ou Avatar answered Oct 14 '22 17:10

weiya ou