import-js / eslint-plugin-import

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

Import order autofix should move above comments with the import too (e.g. @ts-ignore etc) #1450

Open stefanicai opened 5 years ago

stefanicai commented 5 years ago

Currently reordering leaves the comments behind. Thus something like:

import { connect } from 'formik'
import { useReferenceData } from '../../reference'

// @ts-ignore
import { FormikRadioGroup } from '@external/radio-group'

Becomes:

import { connect } from 'formik'
import { FormikRadioGroup } from '@external/radio-group'
import { useReferenceData } from '../../reference'

// @ts-ignore

That's incorrect. The autofix should move the above comment as well.

ljharb commented 5 years ago

Comment attachment is difficult; I believe eslint doesn't actually attach comments to nodes. For you (and for ts-ignore comments, specifically), they go above, but some people put comments on the same line, and some below.

I'm not sure how to address this reliably except perhaps to bail on moving any line that has a comment adjacent in any direction.

belgattitude commented 1 year ago

This is a very annoying bug indeed. Has anyone found a workaround ?