Skip to content

Choose an import ordering convention and write a tool to format imports that way #1082

@grantr

Description

@grantr

From #1078. There are a few different ideas of how to order imports and where the line breaks should be. Let's decide which style makes sense to the most people, then implement a formatter in sockpuppet that can reformat imports automatically.

Examples of conventions that have been proposed:

import (
  // standard lib, enforced by gofmt
  "log"

  // vendored code. These packages cannot be changed by the developer.
  corev1 "k8s.io/api/core/v1"

  // in-repo code. These packages can be changed by the developer.
  "github.com/knative/eventing/pkg/broker"

  // dot imports. These are separate because the developer must recognize them in advance
  // to understand the code.
  . "github.com/knative/pkg/controller/testing"
)
import (
  // standard lib, enforced by gofmt
  "log"

  // vendored code. These packages cannot be changed by the developer.
  corev1 "k8s.io/api/core/v1"

  // vendored code. These packages cannot be changed by the developer.
  cloudevents "github.com/cloudevents/sdk-go"

  // in-repo code. These packages can be changed by the developer.
  "github.com/knative/eventing/pkg/broker"

  // dot imports. These are separate because the developer must recognize them in advance
  // to understand the code.
  . "github.com/knative/pkg/controller/testing"
)
import (
  // standard lib, enforced by gofmt
  "log"

  // dot imports. These are separate because the developer must recognize them in advance
  // to understand the code. These are also quite rare.
  . "github.com/knative/pkg/controller/testing"

  // All 'normal' imports that aren't part of the standard lib, regardless of whether they are in repo or vendored.
  corev1 "k8s.io/api/core/v1"
  "github.com/knative/eventing/pkg/broker"
)

/good-first-issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.kind/cleanupCategorizes issue or PR as related to cleaning up code, process, or technical debt.kind/good-first-issueDenotes an issue ready for a new contributor.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions