aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/daixiang0/gci/pkg/section
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2022-09-05 14:27:54 +0200
committerGitHub <noreply@github.com>2022-09-05 12:27:54 +0000
commitb2f2446b46bf02821d90ebedadae2bf7ae0e880e (patch)
tree923cf42842918d6bebca1d6bbdc08abed54d274d /vendor/github.com/daixiang0/gci/pkg/section
parente6654faff4bcca4be92e9a8596fd4b77f747c39e (diff)
go.mod, vendor: update (#3358)
* go.mod, vendor: remove unnecessary dependencies Commands: 1. go mod tidy 2. go mod vendor * go.mod, vendor: update cloud.google.com/go Commands: 1. go get -u cloud.google.com/go 2. go mod tidy 3. go mod vendor * go.mod, vendor: update cloud.google.com/* Commands: 1. go get -u cloud.google.com/storage cloud.google.com/logging 2. go mod tidy 3. go mod vendor * go.mod, .golangci.yml, vendor: update *lint* Commands: 1. go get -u golang.org/x/tools github.com/golangci/golangci-lint@v1.47.0 2. go mod tidy 3. go mod vendor 4. edit .golangci.yml to suppress new errors (resolved in the same PR later) * all: fix lint errors hash.go: copy() recommended by gosimple parse.go: ent is never nil verifier.go: signal.Notify() with unbuffered channel is bad. Have no idea why. * .golangci.yml: adjust godot rules check-all is deprecated, but still work if you're hesitating too - I'll remove this commit
Diffstat (limited to 'vendor/github.com/daixiang0/gci/pkg/section')
-rw-r--r--vendor/github.com/daixiang0/gci/pkg/section/blank.go25
-rw-r--r--vendor/github.com/daixiang0/gci/pkg/section/commentline.go24
-rw-r--r--vendor/github.com/daixiang0/gci/pkg/section/default.go22
-rw-r--r--vendor/github.com/daixiang0/gci/pkg/section/dot.go25
-rw-r--r--vendor/github.com/daixiang0/gci/pkg/section/errors.go107
-rw-r--r--vendor/github.com/daixiang0/gci/pkg/section/newline.go22
-rw-r--r--vendor/github.com/daixiang0/gci/pkg/section/parser.go44
-rw-r--r--vendor/github.com/daixiang0/gci/pkg/section/prefix.go30
-rw-r--r--vendor/github.com/daixiang0/gci/pkg/section/section.go36
-rw-r--r--vendor/github.com/daixiang0/gci/pkg/section/standard.go30
-rw-r--r--vendor/github.com/daixiang0/gci/pkg/section/standard_list.go159
11 files changed, 524 insertions, 0 deletions
diff --git a/vendor/github.com/daixiang0/gci/pkg/section/blank.go b/vendor/github.com/daixiang0/gci/pkg/section/blank.go
new file mode 100644
index 000000000..4a2741773
--- /dev/null
+++ b/vendor/github.com/daixiang0/gci/pkg/section/blank.go
@@ -0,0 +1,25 @@
+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
new file mode 100644
index 000000000..c3ddd0824
--- /dev/null
+++ b/vendor/github.com/daixiang0/gci/pkg/section/commentline.go
@@ -0,0 +1,24 @@
+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
new file mode 100644
index 000000000..3af07a092
--- /dev/null
+++ b/vendor/github.com/daixiang0/gci/pkg/section/default.go
@@ -0,0 +1,22 @@
+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
new file mode 100644
index 000000000..8112eeb1d
--- /dev/null
+++ b/vendor/github.com/daixiang0/gci/pkg/section/dot.go
@@ -0,0 +1,25 @@
+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
new file mode 100644
index 000000000..1aa42ecdf
--- /dev/null
+++ b/vendor/github.com/daixiang0/gci/pkg/section/errors.go
@@ -0,0 +1,107 @@
+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.ParameterClosingBrackets)
+
+var MoreThanOneOpeningQuotesError = fmt.Errorf("found more than one %q parameter start sequences", utils.ParameterClosingBrackets)
+
+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/newline.go b/vendor/github.com/daixiang0/gci/pkg/section/newline.go
new file mode 100644
index 000000000..4bff91b9d
--- /dev/null
+++ b/vendor/github.com/daixiang0/gci/pkg/section/newline.go
@@ -0,0 +1,22 @@
+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
new file mode 100644
index 000000000..9834dcd13
--- /dev/null
+++ b/vendor/github.com/daixiang0/gci/pkg/section/parser.go
@@ -0,0 +1,44 @@
+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 {
+ 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
new file mode 100644
index 000000000..92ef96377
--- /dev/null
+++ b/vendor/github.com/daixiang0/gci/pkg/section/prefix.go
@@ -0,0 +1,30 @@
+package section
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/daixiang0/gci/pkg/parse"
+ "github.com/daixiang0/gci/pkg/specificity"
+)
+
+type Custom struct {
+ Prefix string
+}
+
+const CustomType = "custom"
+
+func (c Custom) MatchSpecificity(spec *parse.GciImports) specificity.MatchSpecificity {
+ if strings.HasPrefix(spec.Path, c.Prefix) {
+ return specificity.Match{Length: len(c.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
new file mode 100644
index 000000000..cc0a43f2f
--- /dev/null
+++ b/vendor/github.com/daixiang0/gci/pkg/section/section.go
@@ -0,0 +1,36 @@
+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
new file mode 100644
index 000000000..26c7e9dc7
--- /dev/null
+++ b/vendor/github.com/daixiang0/gci/pkg/section/standard.go
@@ -0,0 +1,30 @@
+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
new file mode 100644
index 000000000..b5d884d37
--- /dev/null
+++ b/vendor/github.com/daixiang0/gci/pkg/section/standard_list.go
@@ -0,0 +1,159 @@
+package section
+
+// Code generated based on go1.18.4. DO NOT EDIT.
+
+var standardPackages = map[string]struct{}{
+ "archive/tar": {},
+ "archive/zip": {},
+ "bufio": {},
+ "bytes": {},
+ "compress/bzip2": {},
+ "compress/flate": {},
+ "compress/gzip": {},
+ "compress/lzw": {},
+ "compress/zlib": {},
+ "container/heap": {},
+ "container/list": {},
+ "container/ring": {},
+ "context": {},
+ "crypto": {},
+ "crypto/aes": {},
+ "crypto/cipher": {},
+ "crypto/des": {},
+ "crypto/dsa": {},
+ "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/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/format": {},
+ "go/importer": {},
+ "go/parser": {},
+ "go/printer": {},
+ "go/scanner": {},
+ "go/token": {},
+ "go/types": {},
+ "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": {},
+ "log": {},
+ "log/syslog": {},
+ "math": {},
+ "math/big": {},
+ "math/bits": {},
+ "math/cmplx": {},
+ "math/rand": {},
+ "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/debug": {},
+ "runtime/metrics": {},
+ "runtime/pprof": {},
+ "runtime/race": {},
+ "runtime/trace": {},
+ "sort": {},
+ "strconv": {},
+ "strings": {},
+ "sync": {},
+ "sync/atomic": {},
+ "syscall": {},
+ "testing": {},
+ "testing/fstest": {},
+ "testing/iotest": {},
+ "testing/quick": {},
+ "text/scanner": {},
+ "text/tabwriter": {},
+ "text/template": {},
+ "text/template/parse": {},
+ "time": {},
+ "time/tzdata": {},
+ "unicode": {},
+ "unicode/utf16": {},
+ "unicode/utf8": {},
+ "unsafe": {},
+}