Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump github.com/daixiang0/gci from 0.2.9 to 0.3.0 #2532

Merged
merged 5 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions .golangci.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -295,18 +295,31 @@ linters-settings:
statements: -1

gci:
# Checks that no inline Comments are present
no-inlineComments: false
# Checks that no prefix Comments(comment lines above an import) are present
no-prefixComments: false
# DEPRECATED: use `sections` and `prefix(github.com/org/project)` instead.
local-prefixes: github.com/org/project

# Checks that no inline Comments are present.
# Default: false
no-inlineComments: true

# Checks that no prefix Comments(comment lines above an import) are present.
# Default: false
no-prefixComments: true

# Section configuration to compare against.
# Run gci print -h for a detailed explanation
# Section names are case-insensitive and may contain parameters in ().
# Default: ["standard", "default"]
sections:
- Standard
- Default
# Separators that should be present between sections
- standard # Captures all standard packages if they do not match another section.
- default # Contains all imports that could not be matched to another section type.
- comment(your text here) # Prints the specified indented comment.
- newLine # Prints an empty line
- prefix(github.com/org/project) # Groups all imports with the specified Prefix.
ldez marked this conversation as resolved.
Show resolved Hide resolved

# Separators that should be present between sections.
# Default: ["newLine"]
sectionSeparators:
- Newline
- newLine

gocognit:
# Minimal code complexity to report
Expand Down
6 changes: 0 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ linters-settings:
funlen:
lines: 100
statements: 50
gci:
sections:
- Standard
- Default
- Prefix(github.com/golangci/golangci-lint)
goconst:
min-len: 2
min-occurrences: 3
Expand Down Expand Up @@ -76,7 +71,6 @@ linters:
- errcheck
- exportloopref
- funlen
- gci
ldez marked this conversation as resolved.
Show resolved Hide resolved
- gochecknoinits
- goconst
- gocritic
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ var defaultLintersSettings = LintersSettings{
Forbidigo: ForbidigoSettings{
ExcludeGodocExamples: true,
},
Gci: GciSettings{
ldez marked this conversation as resolved.
Show resolved Hide resolved
Sections: []string{"default", "standard"},
SectionSeparator: []string{"newline"},
},
Gocognit: GocognitSettings{
MinComplexity: 30,
},
Expand Down Expand Up @@ -253,6 +257,7 @@ type FunlenSettings struct {
}

type GciSettings struct {
LocalPrefixes string `mapstructure:"local-prefixes"` // Deprecated
NoInlineComments bool `mapstructure:"no-inlineComments"`
NoPrefixComments bool `mapstructure:"no-prefixComments"`
Sections []string `mapstructure:"sections"`
Expand Down
30 changes: 19 additions & 11 deletions pkg/golinters/gci.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package golinters

import (
"fmt"
"strings"

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

func NewGci(settings *config.GciSettings) *goanalysis.Linter {
analyzer := gciAnalyzer.Analyzer
var cfg map[string]map[string]interface{}
var linterCfg map[string]map[string]interface{}

if settings != nil {
cfg = map[string]map[string]interface{}{
analyzer.Name: {
gciAnalyzer.NoInlineCommentsFlag: settings.NoInlineComments,
gciAnalyzer.NoPrefixCommentsFlag: settings.NoPrefixComments,
gciAnalyzer.SectionsFlag: strings.Join(settings.Sections, gciAnalyzer.SectionDelimiter),
gciAnalyzer.SectionSeparatorsFlag: strings.Join(settings.SectionSeparator, gciAnalyzer.SectionDelimiter),
},
cfg := map[string]interface{}{
gciAnalyzer.NoInlineCommentsFlag: settings.NoInlineComments,
gciAnalyzer.NoPrefixCommentsFlag: settings.NoPrefixComments,
gciAnalyzer.SectionsFlag: strings.Join(settings.Sections, gciAnalyzer.SectionDelimiter),
gciAnalyzer.SectionSeparatorsFlag: strings.Join(settings.SectionSeparator, gciAnalyzer.SectionDelimiter),
}

if settings.LocalPrefixes != "" {
prefix := []string{"Standard", "Default", fmt.Sprintf("Prefix(%s)", settings.LocalPrefixes)}
cfg[gciAnalyzer.SectionsFlag] = strings.Join(prefix, gciAnalyzer.SectionDelimiter)
}

linterCfg = map[string]map[string]interface{}{
gciAnalyzer.Analyzer.Name: cfg,
}
}

return goanalysis.NewLinter(
gciName,
"Gci controls golang package import order and makes it always deterministic.",
[]*analysis.Analyzer{analyzer},
cfg,
[]*analysis.Analyzer{gciAnalyzer.Analyzer},
linterCfg,
).WithLoadMode(goanalysis.LoadModeSyntax)
}
9 changes: 0 additions & 9 deletions pkg/golinters/gofmt_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,6 @@ func getErrorTextForLinter(lintCtx *linter.Context, linterName string) string {
if lintCtx.Settings().Goimports.LocalPrefixes != "" {
text += " with -local " + lintCtx.Settings().Goimports.LocalPrefixes
}
case gciName:
optionsText := []string{}
if lintCtx.Settings().Gci.NoInlineComments {
optionsText = append(optionsText, "NoInlineComments")
}
if lintCtx.Settings().Gci.NoPrefixComments {
optionsText = append(optionsText, "NoPrefixComments")
}
text = fmt.Sprintf("File does not conform to the import format configured for `Gci`(%s)", strings.Join(optionsText, ","))
}
return text
}
Expand Down