aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/daixiang0
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2024-09-10 12:16:33 +0200
committerTaras Madan <tarasmadan@google.com>2024-09-10 14:05:26 +0000
commitc97c816133b42257d0bcf1ee4bd178bb2a7a2b9e (patch)
tree0bcbc2e540bbf8f62f6c17887cdd53b8c2cee637 /vendor/github.com/daixiang0
parent54e657429ab892ad06c90cd7c1a4eb33ba93a3dc (diff)
vendor: update
Diffstat (limited to 'vendor/github.com/daixiang0')
-rw-r--r--vendor/github.com/daixiang0/gci/pkg/config/config.go43
-rw-r--r--vendor/github.com/daixiang0/gci/pkg/gci/testdata.go2
-rw-r--r--vendor/github.com/daixiang0/gci/pkg/section/local_module.go59
-rw-r--r--vendor/github.com/daixiang0/gci/pkg/section/parser.go3
-rw-r--r--vendor/github.com/daixiang0/gci/pkg/section/standard_list.go7
-rw-r--r--vendor/github.com/daixiang0/gci/pkg/specificity/local_module.go15
-rw-r--r--vendor/github.com/daixiang0/gci/pkg/specificity/specificity.go11
7 files changed, 124 insertions, 16 deletions
diff --git a/vendor/github.com/daixiang0/gci/pkg/config/config.go b/vendor/github.com/daixiang0/gci/pkg/config/config.go
index 51f6ccf3b..814201a00 100644
--- a/vendor/github.com/daixiang0/gci/pkg/config/config.go
+++ b/vendor/github.com/daixiang0/gci/pkg/config/config.go
@@ -10,12 +10,13 @@ import (
)
var defaultOrder = map[string]int{
- section.StandardType: 0,
- section.DefaultType: 1,
- section.CustomType: 2,
- section.BlankType: 3,
- section.DotType: 4,
- section.AliasType: 5,
+ section.StandardType: 0,
+ section.DefaultType: 1,
+ section.CustomType: 2,
+ section.BlankType: 3,
+ section.DotType: 4,
+ section.AliasType: 5,
+ section.LocalModuleType: 6,
}
type BoolConfig struct {
@@ -25,6 +26,7 @@ type BoolConfig struct {
SkipGenerated bool `yaml:"skipGenerated"`
SkipVendor bool `yaml:"skipVendor"`
CustomOrder bool `yaml:"customOrder"`
+ NoLexOrder bool `yaml:"noLexOrder"`
}
type Config struct {
@@ -37,6 +39,10 @@ type YamlConfig struct {
Cfg BoolConfig `yaml:",inline"`
SectionStrings []string `yaml:"sections"`
SectionSeparatorStrings []string `yaml:"sectionseparators"`
+
+ // Since history issue, Golangci-lint needs Analyzer to run and GCI add an Analyzer layer to integrate.
+ // The ModPath param is only from analyzer.go, no need to set it in all other places.
+ ModPath string `yaml:"-"`
}
func (g YamlConfig) Parse() (*Config, error) {
@@ -49,16 +55,20 @@ func (g YamlConfig) Parse() (*Config, error) {
if sections == nil {
sections = section.DefaultSections()
}
+ if err := configureSections(sections, g.ModPath); err != nil {
+ return nil, err
+ }
// if default order sorted sections
if !g.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
+ if g.Cfg.NoLexOrder || strings.Compare(sectionI, sectionJ) != 0 {
+ return defaultOrder[sectionI] < defaultOrder[sectionJ]
}
- return defaultOrder[sectionI] < defaultOrder[sectionJ]
+
+ return strings.Compare(sections[i].String(), sections[j].String()) < 0
})
}
@@ -88,3 +98,18 @@ func ParseConfig(in string) (*Config, error) {
return gciCfg, nil
}
+
+// configureSections now only do golang module path finding.
+// Since history issue, Golangci-lint needs Analyzer to run and GCI add an Analyzer layer to integrate.
+// The path param is from analyzer.go, in all other places should pass empty string.
+func configureSections(sections section.SectionList, path string) error {
+ for _, sec := range sections {
+ switch s := sec.(type) {
+ case *section.LocalModule:
+ if err := s.Configure(path); err != nil {
+ return err
+ }
+ }
+ }
+ return nil
+}
diff --git a/vendor/github.com/daixiang0/gci/pkg/gci/testdata.go b/vendor/github.com/daixiang0/gci/pkg/gci/testdata.go
index 4f60e8806..866ae84c4 100644
--- a/vendor/github.com/daixiang0/gci/pkg/gci/testdata.go
+++ b/vendor/github.com/daixiang0/gci/pkg/gci/testdata.go
@@ -421,7 +421,7 @@ import (
`,
},
{
- "comment-whithout-whitespace",
+ "comment-without-whitespace",
commonConfig,
diff --git a/vendor/github.com/daixiang0/gci/pkg/section/local_module.go b/vendor/github.com/daixiang0/gci/pkg/section/local_module.go
new file mode 100644
index 000000000..50f41e501
--- /dev/null
+++ b/vendor/github.com/daixiang0/gci/pkg/section/local_module.go
@@ -0,0 +1,59 @@
+package section
+
+import (
+ "fmt"
+ "os"
+ "strings"
+
+ "golang.org/x/mod/modfile"
+
+ "github.com/daixiang0/gci/pkg/parse"
+ "github.com/daixiang0/gci/pkg/specificity"
+)
+
+const LocalModuleType = "localmodule"
+
+type LocalModule struct {
+ Path string
+}
+
+func (m *LocalModule) MatchSpecificity(spec *parse.GciImports) specificity.MatchSpecificity {
+ if spec.Path == m.Path || strings.HasPrefix(spec.Path, m.Path+"/") {
+ return specificity.LocalModule{}
+ }
+
+ return specificity.MisMatch{}
+}
+
+func (m *LocalModule) String() string {
+ return LocalModuleType
+}
+
+func (m *LocalModule) Type() string {
+ return LocalModuleType
+}
+
+// Configure configures the module section by finding the module
+// for the current path
+func (m *LocalModule) Configure(path string) error {
+ if path != "" {
+ m.Path = path
+ } else {
+ path, err := findLocalModule()
+ if err != nil {
+ return fmt.Errorf("finding local modules for `localModule` configuration: %w", err)
+ }
+ m.Path = path
+ }
+
+ return nil
+}
+
+func findLocalModule() (string, error) {
+ b, err := os.ReadFile("go.mod")
+ if err != nil {
+ return "", fmt.Errorf("reading go.mod: %w", err)
+ }
+
+ return modfile.ModulePath(b), nil
+}
diff --git a/vendor/github.com/daixiang0/gci/pkg/section/parser.go b/vendor/github.com/daixiang0/gci/pkg/section/parser.go
index 38435f540..62ed1582a 100644
--- a/vendor/github.com/daixiang0/gci/pkg/section/parser.go
+++ b/vendor/github.com/daixiang0/gci/pkg/section/parser.go
@@ -35,6 +35,9 @@ func Parse(data []string) (SectionList, error) {
list = append(list, Blank{})
} else if s == "alias" {
list = append(list, Alias{})
+ } else if s == "localmodule" {
+ // pointer because we need to mutate the section at configuration time
+ list = append(list, &LocalModule{})
} else {
errString += fmt.Sprintf(" %s", s)
}
diff --git a/vendor/github.com/daixiang0/gci/pkg/section/standard_list.go b/vendor/github.com/daixiang0/gci/pkg/section/standard_list.go
index 551bba428..5a2dcdc89 100644
--- a/vendor/github.com/daixiang0/gci/pkg/section/standard_list.go
+++ b/vendor/github.com/daixiang0/gci/pkg/section/standard_list.go
@@ -1,6 +1,6 @@
package section
-// Code generated based on go1.22.0 X:arenas. DO NOT EDIT.
+// Code generated based on go1.23.0 X:boringcrypto,arenas. DO NOT EDIT.
var standardPackages = map[string]struct{}{
"archive/tar": {},
@@ -20,6 +20,7 @@ var standardPackages = map[string]struct{}{
"context": {},
"crypto": {},
"crypto/aes": {},
+ "crypto/boring": {},
"crypto/cipher": {},
"crypto/des": {},
"crypto/dsa": {},
@@ -37,6 +38,7 @@ var standardPackages = map[string]struct{}{
"crypto/sha512": {},
"crypto/subtle": {},
"crypto/tls": {},
+ "crypto/tls/fipsonly": {},
"crypto/x509": {},
"crypto/x509/pkix": {},
"database/sql": {},
@@ -98,6 +100,7 @@ var standardPackages = map[string]struct{}{
"io": {},
"io/fs": {},
"io/ioutil": {},
+ "iter": {},
"log": {},
"log/slog": {},
"log/syslog": {},
@@ -149,6 +152,7 @@ var standardPackages = map[string]struct{}{
"sort": {},
"strconv": {},
"strings": {},
+ "structs": {},
"sync": {},
"sync/atomic": {},
"syscall": {},
@@ -166,5 +170,6 @@ var standardPackages = map[string]struct{}{
"unicode": {},
"unicode/utf16": {},
"unicode/utf8": {},
+ "unique": {},
"unsafe": {},
}
diff --git a/vendor/github.com/daixiang0/gci/pkg/specificity/local_module.go b/vendor/github.com/daixiang0/gci/pkg/specificity/local_module.go
new file mode 100644
index 000000000..ae482fec4
--- /dev/null
+++ b/vendor/github.com/daixiang0/gci/pkg/specificity/local_module.go
@@ -0,0 +1,15 @@
+package specificity
+
+type LocalModule struct{}
+
+func (m LocalModule) IsMoreSpecific(than MatchSpecificity) bool {
+ return isMoreSpecific(m, than)
+}
+
+func (m LocalModule) Equal(to MatchSpecificity) bool {
+ return equalSpecificity(m, to)
+}
+
+func (LocalModule) class() specificityClass {
+ return LocalModuleClass
+}
diff --git a/vendor/github.com/daixiang0/gci/pkg/specificity/specificity.go b/vendor/github.com/daixiang0/gci/pkg/specificity/specificity.go
index 842da1857..4a188b3bb 100644
--- a/vendor/github.com/daixiang0/gci/pkg/specificity/specificity.go
+++ b/vendor/github.com/daixiang0/gci/pkg/specificity/specificity.go
@@ -3,11 +3,12 @@ package specificity
type specificityClass int
const (
- MisMatchClass = 0
- DefaultClass = 10
- StandardClass = 20
- MatchClass = 30
- NameClass = 40
+ MisMatchClass = 0
+ DefaultClass = 10
+ StandardClass = 20
+ MatchClass = 30
+ NameClass = 40
+ LocalModuleClass = 50
)
// MatchSpecificity is used to determine which section matches an import best