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.

Prettier-eslint removes empty line between imports incorrectly

See original GitHub issue

Versions:

  • prettier-eslint version: 8.8.2
  • node version: 8.11.1
  • yarn version: 1.5.1

Have you followed the debugging tips?

Yes

Relevant code or config

.eslintrc.js

const path = require("path");

const config = {
  parser: "babel-eslint",
  env: {
    node: true
  },
  plugins: ["import"],
  rules: {
    "import/order": [
      "error",
      {
        groups: [
          ["builtin", "external"],
          "internal",
          "parent",
          ["sibling", "index"]
        ],
        "newlines-between": "always"
      }
    ]
  },
  settings: {
    "import/resolver": {
      node: {
        root: __dirname
      },
      alias: [["appalias", path.resolve(__dirname, "src/app")]]
    }
  }
};

module.exports = config;

src/example.js (file being formatted)

const fs = require("fs");
const main = require("src/main");

const app = require("appalias");

const packageJson = require("../package.json");

const mainSibling = require("./main");

What I did:

Run yarn prettier-eslint --list-different --write src/example.js.

What happened:

It removes the empty line between const main = require("src/main"); and const app = require("appalias");. This causes an eslint error.

Reproduction repository:

https://github.com/amosyuen/prettier-eslint-import-empty-line-removal

Problem description:

Seems that the eslint --fix run by prettier-eslint doesn’t handle the import/order rule correctly. When running with trace logging it looks like import/order rule is correctly set in the inferred options and that prettier doesn’t change the empty lines between import statements. However, for some reason the output after eslint --fix will remove the empty line, causing an eslint error.

Running yarn eslint --fix src/example.js will correctly add back the empty line. So there seems to be something wrong with how prettier-eslint is running eslint. I also made sure I used the same version of eslint.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
baldurhcommented, Jul 4, 2019

We’re having problems with this as well in our team.

1reaction
Maruzcommented, Mar 14, 2019

This is an old task, but we are experiencing this with our setup now which is very similar to the config in the initial bug report. ESlint expects the space that Prettier removes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rationale - Prettier
Prettier collapses multiple blank lines into a single blank line. Empty lines at the start and end of blocks (and whole files) are...
Read more >
no-multiple-empty-lines - ESLint - Pluggable JavaScript Linter
This rule aims to reduce the scrolling required when reading through your code. It will warn when the maximum amount of empty lines...
Read more >
Prettier removes 2 empty lines - visual studio code
and this code gets reformatted by prettier and the 2 empty lines are completely removed (it's a TypeScript file): import { Component }...
Read more >
lines-between-class-members | typescript-eslint
This rule improves readability by enforcing lines between class members. It will not check empty lines before the first member and after the...
Read more >
ESLint | WebStorm Documentation - JetBrains
Configure ESLint automatically. With automatic configuration, WebStorm uses the ESLint package from the project node_modules folder and the ...
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