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

build(deps): bump github.com/daixiang0/gci from 0.3.4 to 0.4.0 #2965

Merged
merged 3 commits into from Jul 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 3 additions & 14 deletions .golangci.reference.yml
Expand Up @@ -341,28 +341,17 @@ linters-settings:
# 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-inline-comments: true

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

# Section configuration to compare against.
# Section names are case-insensitive and may contain parameters in ().
# Default: ["standard", "default"]
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.

# Separators that should be present between sections.
# Default: ["newLine"]
section-separators:
- newLine
# Skip generated files.
# Default: true
skip-generated: false

gocognit:
# Minimal code complexity to report
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -20,7 +20,7 @@ require (
github.com/breml/errchkjson v0.3.0
github.com/butuzov/ireturn v0.1.1
github.com/charithe/durationcheck v0.0.9
github.com/daixiang0/gci v0.3.4
github.com/daixiang0/gci v0.4.0
github.com/denis-tingaikin/go-header v0.4.3
github.com/esimonov/ifshort v1.0.4
github.com/fatih/color v1.13.0
Expand Down
5 changes: 3 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions pkg/config/linters_settings.go
Expand Up @@ -31,8 +31,8 @@ var defaultLintersSettings = LintersSettings{
ExcludeGodocExamples: true,
},
Gci: GciSettings{
Sections: []string{"standard", "default"},
SectionSeparator: []string{"newline"},
Sections: []string{"standard", "default"},
SkipGenerated: true,
},
Gocognit: GocognitSettings{
MinComplexity: 30,
Expand Down Expand Up @@ -275,11 +275,9 @@ type FunlenSettings struct {
}

type GciSettings struct {
LocalPrefixes string `mapstructure:"local-prefixes"` // Deprecated
NoInlineComments bool `mapstructure:"no-inline-comments"`
NoPrefixComments bool `mapstructure:"no-prefix-comments"`
Sections []string `mapstructure:"sections"`
SectionSeparator []string `mapstructure:"section-separators"`
LocalPrefixes string `mapstructure:"local-prefixes"` // Deprecated
Sections []string `mapstructure:"sections"`
SkipGenerated bool `mapstructure:"skip-generated"`
}

type GocognitSettings struct {
Expand Down
30 changes: 10 additions & 20 deletions pkg/golinters/gci.go
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"sync"

gcicfg "github.com/daixiang0/gci/pkg/configuration"
gcicfg "github.com/daixiang0/gci/pkg/config"
"github.com/daixiang0/gci/pkg/gci"
"github.com/pkg/errors"
"golang.org/x/tools/go/analysis"
Expand All @@ -27,15 +27,13 @@ func NewGci(settings *config.GciSettings) *goanalysis.Linter {
Run: goanalysis.DummyRun,
}

var cfg *gci.GciConfiguration
var cfg *gcicfg.Config
if settings != nil {
rawCfg := gci.GciStringConfiguration{
Cfg: gcicfg.FormatterConfiguration{
NoInlineComments: settings.NoInlineComments,
NoPrefixComments: settings.NoPrefixComments,
rawCfg := gcicfg.YamlConfig{
Cfg: gcicfg.BoolConfig{
SkipGenerated: settings.SkipGenerated,
},
SectionStrings: settings.Sections,
SectionSeparatorStrings: settings.SectionSeparator,
SectionStrings: settings.Sections,
}

if settings.LocalPrefixes != "" {
Expand Down Expand Up @@ -75,7 +73,7 @@ func NewGci(settings *config.GciSettings) *goanalysis.Linter {
}).WithLoadMode(goanalysis.LoadModeSyntax)
}

func runGci(pass *analysis.Pass, lintCtx *linter.Context, cfg *gci.GciConfiguration, lock *sync.Mutex) ([]goanalysis.Issue, error) {
func runGci(pass *analysis.Pass, lintCtx *linter.Context, cfg *gcicfg.Config, lock *sync.Mutex) ([]goanalysis.Issue, error) {
var fileNames []string
for _, f := range pass.Files {
pos := pass.Fset.PositionFor(f.Pos(), false)
Expand Down Expand Up @@ -111,28 +109,20 @@ func runGci(pass *analysis.Pass, lintCtx *linter.Context, cfg *gci.GciConfigurat
func getErrorTextForGci(settings config.GciSettings) string {
text := "File is not `gci`-ed"

hasOptions := settings.NoInlineComments || settings.NoPrefixComments || len(settings.Sections) > 0 || len(settings.SectionSeparator) > 0
hasOptions := settings.SkipGenerated || len(settings.Sections) > 0
if !hasOptions {
return text
}

text += " with"

if settings.NoInlineComments {
text += " -NoInlineComments"
}

if settings.NoPrefixComments {
text += " -NoPrefixComments"
if settings.SkipGenerated {
text += " -skip-generated"
}

if len(settings.Sections) > 0 {
text += " -s " + strings.Join(settings.Sections, ",")
}

if len(settings.SectionSeparator) > 0 {
text += " -x " + strings.Join(settings.SectionSeparator, ",")
}

return text
}