Skip to content

Commit 3fcc398

Browse files
committed
Enforce consistent import ordering
Introduces lint rules to enforce all Go imports are consistently ordered: - Standard library - External packages - Internal packages
1 parent 07c5e03 commit 3fcc398

File tree

570 files changed

+1573
-1756
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

570 files changed

+1573
-1756
lines changed

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ linters:
22
disable-all: true
33
enable:
44
- nosprintfhostport
5+
- goimports
6+
- goimports-reviser
57
presets: []
68
fast: true
79
run:
810
timeout: 5m
11+
12+
linters-settings:
13+
goimports-reviser:
14+
local-prefixes: github.com/openshift/origin

cmd/openshift-tests/openshift-tests.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ import (
1010
"time"
1111

1212
"github.com/openshift/library-go/pkg/serviceability"
13+
"github.com/sirupsen/logrus"
14+
"github.com/spf13/cobra"
15+
"github.com/spf13/pflag"
16+
"k8s.io/cli-runtime/pkg/genericclioptions"
17+
utilflag "k8s.io/component-base/cli/flag"
18+
"k8s.io/component-base/logs"
19+
"k8s.io/kubectl/pkg/util/templates"
20+
1321
"github.com/openshift/origin/pkg/cmd"
1422
collectdiskcertificates "github.com/openshift/origin/pkg/cmd/openshift-tests/collect-disk-certificates"
1523
"github.com/openshift/origin/pkg/cmd/openshift-tests/dev"
@@ -28,13 +36,6 @@ import (
2836
versioncmd "github.com/openshift/origin/pkg/cmd/openshift-tests/version"
2937
testginkgo "github.com/openshift/origin/pkg/test/ginkgo"
3038
exutil "github.com/openshift/origin/test/extended/util"
31-
"github.com/sirupsen/logrus"
32-
"github.com/spf13/cobra"
33-
"github.com/spf13/pflag"
34-
"k8s.io/cli-runtime/pkg/genericclioptions"
35-
utilflag "k8s.io/component-base/cli/flag"
36-
"k8s.io/component-base/logs"
37-
"k8s.io/kubectl/pkg/util/templates"
3839
)
3940

4041
func main() {

cmd/update-tls-artifacts/update-tls-artifacts.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import (
55
"fmt"
66
"os"
77

8-
"github.com/openshift/origin/pkg/cmd/update-tls-artifacts/generate-owners"
9-
108
"github.com/openshift/library-go/pkg/serviceability"
11-
exutil "github.com/openshift/origin/test/extended/util"
12-
"github.com/spf13/pflag"
13-
149
"github.com/spf13/cobra"
10+
"github.com/spf13/pflag"
1511
"k8s.io/cli-runtime/pkg/genericclioptions"
1612
"k8s.io/kubectl/pkg/util/templates"
13+
14+
generate_owners "github.com/openshift/origin/pkg/cmd/update-tls-artifacts/generate-owners"
15+
exutil "github.com/openshift/origin/test/extended/util"
1716
)
1817

1918
func main() {

examples/examples_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ import (
66
"path/filepath"
77
"testing"
88

9-
app "k8s.io/api/apps/v1"
10-
corev1 "k8s.io/api/core/v1"
11-
"k8s.io/apimachinery/pkg/api/apitesting"
12-
"k8s.io/apimachinery/pkg/runtime"
13-
"k8s.io/apimachinery/pkg/util/yaml"
14-
"k8s.io/klog/v2"
15-
169
appsv1 "github.com/openshift/api/apps/v1"
1710
buildv1 "github.com/openshift/api/build/v1"
1811
imagev1 "github.com/openshift/api/image/v1"
1912
routev1 "github.com/openshift/api/route/v1"
2013
templatev1 "github.com/openshift/api/template/v1"
14+
app "k8s.io/api/apps/v1"
15+
corev1 "k8s.io/api/core/v1"
16+
"k8s.io/apimachinery/pkg/api/apitesting"
17+
"k8s.io/apimachinery/pkg/runtime"
18+
"k8s.io/apimachinery/pkg/util/yaml"
19+
klog "k8s.io/klog/v2"
2120
)
2221

2322
func walkJSONFiles(inDir string, fn func(name, path string, data []byte)) error {

hack/jsonformat/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ package main
22

33
import (
44
"encoding/json"
5+
"io/ioutil"
56
"log"
7+
"os"
68
)
79

8-
import "io/ioutil"
9-
import "os"
10-
1110
func main() {
1211
if len(os.Args) != 2 {
1312
log.Fatal("Usage: jsonformat.go <filename>")

hack/listtests/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ import (
55
"bytes"
66
"flag"
77
"fmt"
8+
"log"
89
"os"
910
"os/exec"
1011
"path/filepath"
1112
"regexp"
1213
"sort"
1314
"strings"
14-
15-
"log"
1615
)
1716

1817
var reLine = regexp.MustCompile("^\\s*(\\w+)\\s+(\\w+)\\s+(.+)$")

pkg/alerts/types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package alerts
22

33
import (
4-
"github.com/openshift/origin/pkg/monitor/monitorapi"
54
"github.com/prometheus/common/model"
5+
6+
"github.com/openshift/origin/pkg/monitor/monitorapi"
67
)
78

89
type MetricCondition struct {

pkg/certs/types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,31 @@ import (
88
)
99

1010
type ConfigMapRefByNamespaceName []certgraphapi.InClusterConfigMapLocation
11+
1112
type SecretRefByNamespaceName []certgraphapi.InClusterSecretLocation
13+
1214
type SecretInfoByNamespaceName map[certgraphapi.InClusterSecretLocation]certgraphapi.PKIRegistryCertKeyPairInfo
15+
1316
type ConfigMapInfoByNamespaceName map[certgraphapi.InClusterConfigMapLocation]certgraphapi.PKIRegistryCertificateAuthorityInfo
17+
1418
type OnDiskLocationByPath []certgraphapi.OnDiskLocation
19+
1520
type CertKeyPairInfoByOnDiskLocation map[certgraphapi.OnDiskLocation]certgraphapi.PKIRegistryCertKeyPairInfo
21+
1622
type CABundleInfoByOnDiskLocation map[certgraphapi.OnDiskLocation]certgraphapi.PKIRegistryCertificateAuthorityInfo
1723

1824
type CertKeyPairByLocation []certgraphapi.PKIRegistryCertKeyPair
25+
1926
type CertificateAuthorityBundleByLocation []certgraphapi.PKIRegistryCABundle
2027

2128
func (n SecretRefByNamespaceName) Len() int {
2229
return len(n)
2330
}
31+
2432
func (n SecretRefByNamespaceName) Swap(i, j int) {
2533
n[i], n[j] = n[j], n[i]
2634
}
35+
2736
func (n SecretRefByNamespaceName) Less(i, j int) bool {
2837
diff := strings.Compare(n[i].Namespace, n[j].Namespace)
2938
switch {
@@ -39,9 +48,11 @@ func (n SecretRefByNamespaceName) Less(i, j int) bool {
3948
func (n ConfigMapRefByNamespaceName) Len() int {
4049
return len(n)
4150
}
51+
4252
func (n ConfigMapRefByNamespaceName) Swap(i, j int) {
4353
n[i], n[j] = n[j], n[i]
4454
}
55+
4556
func (n ConfigMapRefByNamespaceName) Less(i, j int) bool {
4657
diff := strings.Compare(n[i].Namespace, n[j].Namespace)
4758
switch {
@@ -57,9 +68,11 @@ func (n ConfigMapRefByNamespaceName) Less(i, j int) bool {
5768
func (n OnDiskLocationByPath) Len() int {
5869
return len(n)
5970
}
71+
6072
func (n OnDiskLocationByPath) Swap(i, j int) {
6173
n[i], n[j] = n[j], n[i]
6274
}
75+
6376
func (n OnDiskLocationByPath) Less(i, j int) bool {
6477
return strings.Compare(n[i].Path, n[j].Path) < 0
6578
}
@@ -87,19 +100,23 @@ func BuildCABundlePath(curr certgraphapi.PKIRegistryCABundle) string {
87100
func (n CertKeyPairByLocation) Len() int {
88101
return len(n)
89102
}
103+
90104
func (n CertKeyPairByLocation) Swap(i, j int) {
91105
n[i], n[j] = n[j], n[i]
92106
}
107+
93108
func (n CertKeyPairByLocation) Less(i, j int) bool {
94109
return strings.Compare(BuildCertKeyPath(n[i]), BuildCertKeyPath(n[j])) < 0
95110
}
96111

97112
func (n CertificateAuthorityBundleByLocation) Len() int {
98113
return len(n)
99114
}
115+
100116
func (n CertificateAuthorityBundleByLocation) Swap(i, j int) {
101117
n[i], n[j] = n[j], n[i]
102118
}
119+
103120
func (n CertificateAuthorityBundleByLocation) Less(i, j int) bool {
104121
return strings.Compare(BuildCABundlePath(n[i]), BuildCABundlePath(n[j])) < 0
105122
}

pkg/clioptions/clusterdiscovery/cluster.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,18 @@ import (
99
"net/url"
1010
"strings"
1111

12-
"k8s.io/apimachinery/pkg/runtime/schema"
13-
12+
configv1 "github.com/openshift/api/config/v1"
13+
operatorv1 "github.com/openshift/api/operator/v1"
14+
configclient "github.com/openshift/client-go/config/clientset/versioned"
15+
operatorclient "github.com/openshift/client-go/operator/clientset/versioned"
1416
corev1 "k8s.io/api/core/v1"
1517
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18+
"k8s.io/apimachinery/pkg/runtime/schema"
1619
"k8s.io/apimachinery/pkg/util/sets"
1720
clientset "k8s.io/client-go/kubernetes"
1821
"k8s.io/client-go/rest"
1922
utilnet "k8s.io/utils/net"
2023

21-
configv1 "github.com/openshift/api/config/v1"
22-
operatorv1 "github.com/openshift/api/operator/v1"
23-
configclient "github.com/openshift/client-go/config/clientset/versioned"
24-
operatorclient "github.com/openshift/client-go/operator/clientset/versioned"
2524
"github.com/openshift/origin/test/extended/util/azure"
2625
)
2726

pkg/clioptions/clusterdiscovery/csi.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import (
66
"path/filepath"
77
"strings"
88

9-
"github.com/openshift/origin/test/extended/storage/csi"
109
"k8s.io/apimachinery/pkg/util/sets"
1110
"k8s.io/kubernetes/test/e2e/framework/testfiles"
1211
"k8s.io/kubernetes/test/e2e/storage/external"
1312
"sigs.k8s.io/yaml"
13+
14+
"github.com/openshift/origin/test/extended/storage/csi"
1415
)
1516

1617
const (

0 commit comments

Comments
 (0)