Skip to content

Commit e329fa3

Browse files
authored
chore: Enable go fmt as a lint check for Go code (kubeflow#11830)
Signed-off-by: Caroline DeVoto <[email protected]> Co-authored-by: Caroline DeVoto <[email protected]>
1 parent dc841dd commit e329fa3

Some content is hidden

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

59 files changed

+185
-92
lines changed

.github/workflows/pre-commit.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: pre-commit
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
pre-commit:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: actions/setup-python@v3
17+
- uses: pre-commit/[email protected]
18+
# This is set to only run the golangci-lint pre-commit hooks
19+
# Remove in a later PR to run all hooks
20+
with:
21+
extra_args: golangci-lint --all-files

.golangci.yaml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
version: "2"
2+
13
run:
24
timeout: 30m
35
skip-files:
@@ -11,17 +13,20 @@ linters:
1113
disable-all: true
1214
enable: # please keep this alphabetized
1315
- gocritic
14-
- gosimple
1516
- govet
1617
- ineffassign
1718
- misspell
1819
- staticcheck
19-
- stylecheck
2020
- unused
21+
settings:
22+
misspell:
23+
locale: US
24+
staticcheck:
25+
checks:
26+
- "all"
2127

22-
linters-settings: # please keep this alphabetized
23-
misspell:
24-
locale: US
25-
staticcheck:
26-
checks:
27-
- "all"
28+
formatters:
29+
disable-all: true
30+
enable:
31+
- gofmt
32+
- goimports

.pre-commit-config.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ repos:
2626
# add comment "noqa" to ignore an import that should not be removed
2727
# (e.g., for an import with desired side-effects)
2828
- repo: https://github.com/hadialqattan/pycln
29-
rev: v2.1.1
29+
rev: v2.5.0
3030
hooks:
3131
- id: pycln
3232
name: pycln
@@ -43,7 +43,7 @@ repos:
4343
hooks:
4444
- id: yapf
4545
- repo: https://github.com/pycqa/docformatter
46-
rev: v1.4
46+
rev: v1.7.7
4747
hooks:
4848
- id: docformatter
4949
name: docformatter
@@ -55,7 +55,7 @@ repos:
5555

5656
# Golang pre-submit hooks
5757
- repo: https://github.com/golangci/golangci-lint
58-
rev: v1.64.8
58+
rev: v2.1.2
5959
hooks:
6060
- id: golangci-lint
6161
name: golangci-lint
@@ -65,3 +65,11 @@ repos:
6565
language: golang
6666
require_serial: true
6767
pass_filenames: false
68+
- id: golangci-lint
69+
name: golangci-lint fmt
70+
description: Formatter for Go.
71+
entry: golangci-lint fmt
72+
types: [go]
73+
language: golang
74+
require_serial: true
75+
pass_filenames: false

backend/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,14 @@ kind-load-driver-debug:
108108

109109
.PHONY: kind-build-and-load-driver-debug
110110
kind-build-and-load-driver-debug: image_driver_debug kind-load-driver-debug
111+
112+
.PHONY: lint-and-format
113+
lint-and-format: lint format
114+
115+
.PHONY: lint
116+
lint:
117+
golangci-lint run --new-from-rev HEAD --fix
118+
119+
.PHONY: format
120+
format:
121+
golangci-lint fmt

backend/src/agent/persistence/client/token_refresher.go

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

33
import (
4-
log "github.com/sirupsen/logrus"
54
"os"
65
"sync"
76
"time"
7+
8+
log "github.com/sirupsen/logrus"
89
)
910

1011
type TokenRefresherInterface interface {

backend/src/agent/persistence/worker/metrics_reporter_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestReportMetrics_NoCompletedNode_NoOP(t *testing.T) {
4646
},
4747
Status: workflowapi.WorkflowStatus{
4848
Nodes: map[string]workflowapi.NodeStatus{
49-
"node-1": workflowapi.NodeStatus{
49+
"node-1": {
5050
ID: "node-1",
5151
TemplateName: "template-1",
5252
Phase: workflowapi.NodeRunning,
@@ -72,7 +72,7 @@ func TestReportMetrics_NoRunID_NoOP(t *testing.T) {
7272
},
7373
Status: workflowapi.WorkflowStatus{
7474
Nodes: map[string]workflowapi.NodeStatus{
75-
"node-1": workflowapi.NodeStatus{
75+
"node-1": {
7676
ID: "node-1",
7777
Phase: workflowapi.NodeSucceeded,
7878
},
@@ -99,7 +99,7 @@ func TestReportMetrics_NoArtifact_NoOP(t *testing.T) {
9999
},
100100
Status: workflowapi.WorkflowStatus{
101101
Nodes: map[string]workflowapi.NodeStatus{
102-
"node-1": workflowapi.NodeStatus{
102+
"node-1": {
103103
ID: "node-1",
104104
TemplateName: "template-1",
105105
Phase: workflowapi.NodeSucceeded,
@@ -127,7 +127,7 @@ func TestReportMetrics_NoMetricsArtifact_NoOP(t *testing.T) {
127127
},
128128
Status: workflowapi.WorkflowStatus{
129129
Nodes: map[string]workflowapi.NodeStatus{
130-
"node-1": workflowapi.NodeStatus{
130+
"node-1": {
131131
ID: "node-1",
132132
TemplateName: "template-1",
133133
Phase: workflowapi.NodeSucceeded,
@@ -156,7 +156,7 @@ func TestReportMetrics_Succeed(t *testing.T) {
156156
},
157157
Status: workflowapi.WorkflowStatus{
158158
Nodes: map[string]workflowapi.NodeStatus{
159-
"node-1": workflowapi.NodeStatus{
159+
"node-1": {
160160
ID: "node-1",
161161
TemplateName: "template-1",
162162
Phase: workflowapi.NodeSucceeded,
@@ -220,7 +220,7 @@ func TestReportMetrics_EmptyArchive_Fail(t *testing.T) {
220220
},
221221
Status: workflowapi.WorkflowStatus{
222222
Nodes: map[string]workflowapi.NodeStatus{
223-
"node-1": workflowapi.NodeStatus{
223+
"node-1": {
224224
ID: "node-1",
225225
TemplateName: "template-1",
226226
Phase: workflowapi.NodeSucceeded,
@@ -262,7 +262,7 @@ func TestReportMetrics_MultipleFilesInArchive_Fail(t *testing.T) {
262262
},
263263
Status: workflowapi.WorkflowStatus{
264264
Nodes: map[string]workflowapi.NodeStatus{
265-
"node-1": workflowapi.NodeStatus{
265+
"node-1": {
266266
ID: "MY_NAME-template-1-1",
267267
TemplateName: "template-1",
268268
Phase: workflowapi.NodeSucceeded,
@@ -306,7 +306,7 @@ func TestReportMetrics_InvalidMetricsJSON_Fail(t *testing.T) {
306306
},
307307
Status: workflowapi.WorkflowStatus{
308308
Nodes: map[string]workflowapi.NodeStatus{
309-
"node-1": workflowapi.NodeStatus{
309+
"node-1": {
310310
ID: "node-1",
311311
TemplateName: "template-1",
312312
Phase: workflowapi.NodeSucceeded,
@@ -349,15 +349,15 @@ func TestReportMetrics_InvalidMetricsJSON_PartialFail(t *testing.T) {
349349
},
350350
Status: workflowapi.WorkflowStatus{
351351
Nodes: map[string]workflowapi.NodeStatus{
352-
"node-1": workflowapi.NodeStatus{
352+
"node-1": {
353353
ID: "node-1",
354354
TemplateName: "template-1",
355355
Phase: workflowapi.NodeSucceeded,
356356
Outputs: &workflowapi.Outputs{
357357
Artifacts: []workflowapi.Artifact{{Name: "mlpipeline-metrics"}},
358358
},
359359
},
360-
"node-2": workflowapi.NodeStatus{
360+
"node-2": {
361361
ID: "node-2",
362362
TemplateName: "template-2",
363363
Phase: workflowapi.NodeSucceeded,
@@ -400,12 +400,12 @@ func TestReportMetrics_InvalidMetricsJSON_PartialFail(t *testing.T) {
400400
expectedMetricsRequest := &api.ReportRunMetricsRequest{
401401
RunId: "run-1",
402402
Metrics: []*api.RunMetric{
403-
&api.RunMetric{
403+
{
404404
Name: "accuracy",
405405
NodeId: "MY_NAME-template-2-2",
406406
Value: &api.RunMetric_NumberValue{NumberValue: 0.77},
407407
},
408-
&api.RunMetric{
408+
{
409409
Name: "logloss",
410410
NodeId: "MY_NAME-template-2-2",
411411
Value: &api.RunMetric_NumberValue{NumberValue: 1.2},
@@ -432,7 +432,7 @@ func TestReportMetrics_CorruptedArchiveFile_Fail(t *testing.T) {
432432
},
433433
Status: workflowapi.WorkflowStatus{
434434
Nodes: map[string]workflowapi.NodeStatus{
435-
"node-1": workflowapi.NodeStatus{
435+
"node-1": {
436436
ID: "node-1",
437437
TemplateName: "template-1",
438438
Phase: workflowapi.NodeSucceeded,
@@ -473,7 +473,7 @@ func TestReportMetrics_MultiplMetricErrors_TransientErrowWin(t *testing.T) {
473473
},
474474
Status: workflowapi.WorkflowStatus{
475475
Nodes: map[string]workflowapi.NodeStatus{
476-
"node-1": workflowapi.NodeStatus{
476+
"node-1": {
477477
ID: "node-1",
478478
TemplateName: "template-1",
479479
Phase: workflowapi.NodeSucceeded,
@@ -498,19 +498,19 @@ func TestReportMetrics_MultiplMetricErrors_TransientErrowWin(t *testing.T) {
498498
})
499499
pipelineFake.StubReportRunMetrics(&api.ReportRunMetricsResponse{
500500
Results: []*api.ReportRunMetricsResponse_ReportRunMetricResult{
501-
&api.ReportRunMetricsResponse_ReportRunMetricResult{
501+
{
502502
MetricNodeId: "node-1",
503503
MetricName: "accuracy",
504504
Status: api.ReportRunMetricsResponse_ReportRunMetricResult_OK,
505505
},
506506
// Invalid argument error triggers permanent error
507-
&api.ReportRunMetricsResponse_ReportRunMetricResult{
507+
{
508508
MetricNodeId: "node-1",
509509
MetricName: "log loss",
510510
Status: api.ReportRunMetricsResponse_ReportRunMetricResult_INVALID_ARGUMENT,
511511
},
512512
// Internal error triggers transient error
513-
&api.ReportRunMetricsResponse_ReportRunMetricResult{
513+
{
514514
MetricNodeId: "node-1",
515515
MetricName: "accuracy",
516516
Status: api.ReportRunMetricsResponse_ReportRunMetricResult_INTERNAL_ERROR,
@@ -537,7 +537,7 @@ func TestReportMetrics_Unauthorized(t *testing.T) {
537537
},
538538
Status: workflowapi.WorkflowStatus{
539539
Nodes: map[string]workflowapi.NodeStatus{
540-
"node-1": workflowapi.NodeStatus{
540+
"node-1": {
541541
ID: "node-1",
542542
TemplateName: "template-1",
543543
Phase: workflowapi.NodeSucceeded,

backend/src/apiserver/config/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ package config
1717
import (
1818
"encoding/json"
1919
"fmt"
20+
"os"
21+
"time"
22+
2023
"github.com/golang/glog"
2124
"github.com/kubeflow/pipelines/backend/src/apiserver/client"
2225
"github.com/kubeflow/pipelines/backend/src/apiserver/common"
@@ -25,8 +28,6 @@ import (
2528
"github.com/kubeflow/pipelines/backend/src/apiserver/server"
2629
"github.com/kubeflow/pipelines/backend/src/common/util"
2730
"google.golang.org/grpc/codes"
28-
"os"
29-
"time"
3031
)
3132

3233
// deprecated

backend/src/apiserver/config/config_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ package config
1616

1717
import (
1818
"encoding/json"
19+
"os"
20+
"path/filepath"
21+
"testing"
22+
1923
"github.com/kubeflow/pipelines/backend/src/apiserver/list"
2024
"github.com/kubeflow/pipelines/backend/src/apiserver/model"
2125
"github.com/kubeflow/pipelines/backend/src/apiserver/resource"
@@ -24,9 +28,6 @@ import (
2428
"github.com/stretchr/testify/assert"
2529
"github.com/stretchr/testify/require"
2630
"google.golang.org/grpc/codes"
27-
"os"
28-
"path/filepath"
29-
"testing"
3031
)
3132

3233
func fakeResourceManager() *resource.ResourceManager {

backend/src/apiserver/config/proxy/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
package proxy
1515

1616
import (
17-
k8score "k8s.io/api/core/v1"
1817
"os"
18+
19+
k8score "k8s.io/api/core/v1"
1920
)
2021

2122
const (

backend/src/apiserver/config/proxy/config_test.go

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

1616
import (
1717
"fmt"
18+
"os"
19+
"testing"
20+
1821
"github.com/stretchr/testify/assert"
1922
"github.com/stretchr/testify/require"
2023
k8score "k8s.io/api/core/v1"
21-
"os"
22-
"testing"
2324
)
2425

2526
func TestNewConfigFromEnvVars(t *testing.T) {

0 commit comments

Comments
 (0)