fmtimports

command module
v0.0.0-...-213439d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

README

fmtimports

For K8s related projects, please use https://github.com/kubernetes/kubeadm/blob/main/kinder/hack/verify-imports-order.sh

Tool for formatting golang import lines

stdlib

imports outside of *.k8s.io

*.k8s.io (non local repository)

local repository (k8s.io/kubernetes/.*)

Install

go install github.com/xinydev/fmtimports@latest

Usage

fmtimports --help

usage: gofmt-import [flags] [path ...]
  -d    display diffs instead of rewriting files
  -ignore-file string
        files with this string in the file name will be ignored (default "zz_generated")
  -l    list files whose formatting differs from gofmt's
  -w    write result to (source) file instead of stdout

Example

./fmtimports testdata/1.input

Before:

package main

import (
	bootstraptokenv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/bootstraptoken/v1"
	"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
	"k8s.io/kubernetes/cmd/kubeadm/app/constants"

	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"

	fuzz "github.com/google/gofuzz"
	fuzz2 "github.com/google/gofuzz2"
	"os"
	"fmt"
)

After:

package main

import (
	"fmt"
	"os"

	fuzz "github.com/google/gofuzz"
	fuzz2 "github.com/google/gofuzz2"

	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"

	bootstraptokenv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/bootstraptoken/v1"
	"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
	"k8s.io/kubernetes/cmd/kubeadm/app/constants"
)

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL