aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/sashamelentyev
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2023-02-22 22:16:50 +0100
committerTaras Madan <tarasmadan@google.com>2023-02-24 12:47:23 +0100
commit4165372ec8fd142475a4e35fd0cf4f8042132208 (patch)
tree21cd62211b4dd80bee469054c5b65db77342333c /vendor/github.com/sashamelentyev
parent2b3ed821a493b8936c8bacfa6f8b4f1c90a00855 (diff)
dependencies: update
set go min requirements to 1.19 update dependencies update vendor
Diffstat (limited to 'vendor/github.com/sashamelentyev')
-rw-r--r--vendor/github.com/sashamelentyev/interfacebloat/LICENSE21
-rw-r--r--vendor/github.com/sashamelentyev/interfacebloat/pkg/analyzer/analyzer.go57
-rw-r--r--vendor/github.com/sashamelentyev/usestdlibvars/LICENSE21
-rw-r--r--vendor/github.com/sashamelentyev/usestdlibvars/pkg/analyzer/analyzer.go569
-rw-r--r--vendor/github.com/sashamelentyev/usestdlibvars/pkg/analyzer/internal/mapping/mapping.go199
5 files changed, 867 insertions, 0 deletions
diff --git a/vendor/github.com/sashamelentyev/interfacebloat/LICENSE b/vendor/github.com/sashamelentyev/interfacebloat/LICENSE
new file mode 100644
index 000000000..a52602b3d
--- /dev/null
+++ b/vendor/github.com/sashamelentyev/interfacebloat/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2022 Sasha Melentyev
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/vendor/github.com/sashamelentyev/interfacebloat/pkg/analyzer/analyzer.go b/vendor/github.com/sashamelentyev/interfacebloat/pkg/analyzer/analyzer.go
new file mode 100644
index 000000000..4a6afdf8c
--- /dev/null
+++ b/vendor/github.com/sashamelentyev/interfacebloat/pkg/analyzer/analyzer.go
@@ -0,0 +1,57 @@
+package analyzer
+
+import (
+ "flag"
+ "go/ast"
+
+ "golang.org/x/tools/go/analysis"
+ "golang.org/x/tools/go/analysis/passes/inspect"
+ "golang.org/x/tools/go/ast/inspector"
+)
+
+const InterfaceMaxMethodsFlag = "max"
+
+const defaultMaxMethods = 10
+
+// New returns new interfacebloat analyzer.
+func New() *analysis.Analyzer {
+ return &analysis.Analyzer{
+ Name: "interfacebloat",
+ Doc: "A linter that checks the number of methods inside an interface.",
+ Run: run,
+ Flags: flags(),
+ Requires: []*analysis.Analyzer{inspect.Analyzer},
+ }
+}
+
+func flags() flag.FlagSet {
+ flags := flag.NewFlagSet("", flag.ExitOnError)
+ flags.Int(InterfaceMaxMethodsFlag, 10, "maximum number of methods")
+ return *flags
+}
+
+func run(pass *analysis.Pass) (interface{}, error) {
+ maxMethods, ok := pass.Analyzer.Flags.Lookup(InterfaceMaxMethodsFlag).Value.(flag.Getter).Get().(int)
+ if !ok {
+ maxMethods = defaultMaxMethods
+ }
+
+ insp := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
+
+ filter := []ast.Node{
+ (*ast.InterfaceType)(nil),
+ }
+
+ insp.Preorder(filter, func(node ast.Node) {
+ i, ok := node.(*ast.InterfaceType)
+ if !ok {
+ return
+ }
+
+ if len(i.Methods.List) > maxMethods {
+ pass.Reportf(node.Pos(), `the interface has more than %d methods: %d`, maxMethods, len(i.Methods.List))
+ }
+ })
+
+ return nil, nil
+}
diff --git a/vendor/github.com/sashamelentyev/usestdlibvars/LICENSE b/vendor/github.com/sashamelentyev/usestdlibvars/LICENSE
new file mode 100644
index 000000000..a52602b3d
--- /dev/null
+++ b/vendor/github.com/sashamelentyev/usestdlibvars/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2022 Sasha Melentyev
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/vendor/github.com/sashamelentyev/usestdlibvars/pkg/analyzer/analyzer.go b/vendor/github.com/sashamelentyev/usestdlibvars/pkg/analyzer/analyzer.go
new file mode 100644
index 000000000..4d6ab3cca
--- /dev/null
+++ b/vendor/github.com/sashamelentyev/usestdlibvars/pkg/analyzer/analyzer.go
@@ -0,0 +1,569 @@
+package analyzer
+
+import (
+ "flag"
+ "go/ast"
+ "go/token"
+ "strings"
+
+ "golang.org/x/tools/go/analysis"
+ "golang.org/x/tools/go/analysis/passes/inspect"
+ "golang.org/x/tools/go/ast/inspector"
+
+ "github.com/sashamelentyev/usestdlibvars/pkg/analyzer/internal/mapping"
+)
+
+const (
+ TimeWeekdayFlag = "time-weekday"
+ TimeMonthFlag = "time-month"
+ TimeLayoutFlag = "time-layout"
+ CryptoHashFlag = "crypto-hash"
+ HTTPMethodFlag = "http-method"
+ HTTPStatusCodeFlag = "http-status-code"
+ RPCDefaultPathFlag = "rpc-default-path"
+ OSDevNullFlag = "os-dev-null"
+ SQLIsolationLevelFlag = "sql-isolation-level"
+ TLSSignatureSchemeFlag = "tls-signature-scheme"
+ ConstantKindFlag = "constant-kind"
+ SyslogPriorityFlag = "syslog-priority"
+)
+
+// New returns new usestdlibvars analyzer.
+func New() *analysis.Analyzer {
+ return &analysis.Analyzer{
+ Name: "usestdlibvars",
+ Doc: "A linter that detect the possibility to use variables/constants from the Go standard library.",
+ Run: run,
+ Flags: flags(),
+ Requires: []*analysis.Analyzer{inspect.Analyzer},
+ }
+}
+
+func flags() flag.FlagSet {
+ flags := flag.NewFlagSet("", flag.ExitOnError)
+ flags.Bool(HTTPMethodFlag, true, "suggest the use of http.MethodXX")
+ flags.Bool(HTTPStatusCodeFlag, true, "suggest the use of http.StatusXX")
+ flags.Bool(TimeWeekdayFlag, false, "suggest the use of time.Weekday.String()")
+ flags.Bool(TimeMonthFlag, false, "suggest the use of time.Month.String()")
+ flags.Bool(TimeLayoutFlag, false, "suggest the use of time.Layout")
+ flags.Bool(CryptoHashFlag, false, "suggest the use of crypto.Hash.String()")
+ flags.Bool(RPCDefaultPathFlag, false, "suggest the use of rpc.DefaultXXPath")
+ flags.Bool(OSDevNullFlag, false, "[DEPRECATED] suggest the use of os.DevNull")
+ flags.Bool(SQLIsolationLevelFlag, false, "suggest the use of sql.LevelXX.String()")
+ flags.Bool(TLSSignatureSchemeFlag, false, "suggest the use of tls.SignatureScheme.String()")
+ flags.Bool(ConstantKindFlag, false, "suggest the use of constant.Kind.String()")
+ flags.Bool(SyslogPriorityFlag, false, "[DEPRECATED] suggest the use of syslog.Priority")
+ return *flags
+}
+
+func run(pass *analysis.Pass) (interface{}, error) {
+ insp := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
+
+ types := []ast.Node{
+ (*ast.CallExpr)(nil),
+ (*ast.BasicLit)(nil),
+ (*ast.CompositeLit)(nil),
+ (*ast.IfStmt)(nil),
+ (*ast.SwitchStmt)(nil),
+ (*ast.ForStmt)(nil),
+ }
+
+ insp.Preorder(types, func(node ast.Node) {
+ switch n := node.(type) {
+ case *ast.CallExpr:
+ fun, ok := n.Fun.(*ast.SelectorExpr)
+ if !ok {
+ return
+ }
+
+ x, ok := fun.X.(*ast.Ident)
+ if !ok {
+ return
+ }
+
+ funArgs(pass, x, fun, n.Args)
+
+ case *ast.BasicLit:
+ for _, c := range []struct {
+ flag string
+ checkFunc func(pass *analysis.Pass, basicLit *ast.BasicLit)
+ }{
+ {flag: TimeWeekdayFlag, checkFunc: checkTimeWeekday},
+ {flag: TimeMonthFlag, checkFunc: checkTimeMonth},
+ {flag: TimeLayoutFlag, checkFunc: checkTimeLayout},
+ {flag: CryptoHashFlag, checkFunc: checkCryptoHash},
+ {flag: RPCDefaultPathFlag, checkFunc: checkRPCDefaultPath},
+ {flag: OSDevNullFlag, checkFunc: checkOSDevNull},
+ {flag: SQLIsolationLevelFlag, checkFunc: checkSQLIsolationLevel},
+ {flag: TLSSignatureSchemeFlag, checkFunc: checkTLSSignatureScheme},
+ {flag: ConstantKindFlag, checkFunc: checkConstantKind},
+ } {
+ if lookupFlag(pass, c.flag) {
+ c.checkFunc(pass, n)
+ }
+ }
+
+ case *ast.CompositeLit:
+ typ, ok := n.Type.(*ast.SelectorExpr)
+ if !ok {
+ return
+ }
+
+ x, ok := typ.X.(*ast.Ident)
+ if !ok {
+ return
+ }
+
+ typeElts(pass, x, typ, n.Elts)
+
+ case *ast.IfStmt:
+ cond, ok := n.Cond.(*ast.BinaryExpr)
+ if !ok {
+ return
+ }
+
+ switch cond.Op {
+ case token.LSS, token.GTR, token.LEQ, token.GEQ:
+ return
+ }
+
+ x, ok := cond.X.(*ast.SelectorExpr)
+ if !ok {
+ return
+ }
+
+ y, ok := cond.Y.(*ast.BasicLit)
+ if !ok {
+ return
+ }
+
+ ifElseStmt(pass, x, y)
+
+ case *ast.SwitchStmt:
+ x, ok := n.Tag.(*ast.SelectorExpr)
+ if ok {
+ switchStmt(pass, x, n.Body.List)
+ } else {
+ switchStmtAsIfElseStmt(pass, n.Body.List)
+ }
+
+ case *ast.ForStmt:
+ cond, ok := n.Cond.(*ast.BinaryExpr)
+ if !ok {
+ return
+ }
+
+ x, ok := cond.X.(*ast.SelectorExpr)
+ if !ok {
+ return
+ }
+
+ y, ok := cond.Y.(*ast.BasicLit)
+ if !ok {
+ return
+ }
+
+ ifElseStmt(pass, x, y)
+ }
+ })
+
+ return nil, nil
+}
+
+// funArgs checks arguments of function or method.
+func funArgs(pass *analysis.Pass, x *ast.Ident, fun *ast.SelectorExpr, args []ast.Expr) {
+ switch x.Name {
+ case "http":
+ switch fun.Sel.Name {
+ // http.NewRequest(http.MethodGet, "localhost", http.NoBody)
+ case "NewRequest":
+ if !lookupFlag(pass, HTTPMethodFlag) {
+ return
+ }
+
+ if basicLit := getBasicLitFromArgs(args, 3, 0, token.STRING); basicLit != nil {
+ checkHTTPMethod(pass, basicLit)
+ }
+
+ // http.NewRequestWithContext(context.Background(), http.MethodGet, "localhost", http.NoBody)
+ case "NewRequestWithContext":
+ if !lookupFlag(pass, HTTPMethodFlag) {
+ return
+ }
+
+ if basicLit := getBasicLitFromArgs(args, 4, 1, token.STRING); basicLit != nil {
+ checkHTTPMethod(pass, basicLit)
+ }
+
+ // http.Error(w, err, http.StatusInternalServerError)
+ case "Error":
+ if !lookupFlag(pass, HTTPStatusCodeFlag) {
+ return
+ }
+
+ if basicLit := getBasicLitFromArgs(args, 3, 2, token.INT); basicLit != nil {
+ checkHTTPStatusCode(pass, basicLit)
+ }
+
+ // http.StatusText(http.StatusOK)
+ case "StatusText":
+ if !lookupFlag(pass, HTTPStatusCodeFlag) {
+ return
+ }
+
+ if basicLit := getBasicLitFromArgs(args, 1, 0, token.INT); basicLit != nil {
+ checkHTTPStatusCode(pass, basicLit)
+ }
+
+ // http.Redirect(w, r, "localhost", http.StatusMovedPermanently)
+ case "Redirect":
+ if !lookupFlag(pass, HTTPStatusCodeFlag) {
+ return
+ }
+
+ if basicLit := getBasicLitFromArgs(args, 4, 3, token.INT); basicLit != nil {
+ checkHTTPStatusCode(pass, basicLit)
+ }
+
+ // http.RedirectHandler("localhost", http.StatusMovedPermanently)
+ case "RedirectHandler":
+ if !lookupFlag(pass, HTTPStatusCodeFlag) {
+ return
+ }
+
+ if basicLit := getBasicLitFromArgs(args, 2, 1, token.INT); basicLit != nil {
+ checkHTTPStatusCode(pass, basicLit)
+ }
+ }
+ case "httptest":
+ if fun.Sel.Name == "NewRequest" {
+ if !lookupFlag(pass, HTTPMethodFlag) {
+ return
+ }
+
+ if basicLit := getBasicLitFromArgs(args, 3, 0, token.STRING); basicLit != nil {
+ checkHTTPMethod(pass, basicLit)
+ }
+ }
+ case "syslog":
+ if !lookupFlag(pass, SyslogPriorityFlag) {
+ return
+ }
+
+ switch fun.Sel.Name {
+ case "New":
+ if basicLit := getBasicLitFromArgs(args, 2, 0, token.INT); basicLit != nil {
+ checkSyslogPriority(pass, basicLit)
+ }
+
+ case "Dial":
+ if basicLit := getBasicLitFromArgs(args, 4, 2, token.INT); basicLit != nil {
+ checkSyslogPriority(pass, basicLit)
+ }
+
+ case "NewLogger":
+ if basicLit := getBasicLitFromArgs(args, 2, 0, token.INT); basicLit != nil {
+ checkSyslogPriority(pass, basicLit)
+ }
+ }
+ default:
+ // w.WriteHeader(http.StatusOk)
+ if fun.Sel.Name == "WriteHeader" {
+ if !lookupFlag(pass, HTTPStatusCodeFlag) {
+ return
+ }
+
+ if basicLit := getBasicLitFromArgs(args, 1, 0, token.INT); basicLit != nil {
+ checkHTTPStatusCode(pass, basicLit)
+ }
+ }
+ }
+}
+
+// typeElts checks elements of type.
+func typeElts(pass *analysis.Pass, x *ast.Ident, typ *ast.SelectorExpr, elts []ast.Expr) {
+ switch x.Name {
+ case "http":
+ switch typ.Sel.Name {
+ // http.Request{Method: http.MethodGet}
+ case "Request":
+ if !lookupFlag(pass, HTTPMethodFlag) {
+ return
+ }
+
+ if basicLit := getBasicLitFromElts(elts, "Method"); basicLit != nil {
+ checkHTTPMethod(pass, basicLit)
+ }
+
+ // http.Response{StatusCode: http.StatusOK}
+ case "Response":
+ if !lookupFlag(pass, HTTPStatusCodeFlag) {
+ return
+ }
+
+ if basicLit := getBasicLitFromElts(elts, "StatusCode"); basicLit != nil {
+ checkHTTPStatusCode(pass, basicLit)
+ }
+ }
+ case "httptest":
+ if typ.Sel.Name == "ResponseRecorder" {
+ if !lookupFlag(pass, HTTPStatusCodeFlag) {
+ return
+ }
+
+ if basicLit := getBasicLitFromElts(elts, "Code"); basicLit != nil {
+ checkHTTPStatusCode(pass, basicLit)
+ }
+ }
+ }
+}
+
+// ifElseStmt checks X and Y in if-else-statement.
+func ifElseStmt(pass *analysis.Pass, x *ast.SelectorExpr, y *ast.BasicLit) {
+ switch x.Sel.Name {
+ case "StatusCode":
+ if !lookupFlag(pass, HTTPStatusCodeFlag) {
+ return
+ }
+
+ checkHTTPStatusCode(pass, y)
+
+ case "Method":
+ if !lookupFlag(pass, HTTPMethodFlag) {
+ return
+ }
+
+ checkHTTPMethod(pass, y)
+ }
+}
+
+func switchStmt(pass *analysis.Pass, x *ast.SelectorExpr, cases []ast.Stmt) {
+ var checkFunc func(pass *analysis.Pass, basicLit *ast.BasicLit)
+
+ switch x.Sel.Name {
+ case "StatusCode":
+ if !lookupFlag(pass, HTTPStatusCodeFlag) {
+ return
+ }
+
+ checkFunc = checkHTTPStatusCode
+
+ case "Method":
+ if !lookupFlag(pass, HTTPMethodFlag) {
+ return
+ }
+
+ checkFunc = checkHTTPMethod
+
+ default:
+ return
+ }
+
+ for _, c := range cases {
+ caseClause, ok := c.(*ast.CaseClause)
+ if !ok {
+ continue
+ }
+
+ for _, expr := range caseClause.List {
+ basicLit, ok := expr.(*ast.BasicLit)
+ if !ok {
+ continue
+ }
+
+ checkFunc(pass, basicLit)
+ }
+ }
+}
+
+func switchStmtAsIfElseStmt(pass *analysis.Pass, cases []ast.Stmt) {
+ for _, c := range cases {
+ caseClause, ok := c.(*ast.CaseClause)
+ if !ok {
+ continue
+ }
+
+ for _, expr := range caseClause.List {
+ binaryExpr, ok := expr.(*ast.BinaryExpr)
+ if !ok {
+ continue
+ }
+
+ x, ok := binaryExpr.X.(*ast.SelectorExpr)
+ if !ok {
+ continue
+ }
+
+ y, ok := binaryExpr.Y.(*ast.BasicLit)
+ if !ok {
+ continue
+ }
+
+ ifElseStmt(pass, x, y)
+ }
+ }
+}
+
+func lookupFlag(pass *analysis.Pass, name string) bool {
+ return pass.Analyzer.Flags.Lookup(name).Value.(flag.Getter).Get().(bool)
+}
+
+func checkHTTPMethod(pass *analysis.Pass, basicLit *ast.BasicLit) {
+ currentVal := getBasicLitValue(basicLit)
+
+ key := strings.ToUpper(currentVal)
+
+ if newVal, ok := mapping.HTTPMethod[key]; ok {
+ report(pass, basicLit.Pos(), currentVal, newVal)
+ }
+}
+
+func checkHTTPStatusCode(pass *analysis.Pass, basicLit *ast.BasicLit) {
+ currentVal := getBasicLitValue(basicLit)
+
+ if newVal, ok := mapping.HTTPStatusCode[currentVal]; ok {
+ report(pass, basicLit.Pos(), currentVal, newVal)
+ }
+}
+
+func checkTimeWeekday(pass *analysis.Pass, basicLit *ast.BasicLit) {
+ currentVal := getBasicLitValue(basicLit)
+
+ if newVal, ok := mapping.TimeWeekday[currentVal]; ok {
+ report(pass, basicLit.Pos(), currentVal, newVal)
+ }
+}
+
+func checkTimeMonth(pass *analysis.Pass, basicLit *ast.BasicLit) {
+ currentVal := getBasicLitValue(basicLit)
+
+ if newVal, ok := mapping.TimeMonth[currentVal]; ok {
+ report(pass, basicLit.Pos(), currentVal, newVal)
+ }
+}
+
+func checkTimeLayout(pass *analysis.Pass, basicLit *ast.BasicLit) {
+ currentVal := getBasicLitValue(basicLit)
+
+ if newVal, ok := mapping.TimeLayout[currentVal]; ok {
+ report(pass, basicLit.Pos(), currentVal, newVal)
+ }
+}
+
+func checkCryptoHash(pass *analysis.Pass, basicLit *ast.BasicLit) {
+ currentVal := getBasicLitValue(basicLit)
+
+ if newVal, ok := mapping.CryptoHash[currentVal]; ok {
+ report(pass, basicLit.Pos(), currentVal, newVal)
+ }
+}
+
+func checkRPCDefaultPath(pass *analysis.Pass, basicLit *ast.BasicLit) {
+ currentVal := getBasicLitValue(basicLit)
+
+ if newVal, ok := mapping.RPCDefaultPath[currentVal]; ok {
+ report(pass, basicLit.Pos(), currentVal, newVal)
+ }
+}
+
+func checkOSDevNull(pass *analysis.Pass, basicLit *ast.BasicLit) {}
+
+func checkSQLIsolationLevel(pass *analysis.Pass, basicLit *ast.BasicLit) {
+ currentVal := getBasicLitValue(basicLit)
+
+ if newVal, ok := mapping.SQLIsolationLevel[currentVal]; ok {
+ report(pass, basicLit.Pos(), currentVal, newVal)
+ }
+}
+
+func checkTLSSignatureScheme(pass *analysis.Pass, basicLit *ast.BasicLit) {
+ currentVal := getBasicLitValue(basicLit)
+
+ if newVal, ok := mapping.TLSSignatureScheme[currentVal]; ok {
+ report(pass, basicLit.Pos(), currentVal, newVal)
+ }
+}
+
+func checkConstantKind(pass *analysis.Pass, basicLit *ast.BasicLit) {
+ currentVal := getBasicLitValue(basicLit)
+
+ if newVal, ok := mapping.ConstantKind[currentVal]; ok {
+ report(pass, basicLit.Pos(), currentVal, newVal)
+ }
+}
+
+func checkSyslogPriority(pass *analysis.Pass, basicLit *ast.BasicLit) {}
+
+// getBasicLitFromArgs gets the *ast.BasicLit of a function argument.
+//
+// Arguments:
+// - args - slice of function arguments
+// - count - expected number of argument in function
+// - idx - index of the argument to get the *ast.BasicLit
+// - typ - argument type
+func getBasicLitFromArgs(args []ast.Expr, count, idx int, typ token.Token) *ast.BasicLit {
+ if len(args) != count {
+ return nil
+ }
+
+ if idx > count-1 {
+ return nil
+ }
+
+ basicLit, ok := args[idx].(*ast.BasicLit)
+ if !ok {
+ return nil
+ }
+
+ if basicLit.Kind != typ {
+ return nil
+ }
+
+ return basicLit
+}
+
+// getBasicLitFromElts gets the *ast.BasicLit of a struct elements.
+//
+// Arguments:
+// - elts - slice of a struct elements
+// - key - name of key in struct
+func getBasicLitFromElts(elts []ast.Expr, key string) *ast.BasicLit {
+ for _, e := range elts {
+ keyValueExpr, ok := e.(*ast.KeyValueExpr)
+ if !ok {
+ continue
+ }
+
+ ident, ok := keyValueExpr.Key.(*ast.Ident)
+ if !ok {
+ continue
+ }
+
+ if ident.Name != key {
+ continue
+ }
+
+ if basicLit, ok := keyValueExpr.Value.(*ast.BasicLit); ok {
+ return basicLit
+ }
+ }
+
+ return nil
+}
+
+// getBasicLitValue returns BasicLit value as string without quotes.
+func getBasicLitValue(basicLit *ast.BasicLit) string {
+ var val strings.Builder
+ for _, r := range basicLit.Value {
+ if r == '"' {
+ continue
+ } else {
+ val.WriteRune(r)
+ }
+ }
+ return val.String()
+}
+
+func report(pass *analysis.Pass, pos token.Pos, currentVal, newVal string) {
+ pass.Reportf(pos, "%q can be replaced by %s", currentVal, newVal)
+}
diff --git a/vendor/github.com/sashamelentyev/usestdlibvars/pkg/analyzer/internal/mapping/mapping.go b/vendor/github.com/sashamelentyev/usestdlibvars/pkg/analyzer/internal/mapping/mapping.go
new file mode 100644
index 000000000..b081edea3
--- /dev/null
+++ b/vendor/github.com/sashamelentyev/usestdlibvars/pkg/analyzer/internal/mapping/mapping.go
@@ -0,0 +1,199 @@
+package mapping
+
+import (
+ "crypto"
+ "crypto/tls"
+ "database/sql"
+ "go/constant"
+ "net/http"
+ "net/rpc"
+ "strconv"
+ "time"
+)
+
+var CryptoHash = map[string]string{
+ crypto.MD4.String(): "crypto.MD4.String()",
+ crypto.MD5.String(): "crypto.MD5.String()",
+ crypto.SHA1.String(): "crypto.SHA1.String()",
+ crypto.SHA224.String(): "crypto.SHA224.String()",
+ crypto.SHA256.String(): "crypto.SHA256.String()",
+ crypto.SHA384.String(): "crypto.SHA384.String()",
+ crypto.SHA512.String(): "crypto.SHA512.String()",
+ crypto.MD5SHA1.String(): "crypto.MD5SHA1.String()",
+ crypto.RIPEMD160.String(): "crypto.RIPEMD160.String()",
+ crypto.SHA3_224.String(): "crypto.SHA3_224.String()",
+ crypto.SHA3_256.String(): "crypto.SHA3_256.String()",
+ crypto.SHA3_384.String(): "crypto.SHA3_384.String()",
+ crypto.SHA3_512.String(): "crypto.SHA3_512.String()",
+ crypto.SHA512_224.String(): "crypto.SHA512_224.String()",
+ crypto.SHA512_256.String(): "crypto.SHA512_256.String()",
+ crypto.BLAKE2s_256.String(): "crypto.BLAKE2s_256.String()",
+ crypto.BLAKE2b_256.String(): "crypto.BLAKE2b_256.String()",
+ crypto.BLAKE2b_384.String(): "crypto.BLAKE2b_384.String()",
+ crypto.BLAKE2b_512.String(): "crypto.BLAKE2b_512.String()",
+}
+
+var HTTPMethod = map[string]string{
+ http.MethodGet: "http.MethodGet",
+ http.MethodHead: "http.MethodHead",
+ http.MethodPost: "http.MethodPost",
+ http.MethodPut: "http.MethodPut",
+ http.MethodPatch: "http.MethodPatch",
+ http.MethodDelete: "http.MethodDelete",
+ http.MethodConnect: "http.MethodConnect",
+ http.MethodOptions: "http.MethodOptions",
+ http.MethodTrace: "http.MethodTrace",
+}
+
+var HTTPStatusCode = map[string]string{
+ strconv.Itoa(http.StatusContinue): "http.StatusContinue",
+ strconv.Itoa(http.StatusSwitchingProtocols): "http.StatusSwitchingProtocols",
+ strconv.Itoa(http.StatusProcessing): "http.StatusProcessing",
+ strconv.Itoa(http.StatusEarlyHints): "http.StatusEarlyHints",
+
+ strconv.Itoa(http.StatusOK): "http.StatusOK",
+ strconv.Itoa(http.StatusCreated): "http.StatusCreated",
+ strconv.Itoa(http.StatusAccepted): "http.StatusAccepted",
+ strconv.Itoa(http.StatusNonAuthoritativeInfo): "http.StatusNonAuthoritativeInfo",
+ strconv.Itoa(http.StatusNoContent): "http.StatusNoContent",
+ strconv.Itoa(http.StatusResetContent): "http.StatusResetContent",
+ strconv.Itoa(http.StatusPartialContent): "http.StatusPartialContent",
+ strconv.Itoa(http.StatusMultiStatus): "http.StatusMultiStatus",
+ strconv.Itoa(http.StatusAlreadyReported): "http.StatusAlreadyReported",
+ strconv.Itoa(http.StatusIMUsed): "http.StatusIMUsed",
+
+ strconv.Itoa(http.StatusMultipleChoices): "http.StatusMultipleChoices",
+ strconv.Itoa(http.StatusMovedPermanently): "http.StatusMovedPermanently",
+ strconv.Itoa(http.StatusFound): "http.StatusFound",
+ strconv.Itoa(http.StatusSeeOther): "http.StatusSeeOther",
+ strconv.Itoa(http.StatusNotModified): "http.StatusNotModified",
+ strconv.Itoa(http.StatusUseProxy): "http.StatusUseProxy",
+ strconv.Itoa(http.StatusTemporaryRedirect): "http.StatusTemporaryRedirect",
+ strconv.Itoa(http.StatusPermanentRedirect): "http.StatusPermanentRedirect",
+
+ strconv.Itoa(http.StatusBadRequest): "http.StatusBadRequest",
+ strconv.Itoa(http.StatusUnauthorized): "http.StatusUnauthorized",
+ strconv.Itoa(http.StatusPaymentRequired): "http.StatusPaymentRequired",
+ strconv.Itoa(http.StatusForbidden): "http.StatusForbidden",
+ strconv.Itoa(http.StatusNotFound): "http.StatusNotFound",
+ strconv.Itoa(http.StatusMethodNotAllowed): "http.StatusMethodNotAllowed",
+ strconv.Itoa(http.StatusNotAcceptable): "http.StatusNotAcceptable",
+ strconv.Itoa(http.StatusProxyAuthRequired): "http.StatusProxyAuthRequired",
+ strconv.Itoa(http.StatusRequestTimeout): "http.StatusRequestTimeout",
+ strconv.Itoa(http.StatusConflict): "http.StatusConflict",
+ strconv.Itoa(http.StatusGone): "http.StatusGone",
+ strconv.Itoa(http.StatusLengthRequired): "http.StatusLengthRequired",
+ strconv.Itoa(http.StatusPreconditionFailed): "http.StatusPreconditionFailed",
+ strconv.Itoa(http.StatusRequestEntityTooLarge): "http.StatusRequestEntityTooLarge",
+ strconv.Itoa(http.StatusRequestURITooLong): "http.StatusRequestURITooLong",
+ strconv.Itoa(http.StatusUnsupportedMediaType): "http.StatusUnsupportedMediaType",
+ strconv.Itoa(http.StatusRequestedRangeNotSatisfiable): "http.StatusRequestedRangeNotSatisfiable",
+ strconv.Itoa(http.StatusExpectationFailed): "http.StatusExpectationFailed",
+ strconv.Itoa(http.StatusTeapot): "http.StatusTeapot",
+ strconv.Itoa(http.StatusMisdirectedRequest): "http.StatusMisdirectedRequest",
+ strconv.Itoa(http.StatusUnprocessableEntity): "http.StatusUnprocessableEntity",
+ strconv.Itoa(http.StatusLocked): "http.StatusLocked",
+ strconv.Itoa(http.StatusFailedDependency): "http.StatusFailedDependency",
+ strconv.Itoa(http.StatusTooEarly): "http.StatusTooEarly",
+ strconv.Itoa(http.StatusUpgradeRequired): "http.StatusUpgradeRequired",
+ strconv.Itoa(http.StatusPreconditionRequired): "http.StatusPreconditionRequired",
+ strconv.Itoa(http.StatusTooManyRequests): "http.StatusTooManyRequests",
+ strconv.Itoa(http.StatusRequestHeaderFieldsTooLarge): "http.StatusRequestHeaderFieldsTooLarge",
+ strconv.Itoa(http.StatusUnavailableForLegalReasons): "http.StatusUnavailableForLegalReasons",
+
+ strconv.Itoa(http.StatusInternalServerError): "http.StatusInternalServerError",
+ strconv.Itoa(http.StatusNotImplemented): "http.StatusNotImplemented",
+ strconv.Itoa(http.StatusBadGateway): "http.StatusBadGateway",
+ strconv.Itoa(http.StatusServiceUnavailable): "http.StatusServiceUnavailable",
+ strconv.Itoa(http.StatusGatewayTimeout): "http.StatusGatewayTimeout",
+ strconv.Itoa(http.StatusHTTPVersionNotSupported): "http.StatusHTTPVersionNotSupported",
+ strconv.Itoa(http.StatusVariantAlsoNegotiates): "http.StatusVariantAlsoNegotiates",
+ strconv.Itoa(http.StatusInsufficientStorage): "http.StatusInsufficientStorage",
+ strconv.Itoa(http.StatusLoopDetected): "http.StatusLoopDetected",
+ strconv.Itoa(http.StatusNotExtended): "http.StatusNotExtended",
+ strconv.Itoa(http.StatusNetworkAuthenticationRequired): "http.StatusNetworkAuthenticationRequired",
+}
+
+var RPCDefaultPath = map[string]string{
+ rpc.DefaultRPCPath: "rpc.DefaultRPCPath",
+ rpc.DefaultDebugPath: "rpc.DefaultDebugPath",
+}
+
+var TimeWeekday = map[string]string{
+ time.Sunday.String(): "time.Sunday.String()",
+ time.Monday.String(): "time.Monday.String()",
+ time.Tuesday.String(): "time.Tuesday.String()",
+ time.Wednesday.String(): "time.Wednesday.String()",
+ time.Thursday.String(): "time.Thursday.String()",
+ time.Friday.String(): "time.Friday.String()",
+ time.Saturday.String(): "time.Saturday.String()",
+}
+
+var TimeMonth = map[string]string{
+ time.January.String(): "time.January.String()",
+ time.February.String(): "time.February.String()",
+ time.March.String(): "time.March.String()",
+ time.April.String(): "time.April.String()",
+ time.May.String(): "time.May.String()",
+ time.June.String(): "time.June.String()",
+ time.July.String(): "time.July.String()",
+ time.August.String(): "time.August.String()",
+ time.September.String(): "time.September.String()",
+ time.October.String(): "time.October.String()",
+ time.November.String(): "time.November.String()",
+ time.December.String(): "time.December.String()",
+}
+
+var TimeLayout = map[string]string{
+ time.Layout: "time.Layout",
+ time.ANSIC: "time.ANSIC",
+ time.UnixDate: "time.UnixDate",
+ time.RubyDate: "time.RubyDate",
+ time.RFC822: "time.RFC822",
+ time.RFC822Z: "time.RFC822Z",
+ time.RFC850: "time.RFC850",
+ time.RFC1123: "time.RFC1123",
+ time.RFC1123Z: "time.RFC1123Z",
+ time.RFC3339: "time.RFC3339",
+ time.RFC3339Nano: "time.RFC3339Nano",
+ time.Kitchen: "time.Kitchen",
+ time.Stamp: "time.Stamp",
+ time.StampMilli: "time.StampMilli",
+ time.StampMicro: "time.StampMicro",
+ time.StampNano: "time.StampNano",
+}
+
+var SQLIsolationLevel = map[string]string{
+ // sql.LevelDefault.String(): "sql.LevelDefault.String()",
+ sql.LevelReadUncommitted.String(): "sql.LevelReadUncommitted.String()",
+ sql.LevelReadCommitted.String(): "sql.LevelReadCommitted.String()",
+ sql.LevelWriteCommitted.String(): "sql.LevelWriteCommitted.String()",
+ sql.LevelRepeatableRead.String(): "sql.LevelRepeatableRead.String()",
+ // sql.LevelSnapshot.String(): "sql.LevelSnapshot.String()",
+ // sql.LevelSerializable.String(): "sql.LevelSerializable.String()",
+ // sql.LevelLinearizable.String(): "sql.LevelLinearizable.String()",
+}
+
+var TLSSignatureScheme = map[string]string{
+ tls.PSSWithSHA256.String(): "tls.PSSWithSHA256.String()",
+ tls.ECDSAWithP256AndSHA256.String(): "tls.ECDSAWithP256AndSHA256.String()",
+ tls.Ed25519.String(): "tls.Ed25519.String()",
+ tls.PSSWithSHA384.String(): "tls.PSSWithSHA384.String()",
+ tls.PSSWithSHA512.String(): "tls.PSSWithSHA512.String()",
+ tls.PKCS1WithSHA256.String(): "tls.PKCS1WithSHA256.String()",
+ tls.PKCS1WithSHA384.String(): "tls.PKCS1WithSHA384.String()",
+ tls.PKCS1WithSHA512.String(): "tls.PKCS1WithSHA512.String()",
+ tls.ECDSAWithP384AndSHA384.String(): "tls.ECDSAWithP384AndSHA384.String()",
+ tls.ECDSAWithP521AndSHA512.String(): "tls.ECDSAWithP521AndSHA512.String()",
+ tls.PKCS1WithSHA1.String(): "tls.PKCS1WithSHA1.String()",
+ tls.ECDSAWithSHA1.String(): "tls.ECDSAWithSHA1.String()",
+}
+
+var ConstantKind = map[string]string{
+ // constant.Unknown.String(): "constant.Unknown.String()",
+ constant.Bool.String(): "constant.Bool.String()",
+ constant.String.String(): "constant.String.String()",
+ constant.Int.String(): "constant.Int.String()",
+ constant.Float.String(): "constant.Float.String()",
+ constant.Complex.String(): "constant.Complex.String()",
+}