Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Mrtenz opened this issue Sep 15, 2020 · 4 comments · Fixed by #1933
Closed

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

Mrtenz opened this issue Sep 15, 2020 · 4 comments · Fixed by #1933

Comments

@Mrtenz
Copy link

Mrtenz commented Sep 15, 2020

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?

@ljharb
Copy link
Member

ljharb commented Sep 27, 2020

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.

@Mrtenz
Copy link
Author

Mrtenz commented Sep 27, 2020

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!

@ljharb
Copy link
Member

ljharb commented Sep 27, 2020

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

@anikethsaha
Copy link
Contributor

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

ljharb pushed a commit to anikethsaha/eslint-plugin-import that referenced this issue May 14, 2021
reosarevok pushed a commit to reosarevok/eslint-plugin-import that referenced this issue Sep 14, 2023
ljharb pushed a commit to anikethsaha/eslint-plugin-import that referenced this issue Sep 14, 2023
Fixes import-js#1901. Fixes import-js#514.

Co-authored-by: Anix <anik220798@gmail.com>
Co-authored-by: reosarevok <reosarevok@metabrainz.org>
reosarevok pushed a commit to reosarevok/eslint-plugin-import that referenced this issue Sep 15, 2023
@ljharb ljharb closed this as completed in 8705121 Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants