import-js / import-js/eslint-plugin-import

`import/order` fixer breaks Svelte script imports

Open
#2,407 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted
Dominant language
JavaScript
Stars
5.9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

This source:

<script lang="typescript">
    import { AlertTypes, icons } from "./alert-types";
    import Icon from "ui/library/components/icon/icon.svelte";

    export let type = AlertTypes.Info;
</script>

produces one warning on each of the import lines. The first line produces "There should be at least one empty line between import groups - eslint (import/order)" and the second line produces "ui/library/components/icon/icon.svelte import should occur before import of ./alert-types - eslint (import/order)".

Fixing the first warning works just fine. A newline is inserted between the imports:

<script lang="typescript">
    import { AlertTypes, icons } from "./alert-types";

    import Icon from "ui/library/components/icon/icon.svelte";

    export let type = AlertTypes.Info;
</script>

Unfortunately, fixing the remaining warning with ESLint results in this broken output:

<script lang="typescript">
    import { AlIcon from "ui/library/components/icon/icon.svelte";
import { AlertTypes, icons } from "./alert-types";


    export let type = AlertTypes.Info;
</script>

Note the double whitespace below the two imports.

Any idea what's going on? My goal is to get the autofix to correctly swap those two import lines and not break the source code.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the import/order fixer and reproduce the issue using the Svelte source example in the report. Trace the fix that reorders the two imports, then verify the output preserves both complete import statements, indentation, and spacing without corrupting the script.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript, typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.