eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

[import/order] control over fix newlines

Open Klemensas opened this issue 3 years ago • 2 comments

With import/order, when using 'newlines-between': 'always-and-inside-groups' there seems to be no way to control how the fix happens.

Example problem:

import AddressTextField from './AddressTextField'
import CityField from './CityField'

import ContentLoader from 'components/ContentLoader/ContentLoader'
import SeparatedList from 'components/SeparatedList/SeparatedList'

Fix result:

import ContentLoader from 'components/ContentLoader/ContentLoader'

import SeparatedList from 'components/SeparatedList/SeparatedList'

import AddressTextField from './AddressTextField'
import CityField from './CityField'

Desired result:

import ContentLoader from 'components/ContentLoader/ContentLoader'
import SeparatedList from 'components/SeparatedList/SeparatedList'

import AddressTextField from './AddressTextField'
import CityField from './CityField'

Any chance to add support for some control over this?

Possible ways to control:

  • inference from the surrounding imports in the file, fallbacking to current behavior
  • additional property, accepting arbitrary grouping/spacing logic, likely related to https://github.com/import-js/eslint-plugin-import/issues/2292

Klemensas avatar Mar 01 '22 09:03 Klemensas

This just seems like a fix that can be made in the autofixer.

ljharb avatar Mar 01 '22 16:03 ljharb

Just reporting another example of undesired autofixer behavior: before and after. You can see it even adds some extra lines at the bottom which are removed on a subsequent autofixer run. Here's the desired result. It's slightly different because one more thing was imported from electron. teleterm is an internal package, though idk if it's recognized as such.

FWIW, once manually fixed the autofixer behaves correctly. It's just the initial run that's causing some problems.

ravicious avatar Jul 27 '22 14:07 ravicious