question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

organizeImports should use newlines between groups

See original GitHub issue

Description

I had a look through https://github.com/sveltejs/language-tools/issues/83 and I think this has not been mentioned yet.

Currently when I save a file eslint and the svelte plugin are fighting each other. My non-svelte files are using this plugin to sort imports: https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md

These are the rules I have:

"import/newline-after-import": ["error", { count: 1 }],
"import/order": [
  "warn",
  {
    "newlines-between": "always",
    alphabetize: {
      order: "asc",
      caseInsensitive: true,
    },
  },
],
Expected Actual
<script lang="ts">
  import { onMount } from "svelte";
  import { writable } from "svelte/store";

  import ALib from "$lib/ALib.svelte";
  import BLib from "$lib/BLib.svelte";

  import ARelative from "./ARelative.svelte";
  import BRelative from "./BRelative.svelte";
</script>
<script lang="ts">
  import ALib from "$lib/ALib.svelte";
  import BLib from "$lib/BLib.svelte";
  import { onMount } from "svelte";
  import { writable } from "svelte/store";
  import ARelative from "./ARelative.svelte";
  import BRelative from "./BRelative.svelte";
</script>

Proposed solution

Allow a way to configure this or use the eslint rules

Alternatives

live with the Svelte files being formatted differently.

Additional Information, eg. Screenshots

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jasonlyu123commented, May 20, 2022

Maybe you already set the config in your user settings. So you would have to override it again?

About the “fighting”. this is what I meant by “flash of changes”. Because of that, the group-aware organise import would still help. At least this problem won’t be too obvious.

0reactions
seanlailcommented, May 19, 2022

@jasonlyu123 Thanks for the response. I really appreciate it.

I added your suggestions in this commit https://github.com/seanlail/lint-format-issue/commit/792812aa4590bdca0febdfc324b1d44c1f0d25c6 and you’ll see when I saved the /src/routes/index.svelte file that the formatting removed the groups.

However, I found that adding the same "editor.codeActionsOnSave": ["source.organizeImports", "source.fixAll.eslint"], in the [svelte] setting fixes this and the formatting is correct. (see https://github.com/seanlail/lint-format-issue/commit/b154299473c5b2cb52306bbb8df4d4e11fb5b747)

I’m not sure if this is a bug or something that perhaps should be documented?

I can also see that it’s fighting something else and “jumping around”. Hope that makes sense, video below if not.

https://user-images.githubusercontent.com/142589/169288711-800a1345-c2bd-4238-befd-3ce7f91aa42d.mov

Read more comments on GitHub >

github_iconTop Results From Across the Web

disable organize import on specific lines · Issue #41494 ...
I like using the auto organize imports on save feature ("editor. ... imports would be added in between the organize-imports-disable-above ...
Read more >
Ability to add a separator/newline in organize imports ...
Go to [Blank Lines] tab, and edit [Between Import Groups]. Set it to 1 if you want one space. enter image description here....
Read more >
Organizing Imports in React and React Native | by Manu Rana
1. Group by origin. We will group system libraries (like react), external libraries, and internal project imports separately. · 2. Sort within each...
Read more >
Sorting your imports correctly in React - DEV Community ‍ ‍
newlines -between separates each group with a new line in between. alphabetize sort the order in which group will be sorted. I choose...
Read more >
Rule: ordered-imports - Palantir Open Source
Import sources must be alphabetized within groups, i.e.: import * as foo ... You can use this rule to group imports however you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found