Skip to content

Commit

Permalink
build(deps): bump github.com/daixiang0/gci from 0.3.4 to 0.4.0 (#2965)
Browse files Browse the repository at this point in the history
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
  • Loading branch information
daixiang0 and ldez committed Jul 9, 2022
1 parent 9317da6 commit b8f1e2a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 44 deletions.
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
}

0 comments on commit b8f1e2a

Please sign in to comment.