question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ESLint + Prettier integration

See original GitHub issue

I’m trying to configure ESLint with Prettier in VSCode and that is how it looks like:

package.json:

{
  "scripts": {
    "start": "nodemon bin/www",
    "lint": "eslint src",
    "precommit": "lint-staged"
  },
  "lint-staged": {
    "src/**/*.js": [
      "eslint --fix src",
      "git add"
    ]
  },
  "devDependencies": {
    "eslint": "^5.5.0",
    "eslint-config-airbnb-base": "^13.1.0",
    "eslint-config-prettier": "^3.0.1",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-prettier": "^2.6.2",
    "husky": "^0.14.3",
    "lint-staged": "^7.2.2",
    "nodemon": "^1.18.4",
    "prettier": "^1.14.2"
  }
}

.eslintrc.json:

{
  "extends": ["airbnb-base", "plugin:prettier/recommended"]
}

The prettier extension is installed on VSCode, the only thing left was to put this on the settings:

{
  "editor.formatOnSave": true,
  "prettier.eslintIntegration": true,
}

It worked like a charm, now the thing is that I’m trying to override a few settings like singleQuote: true and semi: false. I tried to create a .prettierrc file like this:

{
  "singleQuote": true,
  "semi": false
}

It does work in the VsCode, it fix the code from double quotes to single and removes all the semicolons, the problem is that it appears this error:

image

It’s like a conflict between ESLint and Prettier.

I was reading the documentation and I saw that "plugin:prettier/recommended" in the .eslintrc already adds "rules": { "prettier/prettier": ["error"] } so I did like this:

  • Removed the .prettierrc file
  • Added the "rules": { "prettier/prettier": ["error"] } as "rules": { "prettier/prettier": ["error", { "singleQuote": true, "semi": false }] }

It worked, but now I’m wondering if I’m duplicating anything as the plugin is already adding this, or if .prettierrc is better suited for this.

What are your solutions for this?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
hasusozamcommented, Sep 14, 2018

For some (God knows what) reason it works now, I don’t know if it’s a vscode problem but it seems to be working now. Thank you very much.

0reactions
hasusozamcommented, Sep 14, 2018

That is weird, I really don’t know what is happening.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Integrating with Linters - Prettier
Use Prettier for code formatting concerns, and linters for code-quality concerns, as outlined in Prettier vs. Linters. Luckily it's easy to turn off...
Read more >
How to use Prettier with ESLint - Robin Wieruch
ESLint knows about all your Prettier rules by integrating all the rules that are enforced by it and removing all the rules that...
Read more >
Using Prettier and ESLint to automate formatting and fixing ...
Learn how to use ESLint and Prettier together to automatically format and fix JavaScript code in your projects.
Read more >
How to use Prettier with ESLint and TypeScript in VSCode
In this guide, we'll explain how to use Prettier with ESLint, ... Combining both ESLint and Prettier, the responsibility division is this:.
Read more >
eslint-plugin-prettier - npm
Runs Prettier as an ESLint rule and reports differences as individual ESLint issues. If your desired formatting does not match Prettier's output ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found