import-js/eslint-plugin-import

`import/order` fixer breaks Svelte script imports

Open

#2,407 创建于 2022年3月21日

在 GitHub 查看
 (15 评论) (0 反应) (0 负责人)JavaScript (1,540 fork)batch import
bughelp wanted

仓库指标

Star
 (4,946 star)
PR 合并指标
 (平均合并 138天 22小时) (30 天内合并 3 个 PR)

描述

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.

贡献者指南