Skip to content

Arrange imports while auto-importing and formatting #1989

@jerome-laforge

Description

@jerome-laforge

Hello all,
First of all, thx for this awesome plugin.
I configure the plugin filewatcher to goimported on each save my go giles.
Is it possible to add the possibility to add new import at the beginning of the import block instead of at its end.
Because that's cause some trouble with goimports that sort the import block.

I try to describle the pb with this example:

initial:

import (
    "fmt"
    "sync"
)

if add github.com/inconshreveable/log15 via auto import of the idea plugin, I have this :

import (
    "fmt"
    "sync"
    "github.com/inconshreveable/log15"
)

When I save (filewatcher executes goimport on it), I have this:

import (
    "fmt"
    "sync"

    "github.com/inconshreveable/log15"
)

If I add another package from stdlib (for example strconv) with auto import (as it appends the new import at the end of the block), I have this:

import (
    "fmt"
    "sync"

    "github.com/inconshreveable/log15"
    "strconv"
)

If I save it (and goimported), I have this:

import (
    "fmt"
    "sync"

    "strconv"

    "github.com/inconshreveable/log15"
)

So if autoimport add the new package à the beginning the import block like this

import (
    "strconv"
    "fmt"
    "sync"

    "github.com/inconshreveable/log15"
)

When I save/goimport the file, I have expected result like this:

import (
    "fmt"
    "strconv"
    "sync"

    "github.com/inconshreveable/log15"
)

Regard
Jérôme

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions