eslint-plugin-prettier: How to disable error Insert `⏎` prettier/prettier?

JSX File:

import React from "react";
import TemplateWrapper from "../layouts/index";

const IndexPage = () => (
  <TemplateWrapper>
    <h1>Hi people</h1>
    <p>Welcome to your Blog.</p>
    <p>Now go build something great.</p>
  </TemplateWrapper>
);

export default IndexPage;  // error  Insert `⏎`  prettier/prettier

ESLint config:

{
  "root": true,
  "env": {
    "browser": true,
    "es6": true,
    "node": true,
    "jest": true
  },
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 2018,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true,
      "modules": true
    }
  },
  "plugins": ["react", "react-hooks", "jsx-a11y", "import"],
  "extends": [
    "airbnb",
    "eslint:recommended",
    "plugin:prettier/recommended",
    "prettier/react",
    "prettier/standard",
    "plugin:react/recommended",
    "plugin:import/errors",
    "plugin:import/warnings",
    "plugin:jsx-a11y/recommended"
  ],
  "settings": {
    "react": {
      "version": "detect"
    }
  },
  "rules": {
    "no-unused-vars": ["warn"],
    "prettier/prettier": ["error", {"singleQuote": false}],
//    "prettier/prettier": ["error", {"singleQuote": false}],
    "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
    "react/jsx-uses-react": 1,
    "react/jsx-uses-vars": 1,
    "react/react-in-jsx-scope": 1,
    "react-hooks/rules-of-hooks": "error",
    "react-hooks/exhaustive-deps": "warn",
    "react/display-name": 0,
    "react/prop-types": [0, { "ignore": ["children"] }],
    "jsx-a11y/anchor-is-valid": 0
  }
}

Prettier config:

{
  "trailingComma": "none",
  "semi": true,
  "tabWidth": 2,
  "singleQuote": false,
  "bracketSpacing": true,
  "jsxBracketSameLine": true
}

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 18 (2 by maintainers)

Most upvoted comments

I just had the same problem with the difference being that linting worked locally (using Windows) but failed on the Linux CI machine. Solved it by adding

"prettier/prettier": ["error", {
    "endOfLine":"auto"
  }],

to the rules section in .eslintrc

just disable or transform in a warning, in your eslintrc rules

module.exports = {
 //... other settings
 rules: {
     //... other rules
    // use 'off' instead of "warn" to disable the rule and the error message
    'prettier/prettier': [   'warn',   {
        endOfLine: 'auto',
      },
    ],
  },

Sounds like you need to insert a trailing new line at the end of your file.

Adding "plugins": ["prettier"] in .eslintrc and

"prettier/prettier": [
      "error",
      {
         "printWidth": 200
      }
  ]

PrintWidth controls the width of printer and It lets you add words in same line and will not complain to add a new line.

One of prettier’s standard formattings is that files must end with a newline character as per the POSIX Standard. There is no option for change that.

{
  "trailingComma": "none",
  "semi": true,
  "tabWidth": 2,
  "singleQuote": false,
  "bracketSpacing": true,
  "jsxBracketSameLine": true
}

This has solved my problem in Vue.

In package.json 😉

  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/vue3-essential",
      "eslint:recommended",
      "plugin:prettier/recommended"
    ],
    "parserOptions": {
      "parser": "@babel/eslint-parser"
    },
    "rules": {
      "prettier/prettier": ["error", {
        "endOfLine":"auto"
      }]
    }
  },

I used Snaptags solution and worked temporally and then came back. Manage to fix it by following full installation steps on https://github.com/prettier/eslint-plugin-prettier Now I don’t have Vscode + Prettier + Eslint fighting each other.

For others that find this, the correct solution we’ve found is to make sure that the CI linter’s prettier version matches the one on your local environment. In our case, we found that our local machines were running 1.19.1 but the CI suite was running 2.0.5 which have major improvements to the way line lengths are handled/trimmed.

Hi - I found this post because I’m getting the same error… in nvim. I hit return and can only guess that I have the newline at the end of the line… Here is the error I’m getting… is there something I need to configure (encoding) perhaps?

Screen Shot 2019-09-03 at 11 52 11 AM

Thank you in advance for taking a quick look.

- E