import-js / eslint-plugin-import

ESLint plugin with rules that help validate proper imports.
MIT License
5.4k stars 1.54k forks source link

🐞: [import/newline-after-import] False positively reports wrong empty line numbers between imports with comments #2913

Open xsjcTony opened 8 months ago

xsjcTony commented 8 months ago

Something like that:

import './index.scss';

// other imports
import { ErrorBoundary } from 'react-error-boundary';

And my setting is

'import/newline-after-import': [
  'error',
  {
    count: 2,
    exactCount: true,
    considerComments: true
  }
]

It reports like this: image

But this is not the correct behavior, as in the documentation it clearly says:

Enforces having one or more empty lines after the last top-level import statement or require call.

after the last top-level import statement

Note: the exactCount doesn't matter, as I've tried to remove it but it's still causing issue.

Package version: ALL LATEST

dzek69 commented 1 month ago

To bump up priority (hopefully) I want to add some more details.

This bug is very much visible if you use TypeScript and you need to // ts-ignore some import (because of missing types for example):

import typescript from "@typescript-eslint/eslint-plugin";
import parserTs from "@typescript-eslint/parser"; // <--- error reported here
// @ts-ignore
import react from "eslint-plugin-react"; // <--- error reported here
// @ts-ignore
import importPlugin from "eslint-plugin-import";

OP example is "just a comment", that can be omitted (not ideal, but possible), with TS you may be forced to have this comment between imports.

This bug exists for 4 years at least (I think it was there since I started using this plugin) and its autofix can trigger import/order rule errors (if you prohibit new lines between imports).