Eslint-plugin-import: [order/newline-after-import]: More new lines allowed than specified in config

Created on 15 Sep 2020  路  4Comments  路  Source: benmosher/eslint-plugin-import

I'm running into an issue with import/order and import/newline-after-import, where more newlines are allowed than specified in the configuration. My (minimal) ESLint config looks like this:

{
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint", "eslint-plugin-import"],
  "extends": ["plugin:eslint-plugin-import/typescript"],
  "rules": {
    "import/newline-after-import": ["error", {
      "count": 1
    }],
    "import/order": ["error", {
        "newlines-between": "always"
    }]
  }
}

I would expect this to ensure that there is always exactly one newline between import groups, and after all imports, e.g.:

import path from 'path';

import { bar } from "./bar";
import { baz } from "./baz";

console.log(path, bar, baz);

It works when there are less newlines than required, the following would result in an error for example:

import path from 'path';
import { bar } from "./bar";
import { baz } from "./baz";
console.log(path, bar, baz);

It does not seem to work when there are more newlines than the specified count however. I would expect the following to result in errors, but it works fine:

import path from 'path';



import { bar } from "./bar";
import { baz } from "./baz";



console.log(path, bar, baz);

Am I misunderstanding newline-after-import's count option, or is this a bug?

enhancement help wanted

Most helpful comment

I will try to implement the option and update the docs soon.

All 4 comments

It's a bit vague in the docs, but it's only enforcing a minimum. It seems reasonable to add an option that would enforce count precisely, though.

From reading the docs I would expect it to enforce an _exact_ number of new lines. It would definitely be nice to have an option for this!

PRs both to make the docs more clear, and to add such an option, would be welcome.

I will try to implement the option and update the docs soon.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

steve-taylor picture steve-taylor  路  24Comments

johanneswilm picture johanneswilm  路  21Comments

ljharb picture ljharb  路  29Comments

nevir picture nevir  路  40Comments

JustFly1984 picture JustFly1984  路  41Comments