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?
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.
Most helpful comment
I will try to implement the option and update the docs soon.