Skip to content

Commit

Permalink
[Docs] order: Add a quick note on how unbound imports and --fix
Browse files Browse the repository at this point in the history
Having unbound imports mixed among the bound ones causes unexpected and incorrect seeming results. I spent several hours trying to fix this problem only to find it was well known!
  • Loading branch information
mi-na-bot authored and ljharb committed Jan 2, 2023
1 parent 7a28ba2 commit f3e505b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
- [`no-unused-modules`]: add console message to help debug [#2866]
- [Refactor] `ExportMap`: make procedures static instead of monkeypatching exportmap ([#2982], thanks [@soryy708])
- [Refactor] `ExportMap`: separate ExportMap instance from its builder logic ([#2985], thanks [@soryy708])
- [Docs] `order`: Add a quick note on how unbound imports and --fix ([#2640], thanks [@minervabot])

## [2.29.1] - 2023-12-14

Expand Down Expand Up @@ -1130,6 +1131,7 @@ for info on changes for earlier releases.
[#2735]: https://github.com/import-js/eslint-plugin-import/pull/2735
[#2699]: https://github.com/import-js/eslint-plugin-import/pull/2699
[#2664]: https://github.com/import-js/eslint-plugin-import/pull/2664
[#2640]: https://github.com/import-js/eslint-plugin-import/pull/2640
[#2613]: https://github.com/import-js/eslint-plugin-import/pull/2613
[#2608]: https://github.com/import-js/eslint-plugin-import/pull/2608
[#2605]: https://github.com/import-js/eslint-plugin-import/pull/2605
Expand Down Expand Up @@ -1846,6 +1848,7 @@ for info on changes for earlier releases.
[@mgwalker]: https://github.com/mgwalker
[@mhmadhamster]: https://github.com/MhMadHamster
[@MikeyBeLike]: https://github.com/MikeyBeLike
[@minervabot]: https://github.com/minervabot
[@mpint]: https://github.com/mpint
[@mplewis]: https://github.com/mplewis
[@mrmckeb]: https://github.com/mrmckeb
Expand Down
19 changes: 19 additions & 0 deletions docs/rules/order.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@ import foo from './foo';
var path = require('path');
```

## Limitations of `--fix`

Unbound imports are assumed to have side effects, and will never be moved/reordered. This can cause other imports to get "stuck" around them, and the fix to fail.

```javascript
import b from 'b'
import 'format.css'; // This will prevent --fix from working.
import a from 'a'
```

As a workaround, move unbound imports to be entirely above or below bound ones.

```javascript
import 'format1.css'; // OK
import b from 'b'
import a from 'a'
import 'format2.css'; // OK
```

## Options

This rule supports the following options:
Expand Down

0 comments on commit f3e505b

Please sign in to comment.