diff options
| author | Taras Madan <tarasmadan@google.com> | 2025-01-22 16:07:17 +0100 |
|---|---|---|
| committer | Taras Madan <tarasmadan@google.com> | 2025-01-23 10:42:36 +0000 |
| commit | 7b4377ad9d8a7205416df8d6217ef2b010f89481 (patch) | |
| tree | e6fec4fd12ff807a16d847923f501075bf71d16c /vendor/github.com/daixiang0 | |
| parent | 475a4c203afb8b7d3af51c4fd32bb170ff32a45e (diff) | |
vendor: delete
Diffstat (limited to 'vendor/github.com/daixiang0')
31 files changed, 0 insertions, 2927 deletions
diff --git a/vendor/github.com/daixiang0/gci/LICENSE b/vendor/github.com/daixiang0/gci/LICENSE deleted file mode 100644 index e1292f738..000000000 --- a/vendor/github.com/daixiang0/gci/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -BSD 3-Clause License - -Copyright (c) 2020, Xiang Dai -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/daixiang0/gci/pkg/config/config.go b/vendor/github.com/daixiang0/gci/pkg/config/config.go deleted file mode 100644 index 814201a00..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/config/config.go +++ /dev/null @@ -1,115 +0,0 @@ -package config - -import ( - "sort" - "strings" - - "gopkg.in/yaml.v3" - - "github.com/daixiang0/gci/pkg/section" -) - -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, -} - -type BoolConfig struct { - NoInlineComments bool `yaml:"no-inlineComments"` - NoPrefixComments bool `yaml:"no-prefixComments"` - Debug bool `yaml:"-"` - SkipGenerated bool `yaml:"skipGenerated"` - SkipVendor bool `yaml:"skipVendor"` - CustomOrder bool `yaml:"customOrder"` - NoLexOrder bool `yaml:"noLexOrder"` -} - -type Config struct { - BoolConfig - Sections section.SectionList - SectionSeparators section.SectionList -} - -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) { - var err error - - sections, err := section.Parse(g.SectionStrings) - if err != nil { - return nil, err - } - 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 g.Cfg.NoLexOrder || strings.Compare(sectionI, sectionJ) != 0 { - return defaultOrder[sectionI] < defaultOrder[sectionJ] - } - - return strings.Compare(sections[i].String(), sections[j].String()) < 0 - }) - } - - sectionSeparators, err := section.Parse(g.SectionSeparatorStrings) - if err != nil { - return nil, err - } - if sectionSeparators == nil { - sectionSeparators = section.DefaultSectionSeparators() - } - - return &Config{g.Cfg, sections, sectionSeparators}, nil -} - -func ParseConfig(in string) (*Config, error) { - config := YamlConfig{} - - err := yaml.Unmarshal([]byte(in), &config) - if err != nil { - return nil, err - } - - gciCfg, err := config.Parse() - if err != nil { - return nil, err - } - - 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/format/format.go b/vendor/github.com/daixiang0/gci/pkg/format/format.go deleted file mode 100644 index 062701d2e..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/format/format.go +++ /dev/null @@ -1,46 +0,0 @@ -package format - -import ( - "fmt" - - "github.com/daixiang0/gci/pkg/config" - "github.com/daixiang0/gci/pkg/log" - "github.com/daixiang0/gci/pkg/parse" - "github.com/daixiang0/gci/pkg/section" - "github.com/daixiang0/gci/pkg/specificity" -) - -type Block struct { - Start, End int -} - -type resultMap map[string][]*Block - -func Format(data []*parse.GciImports, cfg *config.Config) (resultMap, error) { - result := make(resultMap, len(cfg.Sections)) - for _, d := range data { - // determine match specificity for every available section - var bestSection section.Section - var bestSectionSpecificity specificity.MatchSpecificity = specificity.MisMatch{} - for _, section := range cfg.Sections { - sectionSpecificity := section.MatchSpecificity(d) - if sectionSpecificity.IsMoreSpecific(specificity.MisMatch{}) && sectionSpecificity.Equal(bestSectionSpecificity) { - // specificity is identical - // return nil, section.EqualSpecificityMatchError{} - return nil, nil - } - if sectionSpecificity.IsMoreSpecific(bestSectionSpecificity) { - // better match found - bestSectionSpecificity = sectionSpecificity - bestSection = section - } - } - if bestSection == nil { - return nil, section.NoMatchingSectionForImportError{Imports: d} - } - log.L().Debug(fmt.Sprintf("Matched import %v to section %s", d, bestSection)) - result[bestSection.String()] = append(result[bestSection.String()], &Block{d.Start, d.End}) - } - - return result, nil -} diff --git a/vendor/github.com/daixiang0/gci/pkg/gci/gci.go b/vendor/github.com/daixiang0/gci/pkg/gci/gci.go deleted file mode 100644 index 163e95a86..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/gci/gci.go +++ /dev/null @@ -1,229 +0,0 @@ -package gci - -import ( - "bytes" - "errors" - "fmt" - goFormat "go/format" - "os" - "sync" - - "github.com/hexops/gotextdiff" - "github.com/hexops/gotextdiff/myers" - "github.com/hexops/gotextdiff/span" - "golang.org/x/sync/errgroup" - - "github.com/daixiang0/gci/pkg/config" - "github.com/daixiang0/gci/pkg/format" - "github.com/daixiang0/gci/pkg/io" - "github.com/daixiang0/gci/pkg/log" - "github.com/daixiang0/gci/pkg/parse" - "github.com/daixiang0/gci/pkg/section" - "github.com/daixiang0/gci/pkg/utils" -) - -func LocalFlagsToSections(localFlags []string) section.SectionList { - sections := section.DefaultSections() - // Add all local arguments as ImportPrefix sections - // for _, l := range localFlags { - // sections = append(sections, section.Section{l, nil, nil}) - // } - return sections -} - -func PrintFormattedFiles(paths []string, cfg config.Config) error { - return processStdInAndGoFilesInPaths(paths, cfg, func(filePath string, unmodifiedFile, formattedFile []byte) error { - fmt.Print(string(formattedFile)) - return nil - }) -} - -func WriteFormattedFiles(paths []string, cfg config.Config) error { - return processGoFilesInPaths(paths, cfg, func(filePath string, unmodifiedFile, formattedFile []byte) error { - if bytes.Equal(unmodifiedFile, formattedFile) { - log.L().Debug(fmt.Sprintf("Skipping correctly formatted File: %s", filePath)) - return nil - } - log.L().Info(fmt.Sprintf("Writing formatted File: %s", filePath)) - return os.WriteFile(filePath, formattedFile, 0o644) - }) -} - -func ListUnFormattedFiles(paths []string, cfg config.Config) error { - return processGoFilesInPaths(paths, cfg, func(filePath string, unmodifiedFile, formattedFile []byte) error { - if bytes.Equal(unmodifiedFile, formattedFile) { - return nil - } - fmt.Println(filePath) - return nil - }) -} - -func DiffFormattedFiles(paths []string, cfg config.Config) error { - return processStdInAndGoFilesInPaths(paths, cfg, func(filePath string, unmodifiedFile, formattedFile []byte) error { - fileURI := span.URIFromPath(filePath) - edits := myers.ComputeEdits(fileURI, string(unmodifiedFile), string(formattedFile)) - unifiedEdits := gotextdiff.ToUnified(filePath, filePath, string(unmodifiedFile), edits) - fmt.Printf("%v", unifiedEdits) - return nil - }) -} - -func DiffFormattedFilesToArray(paths []string, cfg config.Config, diffs *[]string, lock *sync.Mutex) error { - log.InitLogger() - defer log.L().Sync() - return processStdInAndGoFilesInPaths(paths, cfg, func(filePath string, unmodifiedFile, formattedFile []byte) error { - fileURI := span.URIFromPath(filePath) - edits := myers.ComputeEdits(fileURI, string(unmodifiedFile), string(formattedFile)) - unifiedEdits := gotextdiff.ToUnified(filePath, filePath, string(unmodifiedFile), edits) - lock.Lock() - *diffs = append(*diffs, fmt.Sprint(unifiedEdits)) - lock.Unlock() - return nil - }) -} - -type fileFormattingFunc func(filePath string, unmodifiedFile, formattedFile []byte) error - -func processStdInAndGoFilesInPaths(paths []string, cfg config.Config, fileFunc fileFormattingFunc) error { - return ProcessFiles(io.StdInGenerator.Combine(io.GoFilesInPathsGenerator(paths, cfg.SkipVendor)), cfg, fileFunc) -} - -func processGoFilesInPaths(paths []string, cfg config.Config, fileFunc fileFormattingFunc) error { - return ProcessFiles(io.GoFilesInPathsGenerator(paths, cfg.SkipVendor), cfg, fileFunc) -} - -func ProcessFiles(fileGenerator io.FileGeneratorFunc, cfg config.Config, fileFunc fileFormattingFunc) error { - var taskGroup errgroup.Group - files, err := fileGenerator() - if err != nil { - return err - } - for _, file := range files { - // run file processing in parallel - taskGroup.Go(processingFunc(file, cfg, fileFunc)) - } - return taskGroup.Wait() -} - -func processingFunc(file io.FileObj, cfg config.Config, formattingFunc fileFormattingFunc) func() error { - return func() error { - unmodifiedFile, formattedFile, err := LoadFormatGoFile(file, cfg) - if err != nil { - // if errors.Is(err, FileParsingError{}) { - // // do not process files that are improperly formatted - // return nil - // } - return err - } - return formattingFunc(file.Path(), unmodifiedFile, formattedFile) - } -} - -func LoadFormatGoFile(file io.FileObj, cfg config.Config) (src, dist []byte, err error) { - src, err = file.Load() - log.L().Debug(fmt.Sprintf("Loaded File: %s", file.Path())) - if err != nil { - return nil, nil, err - } - - return LoadFormat(src, file.Path(), cfg) -} - -func LoadFormat(in []byte, path string, cfg config.Config) (src, dist []byte, err error) { - src = in - - if cfg.SkipGenerated && parse.IsGeneratedFileByComment(string(src)) { - return src, src, nil - } - - imports, headEnd, tailStart, cStart, cEnd, err := parse.ParseFile(src, path) - if err != nil { - if errors.Is(err, parse.NoImportError{}) { - return src, src, nil - } - return nil, nil, err - } - - // do not do format if only one import - if len(imports) <= 1 { - return src, src, nil - } - - result, err := format.Format(imports, &cfg) - if err != nil { - return nil, nil, err - } - - firstWithIndex := true - - var body []byte - - // order by section list - for _, s := range cfg.Sections { - if len(result[s.String()]) > 0 { - if len(body) > 0 { - body = append(body, utils.Linebreak) - } - for _, d := range result[s.String()] { - AddIndent(&body, &firstWithIndex) - body = append(body, src[d.Start:d.End]...) - } - } - } - - head := make([]byte, headEnd) - copy(head, src[:headEnd]) - tail := make([]byte, len(src)-tailStart) - copy(tail, src[tailStart:]) - - // ensure C - if cStart != 0 { - head = append(head, src[cStart:cEnd]...) - head = append(head, utils.Linebreak) - } - - // add beginning of import block - head = append(head, `import (`...) - head = append(head, utils.Linebreak) - // add end of import block - body = append(body, []byte{utils.RightParenthesis, utils.Linebreak}...) - - log.L().Debug(fmt.Sprintf("head:\n%s", head)) - log.L().Debug(fmt.Sprintf("body:\n%s", body)) - if len(tail) > 20 { - log.L().Debug(fmt.Sprintf("tail:\n%s", tail[:20])) - } else { - log.L().Debug(fmt.Sprintf("tail:\n%s", tail)) - } - - var totalLen int - slices := [][]byte{head, body, tail} - for _, s := range slices { - totalLen += len(s) - } - dist = make([]byte, totalLen) - var i int - for _, s := range slices { - i += copy(dist[i:], s) - } - - // remove ^M(\r\n) from Win to Unix - dist = bytes.ReplaceAll(dist, []byte{utils.WinLinebreak}, []byte{utils.Linebreak}) - - log.L().Debug(fmt.Sprintf("raw:\n%s", dist)) - dist, err = goFormat.Source(dist) - if err != nil { - return nil, nil, err - } - - return src, dist, nil -} - -func AddIndent(in *[]byte, first *bool) { - if *first { - *first = false - return - } - *in = append(*in, utils.Indent) -} diff --git a/vendor/github.com/daixiang0/gci/pkg/gci/testdata.go b/vendor/github.com/daixiang0/gci/pkg/gci/testdata.go deleted file mode 100644 index 866ae84c4..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/gci/testdata.go +++ /dev/null @@ -1,1298 +0,0 @@ -package gci - -type Cases struct { - name, config, in, out string -} - -var commonConfig = `sections: - - Standard - - Default - - Prefix(github.com/daixiang0) -` - -var testCases = []Cases{ - { - "already-good", - - commonConfig, - - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" -) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" -) -`, - }, - { - "blank-format", - - commonConfig, - - `package main -import ( - "fmt" - - // comment - g "github.com/golang" // comment - - "github.com/daixiang0/gci" -) -`, - `package main - -import ( - "fmt" - - // comment - g "github.com/golang" // comment - - "github.com/daixiang0/gci" -) -`, - }, - { - "cgo-block", - - commonConfig, - - `package main - -import ( - /* - #include "types.h" - */ - "C" -) -`, - `package main - -import ( - /* - #include "types.h" - */ - "C" -) -`, - }, - { - "cgo-block-after-import", - - commonConfig, - - `package main - -import ( - "fmt" - - "github.com/daixiang0/gci" - g "github.com/golang" -) - -// #cgo CFLAGS: -DPNG_DEBUG=1 -// #cgo amd64 386 CFLAGS: -DX86=1 -// #cgo LDFLAGS: -lpng -// #include <png.h> -import "C" -`, - `package main - -// #cgo CFLAGS: -DPNG_DEBUG=1 -// #cgo amd64 386 CFLAGS: -DX86=1 -// #cgo LDFLAGS: -lpng -// #include <png.h> -import "C" - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" -) -`, - }, - { - "cgo-block-before-import", - - commonConfig, - - `package main - -// #cgo CFLAGS: -DPNG_DEBUG=1 -// #cgo amd64 386 CFLAGS: -DX86=1 -// #cgo LDFLAGS: -lpng -// #include <png.h> -import "C" - -import ( - "fmt" - - "github.com/daixiang0/gci" - - g "github.com/golang" -) -`, - `package main - -// #cgo CFLAGS: -DPNG_DEBUG=1 -// #cgo amd64 386 CFLAGS: -DX86=1 -// #cgo LDFLAGS: -lpng -// #include <png.h> -import "C" - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" -) -`, - }, - { - "cgo-block-mixed", - - commonConfig, - - `package main - -import ( - /* #include "types.h" - */"C" -) -`, - `package main - -import ( - /* #include "types.h" - */"C" -) -`, - }, - { - "cgo-block-mixed-with-content", - - commonConfig, - - `package main - -import ( - /* #include "types.h" - #include "other.h" */"C" -) -`, - `package main - -import ( - /* #include "types.h" - #include "other.h" */"C" -) -`, - }, - { - "cgo-block-prefix", - - commonConfig, - - `package main - -import ( - /* #include "types.h" */ "C" -) -`, - `package main - -import ( - /* #include "types.h" */ "C" -) -`, - }, - { - "cgo-block-single-line", - - commonConfig, - - `package main - -import ( - /* #include "types.h" */ - "C" -) -`, - `package main - -import ( - /* #include "types.h" */ - "C" -) -`, - }, - { - "cgo-line", - - commonConfig, - - `package main - -import ( - // #include "types.h" - "C" -) -`, - `package main - -import ( - // #include "types.h" - "C" -) -`, - }, - { - "cgo-multiline", - - commonConfig, - - `package main - -import ( - // #include "types.h" - // #include "other.h" - "C" -) -`, - `package main - -import ( - // #include "types.h" - // #include "other.h" - "C" -) -`, - }, - { - "cgo-single", - - commonConfig, - - `package main - -import ( - "fmt" - - "github.com/daixiang0/gci" -) - -import "C" - -import "github.com/golang" - -import ( - "github.com/daixiang0/gci" -) -`, - `package main - -import "C" - -import ( - "fmt" - - "github.com/golang" - - "github.com/daixiang0/gci" -) -`, - }, - { - "comment", - - commonConfig, - - `package main -import ( - //Do not forget to run Gci - "fmt" -) -`, - `package main -import ( - //Do not forget to run Gci - "fmt" -) -`, - }, - { - "comment-before-import", - - commonConfig, - - `package main - -// comment -import ( - "fmt" - "os" - - "github.com/daixiang0/gci" -) -`, - `package main - -// comment -import ( - "fmt" - "os" - - "github.com/daixiang0/gci" -) -`, - }, - { - "comment-in-the-tail", - - `sections: - - Standard - - Default - - Prefix(github.com/daixiang0) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" -) - -type test int - -// test -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" -) - -type test int - -// test -`, - }, - { - "comment-top", - - commonConfig, - - `package main - -import ( - "os" // https://pkg.go.dev/os - // https://pkg.go.dev/fmt - "fmt" -) -`, - `package main - -import ( - // https://pkg.go.dev/fmt - "fmt" - "os" // https://pkg.go.dev/os -) -`, - }, - { - "comment-without-whitespace", - - commonConfig, - - `package proc - -import ( - "context"// no separating whitespace here //nolint:confusion -) -`, - `package proc - -import ( - "context"// no separating whitespace here //nolint:confusion -) -`, - }, - { - "comment-with-slashslash", - - commonConfig, - - `package main - -import ( - "fmt" // https://pkg.go.dev/fmt -) -`, - `package main - -import ( - "fmt" // https://pkg.go.dev/fmt -) -`, - }, - { - "custom-order", - - `customOrder: true -sections: - - Prefix(github.com/daixiang0) - - Default - - Standard -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/a" -) -`, - `package main - -import ( - "github.com/daixiang0/a" - - g "github.com/golang" - - "fmt" -) -`, - }, - { - "default-order", - - `sections: - - Standard - - Prefix(github.com/daixiang0) - - Default -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/a" -) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/a" -) -`, - }, - { - "dot-and-blank", - - `sections: - - Standard - - Default - - Prefix(github.com/daixiang0) - - Blank - - Dot -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - . "github.com/golang/dot" - _ "github.com/golang/blank" - - "github.com/daixiang0/a" - "github.com/daixiang0/gci" - "github.com/daixiang0/gci/subtest" - . "github.com/daixiang0/gci/dot" - _ "github.com/daixiang0/gci/blank" -) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/a" - "github.com/daixiang0/gci" - "github.com/daixiang0/gci/subtest" - - _ "github.com/daixiang0/gci/blank" - _ "github.com/golang/blank" - - . "github.com/daixiang0/gci/dot" - . "github.com/golang/dot" -) -`, - }, - { - "duplicate-imports", - - `sections: - - Standard - - Default - - Prefix(github.com/daixiang0) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - a "github.com/daixiang0/gci" - "github.com/daixiang0/gci" -) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" - a "github.com/daixiang0/gci" -) -`, - }, - { - "grouped-multiple-custom", - - `sections: - - Standard - - Default - - Prefix(github.com/daixiang0,gitlab.com/daixiang0,daixiang0) -`, - `package main - -import ( - "daixiang0/lib1" - "fmt" - "github.com/daixiang0/gci" - "gitlab.com/daixiang0/gci" - g "github.com/golang" - "github.com/daixiang0/gci/subtest" -) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "daixiang0/lib1" - "github.com/daixiang0/gci" - "github.com/daixiang0/gci/subtest" - "gitlab.com/daixiang0/gci" -) -`, - }, - { - "leading-comment", - - commonConfig, - - `package main - -import ( - // foo - "fmt" -) -`, - `package main - -import ( - // foo - "fmt" -) -`, - }, - { - "linebreak", - - `sections: - - Standard - - Default - - Prefix(github.com/daixiang0) -`, - `package main - -import ( - g "github.com/golang" - - "fmt" - - "github.com/daixiang0/gci" - -) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" -) -`, - }, - { - "linebreak-no-custom", - - `sections: - - Standard - - Default - - Prefix(github.com/daixiang0) -`, - `package main - -import ( - g "github.com/golang" - - "fmt" - -) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" -) -`, - }, - { - "mismatch-section", - - `sections: - - Standard - - Default - - Prefix(github.com/daixiang0) - - Prefix(github.com/daixiang0/gci) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" -) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" -) -`, - }, - { - "multiple-custom", - - `sections: - - Standard - - Default - - Prefix(github.com/daixiang0) - - Prefix(github.com/daixiang0/gci) - - Prefix(github.com/daixiang0/gci/subtest) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/a" - "github.com/daixiang0/gci" - "github.com/daixiang0/gci/subtest" -) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/a" - - "github.com/daixiang0/gci" - - "github.com/daixiang0/gci/subtest" -) -`, - }, - { - "multiple-imports", - - commonConfig, - - `package main - -import "fmt" - -import "context" - -import ( - "os" - - "github.com/daixiang0/test" -) - -import "math" - - -// main -func main() { -} -`, - `package main - -import ( - "context" - "fmt" - "math" - "os" - - "github.com/daixiang0/test" -) - -// main -func main() { -} -`, - }, - { - "multiple-line-comment", - - commonConfig, - - `package proc - -import ( - "context" // in-line comment - "fmt" - "os" - - //nolint:depguard // A multi-line comment explaining why in - // this one case it's OK to use os/exec even though depguard - // is configured to force us to use dlib/exec instead. - "os/exec" - - "golang.org/x/sys/unix" - "github.com/local/dlib/dexec" -) -`, - `package proc - -import ( - "context" // in-line comment - "fmt" - "os" - //nolint:depguard // A multi-line comment explaining why in - // this one case it's OK to use os/exec even though depguard - // is configured to force us to use dlib/exec instead. - "os/exec" - - "github.com/local/dlib/dexec" - "golang.org/x/sys/unix" -) -`, - }, - { - "nochar-after-import", - - commonConfig, - - `package main - -import ( - "fmt" -) -`, - `package main - -import ( - "fmt" -) -`, - }, - { - "no-format", - - commonConfig, - - `package main - -import( -"fmt" - -g "github.com/golang" - -"github.com/daixiang0/gci" -) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" -) -`, - }, - { - "nolint", - - commonConfig, - - `package main - -import ( - "fmt" - - "github.com/forbidden/pkg" //nolint:depguard - - _ "github.com/daixiang0/gci" //nolint:depguard -) -`, - `package main - -import ( - "fmt" - - "github.com/forbidden/pkg" //nolint:depguard - - _ "github.com/daixiang0/gci" //nolint:depguard -) -`, - }, - { - "number-in-alias", - - commonConfig, - - `package main - -import ( - "fmt" - - go_V1 "github.com/golang" - - "github.com/daixiang0/gci" -) -`, - `package main - -import ( - "fmt" - - go_V1 "github.com/golang" - - "github.com/daixiang0/gci" -) -`, - }, - { - "one-import", - - commonConfig, - - `package main -import ( - "fmt" -) - -func main() { -} -`, - `package main -import ( - "fmt" -) - -func main() { -} -`, - }, - { - "one-import-one-line", - - commonConfig, - - `package main - -import "fmt" - -func main() { -} -`, - `package main - -import "fmt" - -func main() { -} -`, - }, - { - "one-line-import-after-import", - - `sections: - - Standard - - Default - - Prefix(github.com/daixiang0) -`, - `package main - -import ( - "fmt" - "os" - - "github.com/daixiang0/test" -) - -import "context" -`, - `package main - -import ( - "context" - "fmt" - "os" - - "github.com/daixiang0/test" -) -`, - }, - { - "same-prefix-custom", - - `sections: - - Standard - - Default - - Prefix(github.com/daixiang0/gci) - - Prefix(github.com/daixiang0/gci/subtest) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" - "github.com/daixiang0/gci/subtest" -) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" - - "github.com/daixiang0/gci/subtest" -) -`, - }, - { - "simple-case", - - commonConfig, - - `package main - -import ( - "golang.org/x/tools" - - "fmt" - - "github.com/daixiang0/gci" -) -`, - `package main - -import ( - "fmt" - - "golang.org/x/tools" - - "github.com/daixiang0/gci" -) -`, - }, - { - "whitespace-test", - - commonConfig, - - `package main - -import ( - "fmt" - "github.com/golang" // golang - alias "github.com/daixiang0/gci" -) -`, - `package main - -import ( - "fmt" - - "github.com/golang" // golang - - alias "github.com/daixiang0/gci" -) -`, - }, - { - "with-above-comment-and-alias", - - commonConfig, - - `package main - -import ( - "fmt" - // golang - _ "github.com/golang" - "github.com/daixiang0/gci" -) -`, - `package main - -import ( - "fmt" - - // golang - _ "github.com/golang" - - "github.com/daixiang0/gci" -) -`, - }, - { - "with-comment-and-alias", - - commonConfig, - - `package main - -import ( - "fmt" - _ "github.com/golang" // golang - "github.com/daixiang0/gci" -) -`, - `package main - -import ( - "fmt" - - _ "github.com/golang" // golang - - "github.com/daixiang0/gci" -) -`, - }, - { - "same-prefix-custom", - - `sections: - - Standard - - Default - - Prefix(github.com/daixiang0/gci) - - Prefix(github.com/daixiang0/gci/subtest) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" - "github.com/daixiang0/gci/subtest" -) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" - - "github.com/daixiang0/gci/subtest" -) -`, - }, - { - "same-prefix-custom", - - `sections: - - Standard - - Default - - Prefix(github.com/daixiang0/gci) - - Prefix(github.com/daixiang0/gci/subtest) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" - "github.com/daixiang0/gci/subtest" -) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" - - "github.com/daixiang0/gci/subtest" -) -`, - }, - { - "blank-in-config", - - `sections: - - Standard - - Default - - Prefix( github.com/daixiang0/gci, github.com/daixiang0/gci/subtest ) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" - "github.com/daixiang0/gci/subtest" -) -`, - `package main - -import ( - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" - "github.com/daixiang0/gci/subtest" -) -`, - }, - { - "alias", - - `sections: - - Standard - - Default - - Alias -`, - `package main - -import ( - testing "github.com/daixiang0/test" - "fmt" - - g "github.com/golang" - - "github.com/daixiang0/gci" - "github.com/daixiang0/gci/subtest" -) -`, - `package main - -import ( - "fmt" - - "github.com/daixiang0/gci" - "github.com/daixiang0/gci/subtest" - - testing "github.com/daixiang0/test" - g "github.com/golang" -) -`, - }, - { - "no-trailing-newline", - - `sections: - - Standard -`, - `package main - -import ( - "net" - "fmt" -)`, - `package main - -import ( - "fmt" - "net" -) -`, - }, -} diff --git a/vendor/github.com/daixiang0/gci/pkg/io/file.go b/vendor/github.com/daixiang0/gci/pkg/io/file.go deleted file mode 100644 index 79950792c..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/io/file.go +++ /dev/null @@ -1,64 +0,0 @@ -package io - -import "io/ioutil" - -// FileObj allows mocking the access to files -type FileObj interface { - Load() ([]byte, error) - Path() string -} - -// File represents a file that can be loaded from the file system -type File struct { - FilePath string -} - -func (f File) Path() string { - return f.FilePath -} - -func (f File) Load() ([]byte, error) { - return ioutil.ReadFile(f.FilePath) -} - -// FileGeneratorFunc returns a list of files that can be loaded and processed -type FileGeneratorFunc func() ([]FileObj, error) - -func (a FileGeneratorFunc) Combine(b FileGeneratorFunc) FileGeneratorFunc { - return func() ([]FileObj, error) { - files, err := a() - if err != nil { - return nil, err - } - additionalFiles, err := b() - if err != nil { - return nil, err - } - files = append(files, additionalFiles...) - return files, err - } -} - -func GoFilesInPathsGenerator(paths []string, skipVendor bool) FileGeneratorFunc { - checkFunc := isGoFile - if skipVendor { - checkFunc = checkChains(isGoFile, isOutsideVendorDir) - } - - return FilesInPathsGenerator(paths, checkFunc) -} - -func FilesInPathsGenerator(paths []string, fileCheckFun fileCheckFunction) FileGeneratorFunc { - return func() (foundFiles []FileObj, err error) { - for _, path := range paths { - files, err := FindFilesForPath(path, fileCheckFun) - if err != nil { - return nil, err - } - for _, filePath := range files { - foundFiles = append(foundFiles, File{filePath}) - } - } - return foundFiles, nil - } -} diff --git a/vendor/github.com/daixiang0/gci/pkg/io/search.go b/vendor/github.com/daixiang0/gci/pkg/io/search.go deleted file mode 100644 index cd821582e..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/io/search.go +++ /dev/null @@ -1,77 +0,0 @@ -package io - -import ( - "io/fs" - "os" - "path/filepath" -) - -type fileCheckFunction func(path string, file os.FileInfo) bool - -func FindFilesForPath(path string, fileCheckFun fileCheckFunction) ([]string, error) { - switch entry, err := os.Stat(path); { - case err != nil: - return nil, err - case entry.IsDir(): - return findFilesForDirectory(path, fileCheckFun) - case fileCheckFun(path, entry): - return []string{filepath.Clean(path)}, nil - default: - return []string{}, nil - } -} - -func findFilesForDirectory(dirPath string, fileCheckFun fileCheckFunction) ([]string, error) { - var filePaths []string - err := filepath.WalkDir(dirPath, func(path string, entry fs.DirEntry, err error) error { - if err != nil { - return err - } - file, err := entry.Info() - if err != nil { - return err - } - if !entry.IsDir() && fileCheckFun(path, file) { - filePaths = append(filePaths, filepath.Clean(path)) - } - return nil - }) - if err != nil { - return nil, err - } - return filePaths, nil -} - -func isGoFile(_ string, file os.FileInfo) bool { - return !file.IsDir() && filepath.Ext(file.Name()) == ".go" -} - -func isOutsideVendorDir(path string, _ os.FileInfo) bool { - for { - base := filepath.Base(path) - if base == "vendor" { - return false - } - - prevPath := path - path = filepath.Dir(path) - - if prevPath == path { - break - } - } - - return true -} - -func checkChains(funcs ...fileCheckFunction) fileCheckFunction { - return func(path string, file os.FileInfo) bool { - for _, checkFunc := range funcs { - if !checkFunc(path, file) { - return false - } - } - - return true - } -} diff --git a/vendor/github.com/daixiang0/gci/pkg/io/stdin.go b/vendor/github.com/daixiang0/gci/pkg/io/stdin.go deleted file mode 100644 index ccab2844f..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/io/stdin.go +++ /dev/null @@ -1,27 +0,0 @@ -package io - -import ( - "io/ioutil" - "os" -) - -type stdInFile struct{} - -func (s stdInFile) Load() ([]byte, error) { - return ioutil.ReadAll(os.Stdin) -} - -func (s stdInFile) Path() string { - return "StdIn" -} - -var StdInGenerator FileGeneratorFunc = func() ([]FileObj, error) { - stat, err := os.Stdin.Stat() - if err != nil { - return nil, err - } - if (stat.Mode() & os.ModeCharDevice) == 0 { - return []FileObj{stdInFile{}}, nil - } - return []FileObj{}, nil -} diff --git a/vendor/github.com/daixiang0/gci/pkg/log/log.go b/vendor/github.com/daixiang0/gci/pkg/log/log.go deleted file mode 100644 index ab33739ca..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/log/log.go +++ /dev/null @@ -1,50 +0,0 @@ -package log - -import ( - "sync" - - "go.uber.org/zap" - "go.uber.org/zap/zapcore" -) - -// Use L to log with Zap -var logger *zap.Logger - -// Keep the config to reference the atomicLevel for changing levels -var logConfig zap.Config - -var doOnce sync.Once - -// InitLogger sets up the logger -func InitLogger() { - doOnce.Do(func() { - logConfig = zap.NewDevelopmentConfig() - - logConfig.EncoderConfig.TimeKey = "timestamp" - logConfig.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder - logConfig.Level.SetLevel(zapcore.InfoLevel) - logConfig.OutputPaths = []string{"stderr"} - - var err error - logger, err = logConfig.Build() - if err != nil { - panic(err) - } - }) -} - -// SetLevel allows you to set the level of the default gci logger. -// This will not work if you replace the logger -func SetLevel(level zapcore.Level) { - logConfig.Level.SetLevel(level) -} - -// L returns the logger -func L() *zap.Logger { - return logger -} - -// SetLogger allows you to set the logger to whatever you want -func SetLogger(l *zap.Logger) { - logger = l -} diff --git a/vendor/github.com/daixiang0/gci/pkg/parse/parse.go b/vendor/github.com/daixiang0/gci/pkg/parse/parse.go deleted file mode 100644 index e8532f850..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/parse/parse.go +++ /dev/null @@ -1,200 +0,0 @@ -package parse - -import ( - "go/ast" - "go/parser" - "go/token" - "sort" - "strings" -) - -const C = "\"C\"" - -type GciImports struct { - // original index of import group, include doc, name, path and comment - Start, End int - Name, Path string -} -type ImportList []*GciImports - -func (l ImportList) Len() int { - return len(l) -} - -func (l ImportList) Less(i, j int) bool { - if strings.Compare(l[i].Path, l[j].Path) == 0 { - return strings.Compare(l[i].Name, l[j].Name) < 0 - } - - return strings.Compare(l[i].Path, l[j].Path) < 0 -} - -func (l ImportList) Swap(i, j int) { l[i], l[j] = l[j], l[i] } - -/* - * AST considers a import block as below: - * ``` - * Doc - * Name Path Comment - * ``` - * An example is like below: - * ``` - * // test - * test "fmt" // test - * ``` - * getImports return a import block with name, start and end index - */ -func getImports(imp *ast.ImportSpec) (start, end int, name string) { - if imp.Doc != nil { - // doc poc need minus one to get the first index of comment - start = int(imp.Doc.Pos()) - 1 - } else { - if imp.Name != nil { - // name pos need minus one too - start = int(imp.Name.Pos()) - 1 - } else { - // path pos start without quote, need minus one for it - start = int(imp.Path.Pos()) - 1 - } - } - - if imp.Name != nil { - name = imp.Name.Name - } - - if imp.Comment != nil { - end = int(imp.Comment.End()) - } else { - end = int(imp.Path.End()) - } - return -} - -func ParseFile(src []byte, filename string) (ImportList, int, int, int, int, error) { - fileSet := token.NewFileSet() - f, err := parser.ParseFile(fileSet, filename, src, parser.ParseComments) - if err != nil { - return nil, 0, 0, 0, 0, err - } - - if len(f.Imports) == 0 { - return nil, 0, 0, 0, 0, NoImportError{} - } - - var ( - // headEnd means the start of import block - headEnd int - // tailStart means the end + 1 of import block - tailStart int - // cStart means the start of C import block - cStart int - // cEnd means the end of C import block - cEnd int - data ImportList - ) - - for index, decl := range f.Decls { - switch decl.(type) { - // skip BadDecl and FuncDecl - case *ast.GenDecl: - genDecl := decl.(*ast.GenDecl) - - if genDecl.Tok == token.IMPORT { - // there are two cases, both end with linebreak: - // 1. - // import ( - // "xxxx" - // ) - // 2. - // import "xxx" - if headEnd == 0 { - headEnd = int(decl.Pos()) - 1 - } - tailStart = int(decl.End()) - if tailStart > len(src) { - tailStart = len(src) - } - - for _, spec := range genDecl.Specs { - imp := spec.(*ast.ImportSpec) - // there are only one C import block - // ensure C import block is the first import block - if imp.Path.Value == C { - /* - common case: - - // #include <png.h> - import "C" - - notice that decl.Pos() == genDecl.Pos() > genDecl.Doc.Pos() - */ - if genDecl.Doc != nil { - cStart = int(genDecl.Doc.Pos()) - 1 - // if C import block is the first, update headEnd - if index == 0 { - headEnd = cStart - } - } else { - /* - special case: - - import "C" - */ - cStart = int(decl.Pos()) - 1 - } - - cEnd = int(decl.End()) - - continue - } - - start, end, name := getImports(imp) - - data = append(data, &GciImports{ - Start: start, - End: end, - Name: name, - Path: strings.Trim(imp.Path.Value, `"`), - }) - } - } - } - } - - sort.Sort(data) - return data, headEnd, tailStart, cStart, cEnd, nil -} - -// IsGeneratedFileByComment reports whether the source file is generated code. -// Using a bit laxer rules than https://golang.org/s/generatedcode to -// match more generated code. -// Taken from https://github.com/golangci/golangci-lint. -func IsGeneratedFileByComment(in string) bool { - const ( - genCodeGenerated = "code generated" - genDoNotEdit = "do not edit" - genAutoFile = "autogenerated file" // easyjson - genAutoGenerated = "automatically generated" // genny - ) - - markers := []string{genCodeGenerated, genDoNotEdit, genAutoFile, genAutoGenerated} - in = strings.ToLower(in) - for _, marker := range markers { - if strings.Contains(in, marker) { - return true - } - } - - return false -} - -type NoImportError struct{} - -func (n NoImportError) Error() string { - return "No imports" -} - -func (i NoImportError) Is(err error) bool { - _, ok := err.(NoImportError) - return ok -} diff --git a/vendor/github.com/daixiang0/gci/pkg/section/alias.go b/vendor/github.com/daixiang0/gci/pkg/section/alias.go deleted file mode 100644 index 423e96acf..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/section/alias.go +++ /dev/null @@ -1,25 +0,0 @@ -package section - -import ( - "github.com/daixiang0/gci/pkg/parse" - "github.com/daixiang0/gci/pkg/specificity" -) - -type Alias struct{} - -const AliasType = "alias" - -func (b Alias) MatchSpecificity(spec *parse.GciImports) specificity.MatchSpecificity { - if spec.Name != "." && spec.Name != "_" && spec.Name != "" { - return specificity.NameMatch{} - } - return specificity.MisMatch{} -} - -func (b Alias) String() string { - return AliasType -} - -func (b Alias) Type() string { - return AliasType -} diff --git a/vendor/github.com/daixiang0/gci/pkg/section/blank.go b/vendor/github.com/daixiang0/gci/pkg/section/blank.go deleted file mode 100644 index 4a2741773..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/section/blank.go +++ /dev/null @@ -1,25 +0,0 @@ -package section - -import ( - "github.com/daixiang0/gci/pkg/parse" - "github.com/daixiang0/gci/pkg/specificity" -) - -type Blank struct{} - -const BlankType = "blank" - -func (b Blank) MatchSpecificity(spec *parse.GciImports) specificity.MatchSpecificity { - if spec.Name == "_" { - return specificity.NameMatch{} - } - return specificity.MisMatch{} -} - -func (b Blank) String() string { - return BlankType -} - -func (b Blank) Type() string { - return BlankType -} diff --git a/vendor/github.com/daixiang0/gci/pkg/section/commentline.go b/vendor/github.com/daixiang0/gci/pkg/section/commentline.go deleted file mode 100644 index c3ddd0824..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/section/commentline.go +++ /dev/null @@ -1,24 +0,0 @@ -package section - -import ( - "fmt" - - "github.com/daixiang0/gci/pkg/parse" - "github.com/daixiang0/gci/pkg/specificity" -) - -type CommentLine struct { - Comment string -} - -func (c CommentLine) MatchSpecificity(spec *parse.GciImports) specificity.MatchSpecificity { - return specificity.MisMatch{} -} - -func (c CommentLine) String() string { - return fmt.Sprintf("commentline(%s)", c.Comment) -} - -func (c CommentLine) Type() string { - return "commentline" -} diff --git a/vendor/github.com/daixiang0/gci/pkg/section/default.go b/vendor/github.com/daixiang0/gci/pkg/section/default.go deleted file mode 100644 index 3af07a092..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/section/default.go +++ /dev/null @@ -1,22 +0,0 @@ -package section - -import ( - "github.com/daixiang0/gci/pkg/parse" - "github.com/daixiang0/gci/pkg/specificity" -) - -const DefaultType = "default" - -type Default struct{} - -func (d Default) MatchSpecificity(spec *parse.GciImports) specificity.MatchSpecificity { - return specificity.Default{} -} - -func (d Default) String() string { - return DefaultType -} - -func (d Default) Type() string { - return DefaultType -} diff --git a/vendor/github.com/daixiang0/gci/pkg/section/dot.go b/vendor/github.com/daixiang0/gci/pkg/section/dot.go deleted file mode 100644 index 8112eeb1d..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/section/dot.go +++ /dev/null @@ -1,25 +0,0 @@ -package section - -import ( - "github.com/daixiang0/gci/pkg/parse" - "github.com/daixiang0/gci/pkg/specificity" -) - -type Dot struct{} - -const DotType = "dot" - -func (d Dot) MatchSpecificity(spec *parse.GciImports) specificity.MatchSpecificity { - if spec.Name == "." { - return specificity.NameMatch{} - } - return specificity.MisMatch{} -} - -func (d Dot) String() string { - return DotType -} - -func (d Dot) Type() string { - return DotType -} diff --git a/vendor/github.com/daixiang0/gci/pkg/section/errors.go b/vendor/github.com/daixiang0/gci/pkg/section/errors.go deleted file mode 100644 index 0a1209135..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/section/errors.go +++ /dev/null @@ -1,107 +0,0 @@ -package section - -import ( - "errors" - "fmt" - - "github.com/daixiang0/gci/pkg/parse" - "github.com/daixiang0/gci/pkg/utils" -) - -type SectionParsingError struct { - error -} - -func (s SectionParsingError) Unwrap() error { - return s.error -} - -func (s SectionParsingError) Wrap(sectionStr string) error { - return fmt.Errorf("failed to parse section %q: %w", sectionStr, s) -} - -func (s SectionParsingError) Is(err error) bool { - _, ok := err.(SectionParsingError) - return ok -} - -var MissingParameterClosingBracketsError = fmt.Errorf("section parameter is missing closing %q", utils.RightParenthesis) - -var MoreThanOneOpeningQuotesError = fmt.Errorf("found more than one %q parameter start sequences", utils.RightParenthesis) - -var SectionTypeDoesNotAcceptParametersError = errors.New("section type does not accept a parameter") - -var SectionTypeDoesNotAcceptPrefixError = errors.New("section may not contain a Prefix") - -var SectionTypeDoesNotAcceptSuffixError = errors.New("section may not contain a Suffix") - -type EqualSpecificityMatchError struct { - Imports *parse.GciImports - SectionA, SectionB Section -} - -func (e EqualSpecificityMatchError) Error() string { - return fmt.Sprintf("Import %v matched section %s and %s equally", e.Imports, e.SectionA, e.SectionB) -} - -func (e EqualSpecificityMatchError) Is(err error) bool { - _, ok := err.(EqualSpecificityMatchError) - return ok -} - -type NoMatchingSectionForImportError struct { - Imports *parse.GciImports -} - -func (n NoMatchingSectionForImportError) Error() string { - return fmt.Sprintf("No section found for Import: %v", n.Imports) -} - -func (n NoMatchingSectionForImportError) Is(err error) bool { - _, ok := err.(NoMatchingSectionForImportError) - return ok -} - -type InvalidImportSplitError struct { - segments []string -} - -func (i InvalidImportSplitError) Error() string { - return fmt.Sprintf("separating the inline comment from the import yielded an invalid number of segments: %v", i.segments) -} - -func (i InvalidImportSplitError) Is(err error) bool { - _, ok := err.(InvalidImportSplitError) - return ok -} - -type InvalidAliasSplitError struct { - segments []string -} - -func (i InvalidAliasSplitError) Error() string { - return fmt.Sprintf("separating the alias from the path yielded an invalid number of segments: %v", i.segments) -} - -func (i InvalidAliasSplitError) Is(err error) bool { - _, ok := err.(InvalidAliasSplitError) - return ok -} - -var ( - MissingImportStatementError = FileParsingError{errors.New("no import statement present in File")} - ImportStatementNotClosedError = FileParsingError{errors.New("import statement not closed")} -) - -type FileParsingError struct { - error -} - -func (f FileParsingError) Unwrap() error { - return f.error -} - -func (f FileParsingError) Is(err error) bool { - _, ok := err.(FileParsingError) - return ok -} diff --git a/vendor/github.com/daixiang0/gci/pkg/section/local_module.go b/vendor/github.com/daixiang0/gci/pkg/section/local_module.go deleted file mode 100644 index 50f41e501..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/section/local_module.go +++ /dev/null @@ -1,59 +0,0 @@ -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/newline.go b/vendor/github.com/daixiang0/gci/pkg/section/newline.go deleted file mode 100644 index 4bff91b9d..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/section/newline.go +++ /dev/null @@ -1,22 +0,0 @@ -package section - -import ( - "github.com/daixiang0/gci/pkg/parse" - "github.com/daixiang0/gci/pkg/specificity" -) - -const newLineName = "newline" - -type NewLine struct{} - -func (n NewLine) MatchSpecificity(spec *parse.GciImports) specificity.MatchSpecificity { - return specificity.MisMatch{} -} - -func (n NewLine) String() string { - return newLineName -} - -func (n NewLine) Type() string { - return newLineName -} diff --git a/vendor/github.com/daixiang0/gci/pkg/section/parser.go b/vendor/github.com/daixiang0/gci/pkg/section/parser.go deleted file mode 100644 index 62ed1582a..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/section/parser.go +++ /dev/null @@ -1,49 +0,0 @@ -package section - -import ( - "errors" - "fmt" - "strings" -) - -func Parse(data []string) (SectionList, error) { - if len(data) == 0 { - return nil, nil - } - - var list SectionList - var errString string - for _, d := range data { - s := strings.ToLower(d) - if len(s) == 0 { - return nil, nil - } - - if s == "default" { - list = append(list, Default{}) - } else if s == "standard" { - list = append(list, Standard{}) - } else if s == "newline" { - list = append(list, NewLine{}) - } else if strings.HasPrefix(s, "prefix(") && len(d) > 8 { - list = append(list, Custom{d[7 : len(d)-1]}) - } else if strings.HasPrefix(s, "commentline(") && len(d) > 13 { - list = append(list, Custom{d[12 : len(d)-1]}) - } else if s == "dot" { - list = append(list, Dot{}) - } else if s == "blank" { - 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) - } - } - if errString != "" { - return nil, errors.New(fmt.Sprintf("invalid params:%s", errString)) - } - return list, nil -} diff --git a/vendor/github.com/daixiang0/gci/pkg/section/prefix.go b/vendor/github.com/daixiang0/gci/pkg/section/prefix.go deleted file mode 100644 index 30bdd8f4e..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/section/prefix.go +++ /dev/null @@ -1,38 +0,0 @@ -package section - -import ( - "fmt" - "strings" - - "github.com/daixiang0/gci/pkg/parse" - "github.com/daixiang0/gci/pkg/specificity" -) - -type Custom struct { - Prefix string -} - -// CustomSeparator allows you to group multiple custom prefix together in the same section -// gci diff -s standard -s default -s prefix(github.com/company,gitlab.com/company,companysuffix) -const CustomSeparator = "," - -const CustomType = "custom" - -func (c Custom) MatchSpecificity(spec *parse.GciImports) specificity.MatchSpecificity { - for _, prefix := range strings.Split(c.Prefix, CustomSeparator) { - prefix = strings.TrimSpace(prefix) - if strings.HasPrefix(spec.Path, prefix) { - return specificity.Match{Length: len(prefix)} - } - } - - return specificity.MisMatch{} -} - -func (c Custom) String() string { - return fmt.Sprintf("prefix(%s)", c.Prefix) -} - -func (c Custom) Type() string { - return CustomType -} diff --git a/vendor/github.com/daixiang0/gci/pkg/section/section.go b/vendor/github.com/daixiang0/gci/pkg/section/section.go deleted file mode 100644 index cc0a43f2f..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/section/section.go +++ /dev/null @@ -1,36 +0,0 @@ -package section - -import ( - "github.com/daixiang0/gci/pkg/parse" - "github.com/daixiang0/gci/pkg/specificity" -) - -// Section defines a part of the formatted output. -type Section interface { - // MatchSpecificity returns how well an Import matches to this Section - MatchSpecificity(spec *parse.GciImports) specificity.MatchSpecificity - - // String Implements the stringer interface - String() string - - // return section type - Type() string -} - -type SectionList []Section - -func (list SectionList) String() []string { - var output []string - for _, section := range list { - output = append(output, section.String()) - } - return output -} - -func DefaultSections() SectionList { - return SectionList{Standard{}, Default{}} -} - -func DefaultSectionSeparators() SectionList { - return SectionList{NewLine{}} -} diff --git a/vendor/github.com/daixiang0/gci/pkg/section/standard.go b/vendor/github.com/daixiang0/gci/pkg/section/standard.go deleted file mode 100644 index 26c7e9dc7..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/section/standard.go +++ /dev/null @@ -1,30 +0,0 @@ -package section - -import ( - "github.com/daixiang0/gci/pkg/parse" - "github.com/daixiang0/gci/pkg/specificity" -) - -const StandardType = "standard" - -type Standard struct{} - -func (s Standard) MatchSpecificity(spec *parse.GciImports) specificity.MatchSpecificity { - if isStandard(spec.Path) { - return specificity.StandardMatch{} - } - return specificity.MisMatch{} -} - -func (s Standard) String() string { - return StandardType -} - -func (s Standard) Type() string { - return StandardType -} - -func isStandard(pkg string) bool { - _, ok := standardPackages[pkg] - return ok -} diff --git a/vendor/github.com/daixiang0/gci/pkg/section/standard_list.go b/vendor/github.com/daixiang0/gci/pkg/section/standard_list.go deleted file mode 100644 index 5a2dcdc89..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/section/standard_list.go +++ /dev/null @@ -1,175 +0,0 @@ -package section - -// Code generated based on go1.23.0 X:boringcrypto,arenas. DO NOT EDIT. - -var standardPackages = map[string]struct{}{ - "archive/tar": {}, - "archive/zip": {}, - "arena": {}, - "bufio": {}, - "bytes": {}, - "cmp": {}, - "compress/bzip2": {}, - "compress/flate": {}, - "compress/gzip": {}, - "compress/lzw": {}, - "compress/zlib": {}, - "container/heap": {}, - "container/list": {}, - "container/ring": {}, - "context": {}, - "crypto": {}, - "crypto/aes": {}, - "crypto/boring": {}, - "crypto/cipher": {}, - "crypto/des": {}, - "crypto/dsa": {}, - "crypto/ecdh": {}, - "crypto/ecdsa": {}, - "crypto/ed25519": {}, - "crypto/elliptic": {}, - "crypto/hmac": {}, - "crypto/md5": {}, - "crypto/rand": {}, - "crypto/rc4": {}, - "crypto/rsa": {}, - "crypto/sha1": {}, - "crypto/sha256": {}, - "crypto/sha512": {}, - "crypto/subtle": {}, - "crypto/tls": {}, - "crypto/tls/fipsonly": {}, - "crypto/x509": {}, - "crypto/x509/pkix": {}, - "database/sql": {}, - "database/sql/driver": {}, - "debug/buildinfo": {}, - "debug/dwarf": {}, - "debug/elf": {}, - "debug/gosym": {}, - "debug/macho": {}, - "debug/pe": {}, - "debug/plan9obj": {}, - "embed": {}, - "encoding": {}, - "encoding/ascii85": {}, - "encoding/asn1": {}, - "encoding/base32": {}, - "encoding/base64": {}, - "encoding/binary": {}, - "encoding/csv": {}, - "encoding/gob": {}, - "encoding/hex": {}, - "encoding/json": {}, - "encoding/pem": {}, - "encoding/xml": {}, - "errors": {}, - "expvar": {}, - "flag": {}, - "fmt": {}, - "go/ast": {}, - "go/build": {}, - "go/build/constraint": {}, - "go/constant": {}, - "go/doc": {}, - "go/doc/comment": {}, - "go/format": {}, - "go/importer": {}, - "go/parser": {}, - "go/printer": {}, - "go/scanner": {}, - "go/token": {}, - "go/types": {}, - "go/version": {}, - "hash": {}, - "hash/adler32": {}, - "hash/crc32": {}, - "hash/crc64": {}, - "hash/fnv": {}, - "hash/maphash": {}, - "html": {}, - "html/template": {}, - "image": {}, - "image/color": {}, - "image/color/palette": {}, - "image/draw": {}, - "image/gif": {}, - "image/jpeg": {}, - "image/png": {}, - "index/suffixarray": {}, - "io": {}, - "io/fs": {}, - "io/ioutil": {}, - "iter": {}, - "log": {}, - "log/slog": {}, - "log/syslog": {}, - "maps": {}, - "math": {}, - "math/big": {}, - "math/bits": {}, - "math/cmplx": {}, - "math/rand": {}, - "math/rand/v2": {}, - "mime": {}, - "mime/multipart": {}, - "mime/quotedprintable": {}, - "net": {}, - "net/http": {}, - "net/http/cgi": {}, - "net/http/cookiejar": {}, - "net/http/fcgi": {}, - "net/http/httptest": {}, - "net/http/httptrace": {}, - "net/http/httputil": {}, - "net/http/pprof": {}, - "net/mail": {}, - "net/netip": {}, - "net/rpc": {}, - "net/rpc/jsonrpc": {}, - "net/smtp": {}, - "net/textproto": {}, - "net/url": {}, - "os": {}, - "os/exec": {}, - "os/signal": {}, - "os/user": {}, - "path": {}, - "path/filepath": {}, - "plugin": {}, - "reflect": {}, - "regexp": {}, - "regexp/syntax": {}, - "runtime": {}, - "runtime/cgo": {}, - "runtime/coverage": {}, - "runtime/debug": {}, - "runtime/metrics": {}, - "runtime/pprof": {}, - "runtime/race": {}, - "runtime/trace": {}, - "slices": {}, - "sort": {}, - "strconv": {}, - "strings": {}, - "structs": {}, - "sync": {}, - "sync/atomic": {}, - "syscall": {}, - "testing": {}, - "testing/fstest": {}, - "testing/iotest": {}, - "testing/quick": {}, - "testing/slogtest": {}, - "text/scanner": {}, - "text/tabwriter": {}, - "text/template": {}, - "text/template/parse": {}, - "time": {}, - "time/tzdata": {}, - "unicode": {}, - "unicode/utf16": {}, - "unicode/utf8": {}, - "unique": {}, - "unsafe": {}, -} diff --git a/vendor/github.com/daixiang0/gci/pkg/specificity/default.go b/vendor/github.com/daixiang0/gci/pkg/specificity/default.go deleted file mode 100644 index f7ae4b87b..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/specificity/default.go +++ /dev/null @@ -1,19 +0,0 @@ -package specificity - -type Default struct{} - -func (d Default) IsMoreSpecific(than MatchSpecificity) bool { - return isMoreSpecific(d, than) -} - -func (d Default) Equal(to MatchSpecificity) bool { - return equalSpecificity(d, to) -} - -func (d Default) class() specificityClass { - return DefaultClass -} - -func (d Default) String() string { - return "Default" -} diff --git a/vendor/github.com/daixiang0/gci/pkg/specificity/local_module.go b/vendor/github.com/daixiang0/gci/pkg/specificity/local_module.go deleted file mode 100644 index ae482fec4..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/specificity/local_module.go +++ /dev/null @@ -1,15 +0,0 @@ -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/match.go b/vendor/github.com/daixiang0/gci/pkg/specificity/match.go deleted file mode 100644 index f08d2b66b..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/specificity/match.go +++ /dev/null @@ -1,24 +0,0 @@ -package specificity - -import "fmt" - -type Match struct { - Length int -} - -func (m Match) IsMoreSpecific(than MatchSpecificity) bool { - otherMatch, isMatch := than.(Match) - return isMoreSpecific(m, than) || (isMatch && m.Length > otherMatch.Length) -} - -func (m Match) Equal(to MatchSpecificity) bool { - return equalSpecificity(m, to) -} - -func (m Match) class() specificityClass { - return MatchClass -} - -func (m Match) String() string { - return fmt.Sprintf("Match(length: %d)", m.Length) -} diff --git a/vendor/github.com/daixiang0/gci/pkg/specificity/mismatch.go b/vendor/github.com/daixiang0/gci/pkg/specificity/mismatch.go deleted file mode 100644 index 8e8711146..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/specificity/mismatch.go +++ /dev/null @@ -1,19 +0,0 @@ -package specificity - -type MisMatch struct{} - -func (m MisMatch) IsMoreSpecific(than MatchSpecificity) bool { - return isMoreSpecific(m, than) -} - -func (m MisMatch) Equal(to MatchSpecificity) bool { - return equalSpecificity(m, to) -} - -func (m MisMatch) class() specificityClass { - return MisMatchClass -} - -func (m MisMatch) String() string { - return "Mismatch" -} diff --git a/vendor/github.com/daixiang0/gci/pkg/specificity/name.go b/vendor/github.com/daixiang0/gci/pkg/specificity/name.go deleted file mode 100644 index 1900a0ac5..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/specificity/name.go +++ /dev/null @@ -1,19 +0,0 @@ -package specificity - -type NameMatch struct{} - -func (n NameMatch) IsMoreSpecific(than MatchSpecificity) bool { - return isMoreSpecific(n, than) -} - -func (n NameMatch) Equal(to MatchSpecificity) bool { - return equalSpecificity(n, to) -} - -func (n NameMatch) class() specificityClass { - return NameClass -} - -func (n NameMatch) String() string { - return "Name" -} diff --git a/vendor/github.com/daixiang0/gci/pkg/specificity/specificity.go b/vendor/github.com/daixiang0/gci/pkg/specificity/specificity.go deleted file mode 100644 index 4a188b3bb..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/specificity/specificity.go +++ /dev/null @@ -1,28 +0,0 @@ -package specificity - -type specificityClass int - -const ( - MisMatchClass = 0 - DefaultClass = 10 - StandardClass = 20 - MatchClass = 30 - NameClass = 40 - LocalModuleClass = 50 -) - -// MatchSpecificity is used to determine which section matches an import best -type MatchSpecificity interface { - IsMoreSpecific(than MatchSpecificity) bool - Equal(to MatchSpecificity) bool - class() specificityClass -} - -func isMoreSpecific(this, than MatchSpecificity) bool { - return this.class() > than.class() -} - -func equalSpecificity(base, to MatchSpecificity) bool { - // m.class() == to.class() would not work for Match - return !base.IsMoreSpecific(to) && !to.IsMoreSpecific(base) -} diff --git a/vendor/github.com/daixiang0/gci/pkg/specificity/standard.go b/vendor/github.com/daixiang0/gci/pkg/specificity/standard.go deleted file mode 100644 index 72ccaf7e1..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/specificity/standard.go +++ /dev/null @@ -1,19 +0,0 @@ -package specificity - -type StandardMatch struct{} - -func (s StandardMatch) IsMoreSpecific(than MatchSpecificity) bool { - return isMoreSpecific(s, than) -} - -func (s StandardMatch) Equal(to MatchSpecificity) bool { - return equalSpecificity(s, to) -} - -func (s StandardMatch) class() specificityClass { - return StandardClass -} - -func (s StandardMatch) String() string { - return "Standard" -} diff --git a/vendor/github.com/daixiang0/gci/pkg/utils/constants.go b/vendor/github.com/daixiang0/gci/pkg/utils/constants.go deleted file mode 100644 index 2fafbc32c..000000000 --- a/vendor/github.com/daixiang0/gci/pkg/utils/constants.go +++ /dev/null @@ -1,12 +0,0 @@ -package utils - -const ( - Indent = '\t' - Linebreak = '\n' - WinLinebreak = '\r' - - Colon = ":" - - LeftParenthesis = '(' - RightParenthesis = ')' -) |
