Skip to content

Commit 3059c0f

Browse files
committed
first review
1 parent deb352c commit 3059c0f

File tree

5 files changed

+46
-35
lines changed

5 files changed

+46
-35
lines changed

.golangci.example.yml

+22-9
Original file line numberDiff line numberDiff line change
@@ -295,18 +295,31 @@ linters-settings:
295295
statements: -1
296296

297297
gci:
298-
# Checks that no inline Comments are present
299-
no-inlineComments: false
300-
# Checks that no prefix Comments(comment lines above an import) are present
301-
no-prefixComments: false
298+
# DEPRECATED: use `sections` and `prefix(github.com/org/project)` instead.
299+
local-prefixes: github.com/org/project
300+
301+
# Checks that no inline Comments are present.
302+
# Default: false
303+
no-inlineComments: true
304+
305+
# Checks that no prefix Comments(comment lines above an import) are present.
306+
# Default: false
307+
no-prefixComments: true
308+
302309
# Section configuration to compare against.
303-
# Run gci print -h for a detailed explanation
310+
# Section names are case-insensitive and may contain parameters in ().
311+
# Default: ["standard", "default"]
304312
sections:
305-
- Standard
306-
- Default
307-
# Separators that should be present between sections
313+
- standard # Captures all standard packages if they do not match another section.
314+
- default # Contains all imports that could not be matched to another section type.
315+
- comment(your text here) # Prints the specified indented comment.
316+
- newLine # Prints an empty line
317+
- prefix(github.com/org/project) # Groups all imports with the specified Prefix.
318+
319+
# Separators that should be present between sections.
320+
# Default: ["newLine"]
308321
sectionSeparators:
309-
- Newline
322+
- newLine
310323

311324
gocognit:
312325
# Minimal code complexity to report

.golangci.yml

-6
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ linters-settings:
1212
funlen:
1313
lines: 100
1414
statements: 50
15-
gci:
16-
sections:
17-
- Standard
18-
- Default
19-
- Prefix(github.com/golangci/golangci-lint)
2015
goconst:
2116
min-len: 2
2217
min-occurrences: 3
@@ -76,7 +71,6 @@ linters:
7671
- errcheck
7772
- exportloopref
7873
- funlen
79-
- gci
8074
- gochecknoinits
8175
- goconst
8276
- gocritic

pkg/config/linters_settings.go

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ package config
33
import "github.com/pkg/errors"
44

55
var defaultLintersSettings = LintersSettings{
6+
Gci: GciSettings{
7+
Sections: []string{"default", "standard"},
8+
SectionSeparator: []string{"newline"},
9+
},
610
Decorder: DecorderSettings{
711
DecOrder: []string{"type", "const", "var", "func"},
812
DisableDecNumCheck: true,
@@ -253,6 +257,7 @@ type FunlenSettings struct {
253257
}
254258

255259
type GciSettings struct {
260+
LocalPrefixes string `mapstructure:"local-prefixes"` // Deprecated
256261
NoInlineComments bool `mapstructure:"no-inlineComments"`
257262
NoPrefixComments bool `mapstructure:"no-prefixComments"`
258263
Sections []string `mapstructure:"sections"`

pkg/golinters/gci.go

+19-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package golinters
22

33
import (
4+
"fmt"
45
"strings"
56

67
gciAnalyzer "github.com/daixiang0/gci/pkg/analyzer"
@@ -13,23 +14,30 @@ import (
1314
const gciName = "gci"
1415

1516
func NewGci(settings *config.GciSettings) *goanalysis.Linter {
16-
analyzer := gciAnalyzer.Analyzer
17-
var cfg map[string]map[string]interface{}
17+
var linterCfg map[string]map[string]interface{}
18+
1819
if settings != nil {
19-
cfg = map[string]map[string]interface{}{
20-
analyzer.Name: {
21-
gciAnalyzer.NoInlineCommentsFlag: settings.NoInlineComments,
22-
gciAnalyzer.NoPrefixCommentsFlag: settings.NoPrefixComments,
23-
gciAnalyzer.SectionsFlag: strings.Join(settings.Sections, gciAnalyzer.SectionDelimiter),
24-
gciAnalyzer.SectionSeparatorsFlag: strings.Join(settings.SectionSeparator, gciAnalyzer.SectionDelimiter),
25-
},
20+
cfg := map[string]interface{}{
21+
gciAnalyzer.NoInlineCommentsFlag: settings.NoInlineComments,
22+
gciAnalyzer.NoPrefixCommentsFlag: settings.NoPrefixComments,
23+
gciAnalyzer.SectionsFlag: strings.Join(settings.Sections, gciAnalyzer.SectionDelimiter),
24+
gciAnalyzer.SectionSeparatorsFlag: strings.Join(settings.SectionSeparator, gciAnalyzer.SectionDelimiter),
25+
}
26+
27+
if settings.LocalPrefixes != "" {
28+
prefix := []string{"Standard", "Default", fmt.Sprintf("Prefix(%s)", settings.LocalPrefixes)}
29+
cfg[gciAnalyzer.SectionsFlag] = strings.Join(prefix, gciAnalyzer.SectionDelimiter)
30+
}
31+
32+
linterCfg = map[string]map[string]interface{}{
33+
gciAnalyzer.Analyzer.Name: cfg,
2634
}
2735
}
2836

2937
return goanalysis.NewLinter(
3038
gciName,
3139
"Gci controls golang package import order and makes it always deterministic.",
32-
[]*analysis.Analyzer{analyzer},
33-
cfg,
40+
[]*analysis.Analyzer{gciAnalyzer.Analyzer},
41+
linterCfg,
3442
).WithLoadMode(goanalysis.LoadModeSyntax)
3543
}

pkg/golinters/gofmt_common.go

-9
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,6 @@ func getErrorTextForLinter(lintCtx *linter.Context, linterName string) string {
225225
if lintCtx.Settings().Goimports.LocalPrefixes != "" {
226226
text += " with -local " + lintCtx.Settings().Goimports.LocalPrefixes
227227
}
228-
case gciName:
229-
optionsText := []string{}
230-
if lintCtx.Settings().Gci.NoInlineComments {
231-
optionsText = append(optionsText, "NoInlineComments")
232-
}
233-
if lintCtx.Settings().Gci.NoPrefixComments {
234-
optionsText = append(optionsText, "NoPrefixComments")
235-
}
236-
text = fmt.Sprintf("File does not conform to the import format configured for `Gci`(%s)", strings.Join(optionsText, ","))
237228
}
238229
return text
239230
}

0 commit comments

Comments
 (0)