Skip to content
This repository has been archived by the owner on Apr 7, 2024. It is now read-only.

The improved goimports with the deterministic behaviour

Pre-release
Pre-release
Compare
Choose a tag to compare
@kamilsk kamilsk released this 07 Apr 20:32
· 2 commits to extended since this release
goimports

Motivation

As a Go developer, I actively use goimports as a code formatter, but it has
non-deterministic behavior that affects a final diff. For example, for the input

import (
	"context"
	"github.com/pkg/b"
	"github.com/pkg/a"

	"github.com/pkg/y"
	"github.com/pkg/x"
	"github.com/pkg/z"
)

the output will be

import (
	"context"

	"github.com/pkg/a"
	"github.com/pkg/b"

	"github.com/pkg/x"
	"github.com/pkg/y"
	"github.com/pkg/z"
)

The proper result for me is

import (
	"context"

	"github.com/pkg/a"
	"github.com/pkg/b"
	"github.com/pkg/x"
	"github.com/pkg/y"
	"github.com/pkg/z"
)

So, I need to patch its behaviour and make a result deterministic.

What's changed

  • The goimports has the deterministic behaviour.
  • The tool is available by brew install octolab/tap/goimports.
  • The installation is also possible by
    $ curl -sSfL https://install.octolab.org/goimports | sh -s -- -b /usr/local/bin

Related issues

made with ❤️ for everyone by OctoLab