Skip to content

Commit 8fceb7f

Browse files
committed
Fix #209: support goimports.local-prefix option for goimports
1 parent 6aeecb7 commit 8fceb7f

Some content is hidden

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

49 files changed

+114
-51
lines changed

.golangci.example.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ linters-settings:
6868
gofmt:
6969
# simplify code: gofmt with `-s` option, true by default
7070
simplify: true
71+
goimports:
72+
# put imports beginning with prefix after 3rd-party packages;
73+
# it's a comma-separated list of prefixes
74+
local-prefixes: github.com/org/project
7175
gocyclo:
7276
# minimal code complexity to report, 30 by default (but we recommend 10-20)
7377
min-complexity: 10

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ linters-settings:
2222
locale: US
2323
lll:
2424
line-length: 140
25+
goimports:
26+
local-prefixes: github.com/golangci/golangci-lint
2527

2628
linters:
2729
enable-all: true

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,10 @@ linters-settings:
518518
gofmt:
519519
# simplify code: gofmt with `-s` option, true by default
520520
simplify: true
521+
goimports:
522+
# put imports beginning with prefix after 3rd-party packages;
523+
# it's a comma-separated list of prefixes
524+
local-prefixes: github.com/org/project
521525
gocyclo:
522526
# minimal code complexity to report, 30 by default (but we recommend 10-20)
523527
min-complexity: 10
@@ -655,6 +659,8 @@ linters-settings:
655659
locale: US
656660
lll:
657661
line-length: 140
662+
goimports:
663+
local-prefixes: github.com/golangci/golangci-lint
658664

659665
linters:
660666
enable-all: true

pkg/commands/executor.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package commands
22

33
import (
4+
"github.com/spf13/cobra"
5+
"github.com/spf13/pflag"
6+
47
"github.com/golangci/golangci-lint/pkg/config"
58
"github.com/golangci/golangci-lint/pkg/goutil"
69
"github.com/golangci/golangci-lint/pkg/lint"
710
"github.com/golangci/golangci-lint/pkg/lint/lintersdb"
811
"github.com/golangci/golangci-lint/pkg/logutils"
912
"github.com/golangci/golangci-lint/pkg/report"
10-
"github.com/spf13/cobra"
11-
"github.com/spf13/pflag"
1213
)
1314

1415
type Executor struct {

pkg/commands/help.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66
"strings"
77

88
"github.com/fatih/color"
9+
"github.com/spf13/cobra"
10+
911
"github.com/golangci/golangci-lint/pkg/lint/linter"
1012
"github.com/golangci/golangci-lint/pkg/logutils"
11-
"github.com/spf13/cobra"
1213
)
1314

1415
func (e *Executor) initHelp() {

pkg/commands/linters.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import (
55
"os"
66

77
"github.com/fatih/color"
8-
"github.com/golangci/golangci-lint/pkg/lint/linter"
98
"github.com/spf13/cobra"
9+
10+
"github.com/golangci/golangci-lint/pkg/lint/linter"
1011
)
1112

1213
func (e *Executor) initLinters() {

pkg/commands/root.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import (
66
"runtime"
77
"runtime/pprof"
88

9-
"github.com/golangci/golangci-lint/pkg/config"
10-
"github.com/golangci/golangci-lint/pkg/logutils"
119
"github.com/spf13/cobra"
1210
"github.com/spf13/pflag"
11+
12+
"github.com/golangci/golangci-lint/pkg/config"
13+
"github.com/golangci/golangci-lint/pkg/logutils"
1314
)
1415

1516
func (e *Executor) persistentPreRun(cmd *cobra.Command, args []string) {

pkg/commands/run.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ import (
1111
"time"
1212

1313
"github.com/fatih/color"
14+
"github.com/pkg/errors"
15+
"github.com/spf13/cobra"
16+
"github.com/spf13/pflag"
17+
1418
"github.com/golangci/golangci-lint/pkg/config"
1519
"github.com/golangci/golangci-lint/pkg/exitcodes"
1620
"github.com/golangci/golangci-lint/pkg/lint"
1721
"github.com/golangci/golangci-lint/pkg/lint/lintersdb"
1822
"github.com/golangci/golangci-lint/pkg/logutils"
1923
"github.com/golangci/golangci-lint/pkg/printers"
2024
"github.com/golangci/golangci-lint/pkg/result"
21-
"github.com/pkg/errors"
22-
"github.com/spf13/cobra"
23-
"github.com/spf13/pflag"
2425
)
2526

2627
func getDefaultExcludeHelp() string {

pkg/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ type LintersSettings struct {
127127
Gofmt struct {
128128
Simplify bool
129129
}
130+
Goimports struct {
131+
LocalPrefixes string `mapstructure:"local-prefixes"`
132+
}
130133
Gocyclo struct {
131134
MinComplexity int `mapstructure:"min-complexity"`
132135
}

pkg/config/reader.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
"path/filepath"
88
"strings"
99

10+
"github.com/spf13/viper"
11+
1012
"github.com/golangci/golangci-lint/pkg/fsutils"
1113
"github.com/golangci/golangci-lint/pkg/logutils"
12-
"github.com/spf13/viper"
1314
)
1415

1516
type FileReader struct {

0 commit comments

Comments
 (0)