aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ldez/gomoddirectives
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/ldez/gomoddirectives
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/ldez/gomoddirectives')
-rw-r--r--vendor/github.com/ldez/gomoddirectives/.gitignore2
-rw-r--r--vendor/github.com/ldez/gomoddirectives/.golangci.yml88
-rw-r--r--vendor/github.com/ldez/gomoddirectives/LICENSE190
-rw-r--r--vendor/github.com/ldez/gomoddirectives/Makefile15
-rw-r--r--vendor/github.com/ldez/gomoddirectives/go.mod8
-rw-r--r--vendor/github.com/ldez/gomoddirectives/go.sum25
-rw-r--r--vendor/github.com/ldez/gomoddirectives/gomoddirectives.go125
-rw-r--r--vendor/github.com/ldez/gomoddirectives/module.go48
-rw-r--r--vendor/github.com/ldez/gomoddirectives/readme.md16
9 files changed, 517 insertions, 0 deletions
diff --git a/vendor/github.com/ldez/gomoddirectives/.gitignore b/vendor/github.com/ldez/gomoddirectives/.gitignore
new file mode 100644
index 000000000..9da3e0da9
--- /dev/null
+++ b/vendor/github.com/ldez/gomoddirectives/.gitignore
@@ -0,0 +1,2 @@
+.idea/
+/gomoddirectives
diff --git a/vendor/github.com/ldez/gomoddirectives/.golangci.yml b/vendor/github.com/ldez/gomoddirectives/.golangci.yml
new file mode 100644
index 000000000..a2483e95f
--- /dev/null
+++ b/vendor/github.com/ldez/gomoddirectives/.golangci.yml
@@ -0,0 +1,88 @@
+run:
+ deadline: 2m
+ skip-files: []
+ skip-dirs: []
+
+linters-settings:
+ govet:
+ enable-all: true
+ gocyclo:
+ min-complexity: 12
+ goconst:
+ min-len: 3
+ min-occurrences: 3
+ misspell:
+ locale: US
+ gofumpt:
+ extra-rules: true
+ depguard:
+ list-type: blacklist
+ include-go-root: false
+ packages:
+ - github.com/pkg/errors
+ godox:
+ keywords:
+ - FIXME
+ gocritic:
+ enabled-tags:
+ - diagnostic
+ - style
+ - performance
+ disabled-checks:
+ - sloppyReassign
+ - rangeValCopy
+ - octalLiteral
+ - paramTypeCombine # already handle by gofumpt.extra-rules
+ settings:
+ hugeParam:
+ sizeThreshold: 100
+ forbidigo:
+ forbid:
+ - '^print(ln)?$'
+ - '^fmt\.Print(f|ln)?$'
+ - '^panic$'
+ - '^spew\.Print(f|ln)?$'
+ - '^spew\.Dump$'
+ tagliatelle:
+ case:
+ rules:
+ json: pascal
+
+linters:
+ enable-all: true
+ disable:
+ - maligned # deprecated
+ - interfacer # deprecated
+ - golint # deprecated
+ - scopelint # deprecated
+ - sqlclosecheck # not relevant (SQL)
+ - rowserrcheck # not relevant (SQL)
+ - cyclop # duplicate of gocyclo
+ - lll
+ - dupl
+ - prealloc
+ - bodyclose
+ - wsl
+ - nlreturn
+ - gomnd
+ - testpackage
+ - paralleltest
+ - tparallel
+ - goerr113
+ - wrapcheck
+ - exhaustive
+ - exhaustivestruct
+ - varnamelen
+
+issues:
+ exclude-use-default: false
+ max-per-linter: 0
+ max-same-issues: 0
+ exclude: []
+ exclude-rules:
+ - path: "(.+)_test.go"
+ linters:
+ - funlen
+ - goconst
+ - path: cmd/gomoddirectives/gomoddirectives.go
+ text: 'use of `fmt.Println` forbidden'
diff --git a/vendor/github.com/ldez/gomoddirectives/LICENSE b/vendor/github.com/ldez/gomoddirectives/LICENSE
new file mode 100644
index 000000000..caed523b4
--- /dev/null
+++ b/vendor/github.com/ldez/gomoddirectives/LICENSE
@@ -0,0 +1,190 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ Copyright 2021 Fernandez Ludovic
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/vendor/github.com/ldez/gomoddirectives/Makefile b/vendor/github.com/ldez/gomoddirectives/Makefile
new file mode 100644
index 000000000..dd3b335c7
--- /dev/null
+++ b/vendor/github.com/ldez/gomoddirectives/Makefile
@@ -0,0 +1,15 @@
+.PHONY: clean check test build
+
+default: clean check test build
+
+clean:
+ rm -rf dist/ cover.out
+
+test: clean
+ go test -v -cover ./...
+
+check:
+ golangci-lint run
+
+build:
+ go build -v -ldflags "-s -w" -trimpath ./cmd/gomoddirectives/
diff --git a/vendor/github.com/ldez/gomoddirectives/go.mod b/vendor/github.com/ldez/gomoddirectives/go.mod
new file mode 100644
index 000000000..fb65d2ddc
--- /dev/null
+++ b/vendor/github.com/ldez/gomoddirectives/go.mod
@@ -0,0 +1,8 @@
+module github.com/ldez/gomoddirectives
+
+go 1.16
+
+require (
+ github.com/stretchr/testify v1.7.0
+ golang.org/x/mod v0.4.2
+)
diff --git a/vendor/github.com/ldez/gomoddirectives/go.sum b/vendor/github.com/ldez/gomoddirectives/go.sum
new file mode 100644
index 000000000..4e4ac3ecc
--- /dev/null
+++ b/vendor/github.com/ldez/gomoddirectives/go.sum
@@ -0,0 +1,25 @@
+github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
+github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
+golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
+golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/vendor/github.com/ldez/gomoddirectives/gomoddirectives.go b/vendor/github.com/ldez/gomoddirectives/gomoddirectives.go
new file mode 100644
index 000000000..2a4c90474
--- /dev/null
+++ b/vendor/github.com/ldez/gomoddirectives/gomoddirectives.go
@@ -0,0 +1,125 @@
+// Package gomoddirectives a linter that handle `replace`, `retract`, `exclude` directives into `go.mod`.
+package gomoddirectives
+
+import (
+ "fmt"
+ "go/token"
+ "strings"
+
+ "golang.org/x/mod/modfile"
+)
+
+const (
+ reasonRetract = "a comment is mandatory to explain why the version has been retracted"
+ reasonExclude = "exclude directive is not allowed"
+ reasonReplaceLocal = "local replacement are not allowed"
+ reasonReplace = "replacement are not allowed"
+ reasonReplaceIdentical = "the original module and the replacement are identical"
+ reasonReplaceDuplicate = "multiple replacement of the same module"
+)
+
+// Result the analysis result.
+type Result struct {
+ Reason string
+ Start token.Position
+ End token.Position
+}
+
+// NewResult creates a new Result.
+func NewResult(file *modfile.File, line *modfile.Line, reason string) Result {
+ return Result{
+ Start: token.Position{Filename: file.Syntax.Name, Line: line.Start.Line, Column: line.Start.LineRune},
+ End: token.Position{Filename: file.Syntax.Name, Line: line.End.Line, Column: line.End.LineRune},
+ Reason: reason,
+ }
+}
+
+func (r Result) String() string {
+ return fmt.Sprintf("%s: %s", r.Start, r.Reason)
+}
+
+// Options the analyzer options.
+type Options struct {
+ ReplaceAllowList []string
+ ReplaceAllowLocal bool
+ ExcludeForbidden bool
+ RetractAllowNoExplanation bool
+}
+
+// Analyze analyzes a project.
+func Analyze(opts Options) ([]Result, error) {
+ f, err := GetModuleFile()
+ if err != nil {
+ return nil, fmt.Errorf("failed to get module file: %w", err)
+ }
+
+ return AnalyzeFile(f, opts), nil
+}
+
+// AnalyzeFile analyzes a mod file.
+func AnalyzeFile(file *modfile.File, opts Options) []Result {
+ var results []Result
+
+ if !opts.RetractAllowNoExplanation {
+ for _, r := range file.Retract {
+ if r.Rationale != "" {
+ continue
+ }
+
+ results = append(results, NewResult(file, r.Syntax, reasonRetract))
+ }
+ }
+
+ if opts.ExcludeForbidden {
+ for _, e := range file.Exclude {
+ results = append(results, NewResult(file, e.Syntax, reasonExclude))
+ }
+ }
+
+ uniqReplace := map[string]struct{}{}
+
+ for _, r := range file.Replace {
+ reason := check(opts, r)
+ if reason != "" {
+ results = append(results, NewResult(file, r.Syntax, reason))
+ continue
+ }
+
+ if r.Old.Path == r.New.Path && r.Old.Version == r.New.Version {
+ results = append(results, NewResult(file, r.Syntax, reasonReplaceIdentical))
+ continue
+ }
+
+ if _, ok := uniqReplace[r.Old.Path+r.Old.Version]; ok {
+ results = append(results, NewResult(file, r.Syntax, reasonReplaceDuplicate))
+ }
+
+ uniqReplace[r.Old.Path+r.Old.Version] = struct{}{}
+ }
+
+ return results
+}
+
+func check(o Options, r *modfile.Replace) string {
+ if isLocal(r) {
+ if o.ReplaceAllowLocal {
+ return ""
+ }
+
+ return fmt.Sprintf("%s: %s", reasonReplaceLocal, r.Old.Path)
+ }
+
+ for _, v := range o.ReplaceAllowList {
+ if r.Old.Path == v {
+ return ""
+ }
+ }
+
+ return fmt.Sprintf("%s: %s", reasonReplace, r.Old.Path)
+}
+
+// Filesystem paths found in "replace" directives are represented by a path with an empty version.
+// https://github.com/golang/mod/blob/bc388b264a244501debfb9caea700c6dcaff10e2/module/module.go#L122-L124
+func isLocal(r *modfile.Replace) bool {
+ return strings.TrimSpace(r.New.Version) == ""
+}
diff --git a/vendor/github.com/ldez/gomoddirectives/module.go b/vendor/github.com/ldez/gomoddirectives/module.go
new file mode 100644
index 000000000..907be244f
--- /dev/null
+++ b/vendor/github.com/ldez/gomoddirectives/module.go
@@ -0,0 +1,48 @@
+package gomoddirectives
+
+import (
+ "bytes"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "os"
+ "os/exec"
+
+ "golang.org/x/mod/modfile"
+)
+
+type modInfo struct {
+ Path string `json:"Path"`
+ Dir string `json:"Dir"`
+ GoMod string `json:"GoMod"`
+ GoVersion string `json:"GoVersion"`
+ Main bool `json:"Main"`
+}
+
+// GetModuleFile gets module file.
+func GetModuleFile() (*modfile.File, error) {
+ // https://github.com/golang/go/issues/44753#issuecomment-790089020
+ cmd := exec.Command("go", "list", "-m", "-json")
+
+ raw, err := cmd.CombinedOutput()
+ if err != nil {
+ return nil, fmt.Errorf("command go list: %w: %s", err, string(raw))
+ }
+
+ var v modInfo
+ err = json.NewDecoder(bytes.NewBuffer(raw)).Decode(&v)
+ if err != nil {
+ return nil, fmt.Errorf("unmarshaling error: %w: %s", err, string(raw))
+ }
+
+ if v.GoMod == "" {
+ return nil, errors.New("working directory is not part of a module")
+ }
+
+ raw, err = os.ReadFile(v.GoMod)
+ if err != nil {
+ return nil, fmt.Errorf("reading go.mod file: %w", err)
+ }
+
+ return modfile.Parse("go.mod", raw, nil)
+}
diff --git a/vendor/github.com/ldez/gomoddirectives/readme.md b/vendor/github.com/ldez/gomoddirectives/readme.md
new file mode 100644
index 000000000..510c8502e
--- /dev/null
+++ b/vendor/github.com/ldez/gomoddirectives/readme.md
@@ -0,0 +1,16 @@
+# gomoddirectives
+
+[![Sponsor](https://img.shields.io/badge/Sponsor%20me-%E2%9D%A4%EF%B8%8F-pink)](https://github.com/sponsors/ldez)
+[![Build Status](https://github.com/ldez/gomoddirectives/workflows/Main/badge.svg?branch=master)](https://github.com/ldez/gomoddirectives/actions)
+
+A linter that handle [`replace`](https://golang.org/ref/mod#go-mod-file-replace), [`retract`](https://golang.org/ref/mod#go-mod-file-retract), [`exclude`](https://golang.org/ref/mod#go-mod-file-exclude) directives into `go.mod`.
+
+Features:
+
+- ban all [`replace`](https://golang.org/ref/mod#go-mod-file-replace) directives
+- allow only local [`replace`](https://golang.org/ref/mod#go-mod-file-replace) directives
+- allow only some [`replace`](https://golang.org/ref/mod#go-mod-file-replace) directives
+- force explanation for [`retract`](https://golang.org/ref/mod#go-mod-file-retract) directives
+- ban all [`exclude`](https://golang.org/ref/mod#go-mod-file-exclude) directives
+- detect duplicated [`replace`](https://golang.org/ref/mod#go-mod-file-replace) directives
+- detect identical [`replace`](https://golang.org/ref/mod#go-mod-file-replace) directives