Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prettier rule "no-multiple-empty-lines" not working in React.js project

I want to have an ability to use 2 blank lines in some parts of my code. Prettier default behaviour allows to have 1 blank line maximum.

I've tried to use "no-multiple-empty-lines": [2, {"max": 2 }] but it doesn't work at all and prettier still complains.

This is my .eslintrc config file. If you need any other information please let me know.

{
  "env": {
    "node": true,
    "browser": true,
    "es6": true,
    "commonjs": true
  },
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 6,
    "ecmaFeatures": {
      "jsx": true,
      "modules": true
    },
    "sourceType": "module"
  },
  "extends": [
    "eslint:recommended",
    "plugin:prettier/recommended",
    "plugin:react/recommended"
  ],
  "rules": {
    "prettier/prettier": "error",
    "no-multiple-empty-lines": [2, {"max": 2 }],
    "react/jsx-uses-vars": [2],
    "react/react-in-jsx-scope": "off",
    "react/prop-types": "off"
  },
  "plugins": [
    "prettier",
    "react"
  ],
  "settings": {
    "react": {
      "version": "detect" // React version. "detect" automatically picks the version you have installed.
    }
  }
}
like image 353
Serhii Zharkov Avatar asked Oct 22 '25 18:10

Serhii Zharkov


1 Answers

This might not work in your case -- I'm just running eslint without prettier -- but try this line instead:

"no-multiple-empty-lines": ["error", { "max": 2, "maxBOF": 0, "maxEOF": 0 }]

If you definitely want to run it through prettier with eslint though, it looks like that might not work at all. Not sure I'm reading this issue correctly, but it seems like that might not be configurable in prettier? If all you want is to change eslint's behavior though, I think the above line should work because I just had to use it in my own config.

like image 154
Erdős-Bacon Avatar answered Oct 24 '25 07:10

Erdős-Bacon