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.12.3 to 0.13.3 #4522

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ linters-settings:

# Section configuration to compare against.
# Section names are case-insensitive and may contain parameters in ().
# The default order of sections is `standard > default > custom > blank > dot > alias`,
# The default order of sections is `standard > default > custom > blank > dot > alias > localmodule`,
# If `custom-order` is `true`, it follows the order of `sections` option.
# Default: ["standard", "default"]
sections:
Expand All @@ -446,6 +446,7 @@ linters-settings:
- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
- dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.
- alias # Alias section: contains all alias imports. This section is not present unless explicitly enabled.
- localmodule # Local module section: contains all local packages. This section is not present unless explicitly enabled.

# Skip generated files.
# Default: true
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
github.com/charithe/durationcheck v0.0.10
github.com/ckaznocha/intrange v0.1.1
github.com/curioswitch/go-reassign v0.2.0
github.com/daixiang0/gci v0.12.3
github.com/daixiang0/gci v0.13.3
github.com/denis-tingaikin/go-header v0.5.0
github.com/fatih/color v1.16.0
github.com/firefart/nonamedreturns v1.0.4
Expand All @@ -44,6 +44,7 @@ require (
github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a
github.com/golangci/gofmt v0.0.0-20231018234816-f50ced29576e
github.com/golangci/misspell v0.4.1
github.com/golangci/modinfo v0.3.4
github.com/golangci/plugin-module-register v0.1.1
github.com/golangci/revgrep v0.5.2
github.com/golangci/unconvert v0.0.0-20240309020433-c5143eacb3ed
Expand Down
6 changes: 4 additions & 2 deletions go.sum

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

16 changes: 15 additions & 1 deletion jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,21 @@
"description": "Section configuration to compare against.",
"type": "array",
"items": {
"type": "string"
"anyOf": [
{
"enum": [
"standard",
"default",
"blank",
"dot",
"alias",
"localmodule"
]
},
{
"type": "string"
}
]
},
"default": ["standard", "default"]
},
Expand Down
124 changes: 107 additions & 17 deletions pkg/golinters/gci.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ package golinters

import (
"fmt"
"sort"
"strings"
"sync"

gcicfg "github.com/daixiang0/gci/pkg/config"
"github.com/daixiang0/gci/pkg/gci"
"github.com/daixiang0/gci/pkg/io"
"github.com/daixiang0/gci/pkg/log"
"github.com/daixiang0/gci/pkg/section"
"github.com/golangci/modinfo"
"github.com/hexops/gotextdiff"
"github.com/hexops/gotextdiff/myers"
"github.com/hexops/gotextdiff/span"
Expand All @@ -29,6 +33,9 @@ func NewGci(settings *config.GciSettings) *goanalysis.Linter {
Name: gciName,
Doc: goanalysis.TheOnlyanalyzerDoc,
Run: goanalysis.DummyRun,
Requires: []*analysis.Analyzer{
modinfo.Analyzer,
},
}

var cfg *gcicfg.Config
Expand All @@ -47,7 +54,7 @@ func NewGci(settings *config.GciSettings) *goanalysis.Linter {
}

var err error
cfg, err = rawCfg.Parse()
cfg, err = YamlConfig{origin: rawCfg}.Parse()
if err != nil {
internal.LinterLogger.Fatalf("gci: configuration parsing: %v", err)
}
Expand All @@ -62,6 +69,12 @@ func NewGci(settings *config.GciSettings) *goanalysis.Linter {
nil,
).WithContextSetter(func(lintCtx *linter.Context) {
analyzer.Run = func(pass *analysis.Pass) (any, error) {
var err error
cfg.Sections, err = hackSectionList(pass, cfg)
if err != nil {
return nil, err
}

issues, err := runGci(pass, lintCtx, cfg, &lock)
if err != nil {
return nil, err
Expand Down Expand Up @@ -111,6 +124,57 @@ func runGci(pass *analysis.Pass, lintCtx *linter.Context, cfg *gcicfg.Config, lo
return issues, nil
}

func getIssuedTextGci(settings *config.LintersSettings) string {
text := "File is not `gci`-ed"

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

text += " with"

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

if len(settings.Gci.Sections) > 0 {
for _, sect := range settings.Gci.Sections {
text += " -s " + sect
}
}

if settings.Gci.CustomOrder {
text += " --custom-order"
}

return text
}

func hackSectionList(pass *analysis.Pass, cfg *gcicfg.Config) (section.SectionList, error) {
var sections section.SectionList

for _, sect := range cfg.Sections {
// local module hack
if v, ok := sect.(*section.LocalModule); ok {
info, err := modinfo.FindModuleFromPass(pass)
if err != nil {
return nil, err
}

if info.Path == "" {
continue
}

v.Path = info.Path
}

sections = append(sections, sect)
}

return sections, nil
}

// diffFormattedFilesToArray is a copy of gci.DiffFormattedFilesToArray without io.StdInGenerator.
// gci.DiffFormattedFilesToArray uses gci.processStdInAndGoFilesInPaths that uses io.StdInGenerator but stdin is not active on CI.
// https://github.com/daixiang0/gci/blob/6f5cb16718ba07f0342a58de9b830ec5a6d58790/pkg/gci/gci.go#L63-L75
Expand All @@ -130,29 +194,55 @@ func diffFormattedFilesToArray(paths []string, cfg gcicfg.Config, diffs *[]strin
})
}

func getIssuedTextGci(settings *config.LintersSettings) string {
text := "File is not `gci`-ed"
// Code bellow this comment is borrowed and modified from gci.
// https://github.com/daixiang0/gci/blob/4725b0c101801e7449530eee2ddb0c72592e3405/pkg/config/config.go

var defaultOrder = map[string]int{
section.StandardType: 0,
section.DefaultType: 1,
section.CustomType: 2,
section.BlankType: 3,
section.DotType: 4,
section.AliasType: 5,
section.LocalModuleType: 6,
}

hasOptions := settings.Gci.SkipGenerated || len(settings.Gci.Sections) > 0
if !hasOptions {
return text
}
type YamlConfig struct {
origin gcicfg.YamlConfig
}

text += " with"
//nolint:gocritic // code borrowed from gci and modified to fix LocalModule section behavior.
func (g YamlConfig) Parse() (*gcicfg.Config, error) {
var err error

if settings.Gci.SkipGenerated {
text += " --skip-generated"
sections, err := section.Parse(g.origin.SectionStrings)
if err != nil {
return nil, err
}

if len(settings.Gci.Sections) > 0 {
for _, section := range settings.Gci.Sections {
text += " -s " + section
}
if sections == nil {
sections = section.DefaultSections()
}

if settings.Gci.CustomOrder {
text += " --custom-order"
// if default order sorted sections
if !g.origin.Cfg.CustomOrder {
sort.Slice(sections, func(i, j int) bool {
sectionI, sectionJ := sections[i].Type(), sections[j].Type()

if strings.Compare(sectionI, sectionJ) == 0 {
return strings.Compare(sections[i].String(), sections[j].String()) < 0
}
return defaultOrder[sectionI] < defaultOrder[sectionJ]
})
}

return text
sectionSeparators, err := section.Parse(g.origin.SectionSeparatorStrings)
if err != nil {
return nil, err
}
if sectionSeparators == nil {
sectionSeparators = section.DefaultSectionSeparators()
}

return &gcicfg.Config{BoolConfig: g.origin.Cfg, Sections: sections, SectionSeparators: sectionSeparators}, nil
}
Loading