From c3802dcc0f54763b27ffb6af5b03289651fda250 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sun, 9 May 2021 13:08:02 +0200 Subject: [PATCH] Use binary version of revive linter (#15739) Use the common `go get` method to install and run the revive linter, removing the useless build/lint.go and related vendor libraries. --- Makefile | 5 +- build.go | 8 - build/lint.go | 325 ---- go.mod | 7 +- go.sum | 13 - vendor/github.com/chavacava/garif/.gitignore | 3 - vendor/github.com/chavacava/garif/LICENSE | 21 - vendor/github.com/chavacava/garif/README.md | 52 - .../chavacava/garif/constructors.go | 338 ---- .../github.com/chavacava/garif/decorators.go | 94 -- vendor/github.com/chavacava/garif/doc.go | 11 - vendor/github.com/chavacava/garif/go.mod | 5 - vendor/github.com/chavacava/garif/go.sum | 11 - vendor/github.com/chavacava/garif/io.go | 26 - vendor/github.com/chavacava/garif/models.go | 1486 ----------------- vendor/github.com/fatih/color/LICENSE.md | 20 - vendor/github.com/fatih/color/README.md | 173 -- vendor/github.com/fatih/color/color.go | 603 ------- vendor/github.com/fatih/color/doc.go | 133 -- vendor/github.com/fatih/color/go.mod | 8 - vendor/github.com/fatih/color/go.sum | 7 - vendor/github.com/fatih/structtag/LICENSE | 60 - vendor/github.com/fatih/structtag/README.md | 73 - vendor/github.com/fatih/structtag/go.mod | 3 - vendor/github.com/fatih/structtag/tags.go | 315 ---- .../github.com/mattn/go-colorable/.travis.yml | 15 - vendor/github.com/mattn/go-colorable/LICENSE | 21 - .../github.com/mattn/go-colorable/README.md | 48 - .../mattn/go-colorable/colorable_appengine.go | 37 - .../mattn/go-colorable/colorable_others.go | 38 - .../mattn/go-colorable/colorable_windows.go | 1043 ------------ vendor/github.com/mattn/go-colorable/go.mod | 8 - vendor/github.com/mattn/go-colorable/go.sum | 5 - .../github.com/mattn/go-colorable/go.test.sh | 12 - .../mattn/go-colorable/noncolorable.go | 55 - vendor/github.com/mgechev/dots/.travis.yml | 2 - vendor/github.com/mgechev/dots/LICENSE | 21 - vendor/github.com/mgechev/dots/README.md | 100 -- vendor/github.com/mgechev/dots/resolve.go | 456 ----- vendor/github.com/mgechev/revive/LICENSE | 21 - .../mgechev/revive/formatter/checkstyle.go | 76 - .../mgechev/revive/formatter/default.go | 26 - .../mgechev/revive/formatter/friendly.go | 149 -- .../mgechev/revive/formatter/json.go | 40 - .../mgechev/revive/formatter/ndjson.go | 34 - .../mgechev/revive/formatter/plain.go | 26 - .../mgechev/revive/formatter/sarif.go | 107 -- .../mgechev/revive/formatter/severity.go | 13 - .../mgechev/revive/formatter/stylish.go | 89 - .../mgechev/revive/formatter/unix.go | 27 - .../github.com/mgechev/revive/lint/config.go | 33 - .../github.com/mgechev/revive/lint/failure.go | 39 - vendor/github.com/mgechev/revive/lint/file.go | 278 --- .../mgechev/revive/lint/formatter.go | 14 - .../github.com/mgechev/revive/lint/linter.go | 99 -- .../github.com/mgechev/revive/lint/package.go | 178 -- vendor/github.com/mgechev/revive/lint/rule.go | 31 - .../github.com/mgechev/revive/lint/utils.go | 128 -- .../mgechev/revive/rule/add-constant.go | 151 -- .../mgechev/revive/rule/argument-limit.go | 67 - .../github.com/mgechev/revive/rule/atomic.go | 94 -- .../mgechev/revive/rule/bare-return.go | 84 - .../mgechev/revive/rule/blank-imports.go | 75 - .../revive/rule/bool-literal-in-expr.go | 73 - .../mgechev/revive/rule/call-to-gc.go | 70 - .../revive/rule/cognitive-complexity.go | 195 --- .../mgechev/revive/rule/confusing-naming.go | 190 --- .../mgechev/revive/rule/confusing-results.go | 67 - .../revive/rule/constant-logical-expr.go | 88 - .../revive/rule/context-as-argument.go | 60 - .../mgechev/revive/rule/context-keys-type.go | 81 - .../mgechev/revive/rule/cyclomatic.go | 115 -- .../mgechev/revive/rule/deep-exit.go | 94 -- .../github.com/mgechev/revive/rule/defer.go | 137 -- .../mgechev/revive/rule/dot-imports.go | 54 - .../mgechev/revive/rule/duplicated-imports.go | 39 - .../mgechev/revive/rule/early-return.go | 78 - .../mgechev/revive/rule/empty-block.go | 65 - .../mgechev/revive/rule/empty-lines.go | 113 -- .../mgechev/revive/rule/error-naming.go | 79 - .../mgechev/revive/rule/error-return.go | 67 - .../mgechev/revive/rule/error-strings.go | 98 -- .../github.com/mgechev/revive/rule/errorf.go | 93 -- .../mgechev/revive/rule/exported.go | 272 --- .../mgechev/revive/rule/file-header.go | 69 - .../mgechev/revive/rule/flag-param.go | 104 -- .../mgechev/revive/rule/function-length.go | 153 -- .../revive/rule/function-result-limit.go | 68 - .../mgechev/revive/rule/get-return.go | 70 - .../mgechev/revive/rule/identical-branches.go | 82 - .../mgechev/revive/rule/if-return.go | 115 -- .../mgechev/revive/rule/import-shadowing.go | 102 -- .../mgechev/revive/rule/imports-blacklist.go | 52 - .../revive/rule/increment-decrement.go | 74 - .../mgechev/revive/rule/indent-error-flow.go | 78 - .../mgechev/revive/rule/line-length-limit.go | 84 - .../mgechev/revive/rule/max-public-structs.go | 67 - .../mgechev/revive/rule/modifies-param.go | 80 - .../revive/rule/modifies-value-receiver.go | 134 -- .../mgechev/revive/rule/package-comments.go | 121 -- .../mgechev/revive/rule/range-val-address.go | 113 -- .../revive/rule/range-val-in-closure.go | 111 -- .../github.com/mgechev/revive/rule/range.go | 82 - .../mgechev/revive/rule/receiver-naming.go | 81 - .../revive/rule/redefines-builtin-id.go | 145 -- .../mgechev/revive/rule/string-of-int.go | 95 -- .../mgechev/revive/rule/struct-tag.go | 236 --- .../mgechev/revive/rule/superfluous-else.go | 114 -- .../mgechev/revive/rule/time-naming.go | 93 -- .../revive/rule/unconditional-recursion.go | 183 -- .../mgechev/revive/rule/unexported-naming.go | 115 -- .../mgechev/revive/rule/unexported-return.go | 106 -- .../mgechev/revive/rule/unhandled-error.go | 120 -- .../mgechev/revive/rule/unnecessary-stmt.go | 107 -- .../mgechev/revive/rule/unreachable-code.go | 114 -- .../mgechev/revive/rule/unused-param.go | 102 -- .../mgechev/revive/rule/unused-receiver.go | 77 - .../github.com/mgechev/revive/rule/utils.go | 191 --- .../mgechev/revive/rule/var-declarations.go | 120 -- .../mgechev/revive/rule/var-naming.go | 230 --- .../mgechev/revive/rule/waitgroup-by-value.go | 66 - vendor/modules.txt | 19 +- 122 files changed, 7 insertions(+), 13734 deletions(-) delete mode 100644 build/lint.go delete mode 100644 vendor/github.com/chavacava/garif/.gitignore delete mode 100644 vendor/github.com/chavacava/garif/LICENSE delete mode 100644 vendor/github.com/chavacava/garif/README.md delete mode 100644 vendor/github.com/chavacava/garif/constructors.go delete mode 100644 vendor/github.com/chavacava/garif/decorators.go delete mode 100644 vendor/github.com/chavacava/garif/doc.go delete mode 100644 vendor/github.com/chavacava/garif/go.mod delete mode 100644 vendor/github.com/chavacava/garif/go.sum delete mode 100644 vendor/github.com/chavacava/garif/io.go delete mode 100644 vendor/github.com/chavacava/garif/models.go delete mode 100644 vendor/github.com/fatih/color/LICENSE.md delete mode 100644 vendor/github.com/fatih/color/README.md delete mode 100644 vendor/github.com/fatih/color/color.go delete mode 100644 vendor/github.com/fatih/color/doc.go delete mode 100644 vendor/github.com/fatih/color/go.mod delete mode 100644 vendor/github.com/fatih/color/go.sum delete mode 100644 vendor/github.com/fatih/structtag/LICENSE delete mode 100644 vendor/github.com/fatih/structtag/README.md delete mode 100644 vendor/github.com/fatih/structtag/go.mod delete mode 100644 vendor/github.com/fatih/structtag/tags.go delete mode 100644 vendor/github.com/mattn/go-colorable/.travis.yml delete mode 100644 vendor/github.com/mattn/go-colorable/LICENSE delete mode 100644 vendor/github.com/mattn/go-colorable/README.md delete mode 100644 vendor/github.com/mattn/go-colorable/colorable_appengine.go delete mode 100644 vendor/github.com/mattn/go-colorable/colorable_others.go delete mode 100644 vendor/github.com/mattn/go-colorable/colorable_windows.go delete mode 100644 vendor/github.com/mattn/go-colorable/go.mod delete mode 100644 vendor/github.com/mattn/go-colorable/go.sum delete mode 100644 vendor/github.com/mattn/go-colorable/go.test.sh delete mode 100644 vendor/github.com/mattn/go-colorable/noncolorable.go delete mode 100644 vendor/github.com/mgechev/dots/.travis.yml delete mode 100644 vendor/github.com/mgechev/dots/LICENSE delete mode 100644 vendor/github.com/mgechev/dots/README.md delete mode 100644 vendor/github.com/mgechev/dots/resolve.go delete mode 100644 vendor/github.com/mgechev/revive/LICENSE delete mode 100644 vendor/github.com/mgechev/revive/formatter/checkstyle.go delete mode 100644 vendor/github.com/mgechev/revive/formatter/default.go delete mode 100644 vendor/github.com/mgechev/revive/formatter/friendly.go delete mode 100644 vendor/github.com/mgechev/revive/formatter/json.go delete mode 100644 vendor/github.com/mgechev/revive/formatter/ndjson.go delete mode 100644 vendor/github.com/mgechev/revive/formatter/plain.go delete mode 100644 vendor/github.com/mgechev/revive/formatter/sarif.go delete mode 100644 vendor/github.com/mgechev/revive/formatter/severity.go delete mode 100644 vendor/github.com/mgechev/revive/formatter/stylish.go delete mode 100644 vendor/github.com/mgechev/revive/formatter/unix.go delete mode 100644 vendor/github.com/mgechev/revive/lint/config.go delete mode 100644 vendor/github.com/mgechev/revive/lint/failure.go delete mode 100644 vendor/github.com/mgechev/revive/lint/file.go delete mode 100644 vendor/github.com/mgechev/revive/lint/formatter.go delete mode 100644 vendor/github.com/mgechev/revive/lint/linter.go delete mode 100644 vendor/github.com/mgechev/revive/lint/package.go delete mode 100644 vendor/github.com/mgechev/revive/lint/rule.go delete mode 100644 vendor/github.com/mgechev/revive/lint/utils.go delete mode 100644 vendor/github.com/mgechev/revive/rule/add-constant.go delete mode 100644 vendor/github.com/mgechev/revive/rule/argument-limit.go delete mode 100644 vendor/github.com/mgechev/revive/rule/atomic.go delete mode 100644 vendor/github.com/mgechev/revive/rule/bare-return.go delete mode 100644 vendor/github.com/mgechev/revive/rule/blank-imports.go delete mode 100644 vendor/github.com/mgechev/revive/rule/bool-literal-in-expr.go delete mode 100644 vendor/github.com/mgechev/revive/rule/call-to-gc.go delete mode 100644 vendor/github.com/mgechev/revive/rule/cognitive-complexity.go delete mode 100644 vendor/github.com/mgechev/revive/rule/confusing-naming.go delete mode 100644 vendor/github.com/mgechev/revive/rule/confusing-results.go delete mode 100644 vendor/github.com/mgechev/revive/rule/constant-logical-expr.go delete mode 100644 vendor/github.com/mgechev/revive/rule/context-as-argument.go delete mode 100644 vendor/github.com/mgechev/revive/rule/context-keys-type.go delete mode 100644 vendor/github.com/mgechev/revive/rule/cyclomatic.go delete mode 100644 vendor/github.com/mgechev/revive/rule/deep-exit.go delete mode 100644 vendor/github.com/mgechev/revive/rule/defer.go delete mode 100644 vendor/github.com/mgechev/revive/rule/dot-imports.go delete mode 100644 vendor/github.com/mgechev/revive/rule/duplicated-imports.go delete mode 100644 vendor/github.com/mgechev/revive/rule/early-return.go delete mode 100644 vendor/github.com/mgechev/revive/rule/empty-block.go delete mode 100644 vendor/github.com/mgechev/revive/rule/empty-lines.go delete mode 100644 vendor/github.com/mgechev/revive/rule/error-naming.go delete mode 100644 vendor/github.com/mgechev/revive/rule/error-return.go delete mode 100644 vendor/github.com/mgechev/revive/rule/error-strings.go delete mode 100644 vendor/github.com/mgechev/revive/rule/errorf.go delete mode 100644 vendor/github.com/mgechev/revive/rule/exported.go delete mode 100644 vendor/github.com/mgechev/revive/rule/file-header.go delete mode 100644 vendor/github.com/mgechev/revive/rule/flag-param.go delete mode 100644 vendor/github.com/mgechev/revive/rule/function-length.go delete mode 100644 vendor/github.com/mgechev/revive/rule/function-result-limit.go delete mode 100644 vendor/github.com/mgechev/revive/rule/get-return.go delete mode 100644 vendor/github.com/mgechev/revive/rule/identical-branches.go delete mode 100644 vendor/github.com/mgechev/revive/rule/if-return.go delete mode 100644 vendor/github.com/mgechev/revive/rule/import-shadowing.go delete mode 100644 vendor/github.com/mgechev/revive/rule/imports-blacklist.go delete mode 100644 vendor/github.com/mgechev/revive/rule/increment-decrement.go delete mode 100644 vendor/github.com/mgechev/revive/rule/indent-error-flow.go delete mode 100644 vendor/github.com/mgechev/revive/rule/line-length-limit.go delete mode 100644 vendor/github.com/mgechev/revive/rule/max-public-structs.go delete mode 100644 vendor/github.com/mgechev/revive/rule/modifies-param.go delete mode 100644 vendor/github.com/mgechev/revive/rule/modifies-value-receiver.go delete mode 100644 vendor/github.com/mgechev/revive/rule/package-comments.go delete mode 100644 vendor/github.com/mgechev/revive/rule/range-val-address.go delete mode 100644 vendor/github.com/mgechev/revive/rule/range-val-in-closure.go delete mode 100644 vendor/github.com/mgechev/revive/rule/range.go delete mode 100644 vendor/github.com/mgechev/revive/rule/receiver-naming.go delete mode 100644 vendor/github.com/mgechev/revive/rule/redefines-builtin-id.go delete mode 100644 vendor/github.com/mgechev/revive/rule/string-of-int.go delete mode 100644 vendor/github.com/mgechev/revive/rule/struct-tag.go delete mode 100644 vendor/github.com/mgechev/revive/rule/superfluous-else.go delete mode 100644 vendor/github.com/mgechev/revive/rule/time-naming.go delete mode 100644 vendor/github.com/mgechev/revive/rule/unconditional-recursion.go delete mode 100644 vendor/github.com/mgechev/revive/rule/unexported-naming.go delete mode 100644 vendor/github.com/mgechev/revive/rule/unexported-return.go delete mode 100644 vendor/github.com/mgechev/revive/rule/unhandled-error.go delete mode 100644 vendor/github.com/mgechev/revive/rule/unnecessary-stmt.go delete mode 100644 vendor/github.com/mgechev/revive/rule/unreachable-code.go delete mode 100644 vendor/github.com/mgechev/revive/rule/unused-param.go delete mode 100644 vendor/github.com/mgechev/revive/rule/unused-receiver.go delete mode 100644 vendor/github.com/mgechev/revive/rule/utils.go delete mode 100644 vendor/github.com/mgechev/revive/rule/var-declarations.go delete mode 100644 vendor/github.com/mgechev/revive/rule/var-naming.go delete mode 100644 vendor/github.com/mgechev/revive/rule/waitgroup-by-value.go diff --git a/Makefile b/Makefile index 8d9702ac8..6074f541c 100644 --- a/Makefile +++ b/Makefile @@ -282,7 +282,10 @@ errcheck: .PHONY: revive revive: - GO111MODULE=on $(GO) run -mod=vendor build/lint.go -config .revive.toml -exclude=./vendor/... ./... || exit 1 + @hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ + GO111MODULE=off $(GO) get -u github.com/mgechev/revive; \ + fi + @revive -config .revive.toml -exclude=./vendor/... ./... .PHONY: misspell-check misspell-check: diff --git a/build.go b/build.go index ab57fb1d9..b843465dc 100644 --- a/build.go +++ b/build.go @@ -10,14 +10,6 @@ package main // These libraries will not be included in a normal compilation. import ( - // for lint - _ "github.com/mgechev/dots" - _ "github.com/mgechev/revive/formatter" - _ "github.com/mgechev/revive/lint" - _ "github.com/mgechev/revive/rule" - _ "github.com/mitchellh/go-homedir" - _ "github.com/pelletier/go-toml" - // for embed _ "github.com/shurcooL/vfsgen" diff --git a/build/lint.go b/build/lint.go deleted file mode 100644 index 60e93697a..000000000 --- a/build/lint.go +++ /dev/null @@ -1,325 +0,0 @@ -// Copyright 2020 The Gitea Authors. All rights reserved. -// Copyright (c) 2018 Minko Gechev. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -// +build ignore - -package main - -import ( - "flag" - "fmt" - "io/ioutil" - "os" - "path/filepath" - "strings" - - "github.com/mgechev/dots" - "github.com/mgechev/revive/formatter" - "github.com/mgechev/revive/lint" - "github.com/mgechev/revive/rule" - "github.com/mitchellh/go-homedir" - "github.com/pelletier/go-toml" -) - -func fail(err string) { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) -} - -var defaultRules = []lint.Rule{ - &rule.VarDeclarationsRule{}, - &rule.PackageCommentsRule{}, - &rule.DotImportsRule{}, - &rule.BlankImportsRule{}, - &rule.ExportedRule{}, - &rule.VarNamingRule{}, - &rule.IndentErrorFlowRule{}, - &rule.IfReturnRule{}, - &rule.RangeRule{}, - &rule.ErrorfRule{}, - &rule.ErrorNamingRule{}, - &rule.ErrorStringsRule{}, - &rule.ReceiverNamingRule{}, - &rule.IncrementDecrementRule{}, - &rule.ErrorReturnRule{}, - &rule.UnexportedReturnRule{}, - &rule.TimeNamingRule{}, - &rule.ContextKeysType{}, - &rule.ContextAsArgumentRule{}, -} - -var allRules = append([]lint.Rule{ - &rule.ArgumentsLimitRule{}, - &rule.CyclomaticRule{}, - &rule.FileHeaderRule{}, - &rule.EmptyBlockRule{}, - &rule.SuperfluousElseRule{}, - &rule.ConfusingNamingRule{}, - &rule.GetReturnRule{}, - &rule.ModifiesParamRule{}, - &rule.ConfusingResultsRule{}, - &rule.DeepExitRule{}, - &rule.UnusedParamRule{}, - &rule.UnreachableCodeRule{}, - &rule.AddConstantRule{}, - &rule.FlagParamRule{}, - &rule.UnnecessaryStmtRule{}, - &rule.StructTagRule{}, - &rule.ModifiesValRecRule{}, - &rule.ConstantLogicalExprRule{}, - &rule.BoolLiteralRule{}, - &rule.RedefinesBuiltinIDRule{}, - &rule.ImportsBlacklistRule{}, - &rule.FunctionResultsLimitRule{}, - &rule.MaxPublicStructsRule{}, - &rule.RangeValInClosureRule{}, - &rule.RangeValAddress{}, - &rule.WaitGroupByValueRule{}, - &rule.AtomicRule{}, - &rule.EmptyLinesRule{}, - &rule.LineLengthLimitRule{}, - &rule.CallToGCRule{}, - &rule.DuplicatedImportsRule{}, - &rule.ImportShadowingRule{}, - &rule.BareReturnRule{}, - &rule.UnusedReceiverRule{}, - &rule.UnhandledErrorRule{}, - &rule.CognitiveComplexityRule{}, - &rule.StringOfIntRule{}, -}, defaultRules...) - -var allFormatters = []lint.Formatter{ - &formatter.Stylish{}, - &formatter.Friendly{}, - &formatter.JSON{}, - &formatter.NDJSON{}, - &formatter.Default{}, - &formatter.Unix{}, - &formatter.Checkstyle{}, - &formatter.Plain{}, -} - -func getFormatters() map[string]lint.Formatter { - result := map[string]lint.Formatter{} - for _, f := range allFormatters { - result[f.Name()] = f - } - return result -} - -func getLintingRules(config *lint.Config) []lint.Rule { - rulesMap := map[string]lint.Rule{} - for _, r := range allRules { - rulesMap[r.Name()] = r - } - - lintingRules := []lint.Rule{} - for name := range config.Rules { - rule, ok := rulesMap[name] - if !ok { - fail("cannot find rule: " + name) - } - lintingRules = append(lintingRules, rule) - } - - return lintingRules -} - -func parseConfig(path string) *lint.Config { - config := &lint.Config{} - file, err := ioutil.ReadFile(path) - if err != nil { - fail("cannot read the config file") - } - err = toml.Unmarshal(file, config) - if err != nil { - fail("cannot parse the config file: " + err.Error()) - } - return config -} - -func normalizeConfig(config *lint.Config) { - if config.Confidence == 0 { - config.Confidence = 0.8 - } - severity := config.Severity - if severity != "" { - for k, v := range config.Rules { - if v.Severity == "" { - v.Severity = severity - } - config.Rules[k] = v - } - for k, v := range config.Directives { - if v.Severity == "" { - v.Severity = severity - } - config.Directives[k] = v - } - } -} - -func getConfig() *lint.Config { - config := defaultConfig() - if configPath != "" { - config = parseConfig(configPath) - } - normalizeConfig(config) - return config -} - -func getFormatter() lint.Formatter { - formatters := getFormatters() - formatter := formatters["default"] - if formatterName != "" { - f, ok := formatters[formatterName] - if !ok { - fail("unknown formatter " + formatterName) - } - formatter = f - } - return formatter -} - -func buildDefaultConfigPath() string { - var result string - if homeDir, err := homedir.Dir(); err == nil { - result = filepath.Join(homeDir, "revive.toml") - if _, err := os.Stat(result); err != nil { - result = "" - } - } - - return result -} - -func defaultConfig() *lint.Config { - defaultConfig := lint.Config{ - Confidence: 0.0, - Severity: lint.SeverityWarning, - Rules: map[string]lint.RuleConfig{}, - } - for _, r := range defaultRules { - defaultConfig.Rules[r.Name()] = lint.RuleConfig{} - } - return &defaultConfig -} - -func normalizeSplit(strs []string) []string { - res := []string{} - for _, s := range strs { - t := strings.Trim(s, " \t") - if len(t) > 0 { - res = append(res, t) - } - } - return res -} - -func getPackages() [][]string { - globs := normalizeSplit(flag.Args()) - if len(globs) == 0 { - globs = append(globs, ".") - } - - packages, err := dots.ResolvePackages(globs, normalizeSplit(excludePaths)) - if err != nil { - fail(err.Error()) - } - - return packages -} - -type arrayFlags []string - -func (i *arrayFlags) String() string { - return strings.Join([]string(*i), " ") -} - -func (i *arrayFlags) Set(value string) error { - *i = append(*i, value) - return nil -} - -var configPath string -var excludePaths arrayFlags -var formatterName string -var help bool - -var originalUsage = flag.Usage - -func init() { - flag.Usage = func() { - originalUsage() - } - // command line help strings - const ( - configUsage = "path to the configuration TOML file, defaults to $HOME/revive.toml, if present (i.e. -config myconf.toml)" - excludeUsage = "list of globs which specify files to be excluded (i.e. -exclude foo/...)" - formatterUsage = "formatter to be used for the output (i.e. -formatter stylish)" - ) - - defaultConfigPath := buildDefaultConfigPath() - - flag.StringVar(&configPath, "config", defaultConfigPath, configUsage) - flag.Var(&excludePaths, "exclude", excludeUsage) - flag.StringVar(&formatterName, "formatter", "", formatterUsage) - flag.Parse() -} - -func main() { - config := getConfig() - formatter := getFormatter() - packages := getPackages() - - revive := lint.New(func(file string) ([]byte, error) { - return ioutil.ReadFile(file) - }) - - lintingRules := getLintingRules(config) - - failures, err := revive.Lint(packages, lintingRules, *config) - if err != nil { - fail(err.Error()) - } - - formatChan := make(chan lint.Failure) - exitChan := make(chan bool) - - var output string - go (func() { - output, err = formatter.Format(formatChan, *config) - if err != nil { - fail(err.Error()) - } - exitChan <- true - })() - - exitCode := 0 - for f := range failures { - if f.Confidence < config.Confidence { - continue - } - if exitCode == 0 { - exitCode = config.WarningCode - } - if c, ok := config.Rules[f.RuleName]; ok && c.Severity == lint.SeverityError { - exitCode = config.ErrorCode - } - if c, ok := config.Directives[f.RuleName]; ok && c.Severity == lint.SeverityError { - exitCode = config.ErrorCode - } - - formatChan <- f - } - - close(formatChan) - <-exitChan - if output != "" { - fmt.Println(output) - } - - os.Exit(exitCode) -} diff --git a/go.mod b/go.mod index 9a3ef0652..5d0dd5fd6 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,6 @@ require ( github.com/boombuler/barcode v1.0.1 // indirect github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b // indirect github.com/caddyserver/certmagic v0.13.0 - github.com/chavacava/garif v0.0.0-20210405164556-e8a0a408d6af // indirect github.com/chi-middleware/proxy v1.1.1 github.com/couchbase/go-couchbase v0.0.0-20210224140812-5740cd35f448 // indirect github.com/couchbase/gomemcached v0.1.2 // indirect @@ -74,22 +73,20 @@ require ( github.com/mattn/go-isatty v0.0.12 github.com/mattn/go-runewidth v0.0.12 // indirect github.com/mattn/go-sqlite3 v1.14.7 - github.com/mgechev/dots v0.0.0-20190921121421-c36f7dcfbb81 - github.com/mgechev/revive v1.0.6 github.com/mholt/archiver/v3 v3.5.0 github.com/microcosm-cc/bluemonday v1.0.8 github.com/miekg/dns v1.1.40 // indirect github.com/minio/md5-simd v1.1.2 // indirect github.com/minio/minio-go/v7 v7.0.10 github.com/minio/sha256-simd v1.0.0 // indirect - github.com/mitchellh/go-homedir v1.1.0 github.com/mrjones/oauth v0.0.0-20190623134757-126b35219450 // indirect github.com/msteinert/pam v0.0.0-20201130170657-e61372126161 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 github.com/niklasfasching/go-org v1.5.0 + github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/oliamb/cutter v0.2.2 github.com/olivere/elastic/v7 v7.0.24 - github.com/pelletier/go-toml v1.9.0 + github.com/pelletier/go-toml v1.9.0 // indirect github.com/pierrec/lz4/v4 v4.1.3 // indirect github.com/pkg/errors v0.9.1 github.com/pquerna/otp v1.3.0 diff --git a/go.sum b/go.sum index 70867f495..ada171e23 100644 --- a/go.sum +++ b/go.sum @@ -196,9 +196,6 @@ github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/chavacava/garif v0.0.0-20210405163807-87a70f3d418b/go.mod h1:Qjyv4H3//PWVzTeCezG2b9IRn6myJxJSr4TD/xo6ojU= -github.com/chavacava/garif v0.0.0-20210405164556-e8a0a408d6af h1:spmv8nSH9h5oCQf40jt/ufBCt9j0/58u4G+rkeMqXGI= -github.com/chavacava/garif v0.0.0-20210405164556-e8a0a408d6af/go.mod h1:Qjyv4H3//PWVzTeCezG2b9IRn6myJxJSr4TD/xo6ojU= github.com/chi-middleware/proxy v1.1.1 h1:4HaXUp8o2+bhHr1OhVy+VjN0+L7/07JDcn6v7YrTjrQ= github.com/chi-middleware/proxy v1.1.1/go.mod h1:jQwMEJct2tz9VmtCELxvnXoMfa+SOdikvbVJVHv/M+0= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= @@ -292,10 +289,6 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/ethantkoenig/rupture v1.0.0 h1:gPInt1N30UErGNzd8t5js5Qbnpjcd1l6yU2MCrJxIe8= github.com/ethantkoenig/rupture v1.0.0/go.mod h1:GyE9QabHfxA6ch0NZgwsHopRbOLcYjUr9g4FTJmq0WM= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= -github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= -github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= -github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ= github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= @@ -805,8 +798,6 @@ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= -github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= @@ -825,10 +816,6 @@ github.com/mattn/go-sqlite3 v1.14.7 h1:fxWBnXkxfM6sRiuH3bqJ4CfzZojMOLVc0UTsTglEg github.com/mattn/go-sqlite3 v1.14.7/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mgechev/dots v0.0.0-20190921121421-c36f7dcfbb81 h1:QASJXOGm2RZ5Ardbc86qNFvby9AqkLDibfChMtAg5QM= -github.com/mgechev/dots v0.0.0-20190921121421-c36f7dcfbb81/go.mod h1:KQ7+USdGKfpPjXk4Ga+5XxQM4Lm4e3gAogrreFAYpOg= -github.com/mgechev/revive v1.0.6 h1:MgRQ3ys2uQCyVjelaDhVs8oSvOPYInzGA/nNGMa+MNU= -github.com/mgechev/revive v1.0.6/go.mod h1:Lj5gIVxjBlH8REa3icEOkdfchwYc291nShzZ4QYWyMo= github.com/mholt/acmez v0.1.3 h1:J7MmNIk4Qf9b8mAGqAh4XkNeowv3f1zW816yf4zt7Qk= github.com/mholt/acmez v0.1.3/go.mod h1:8qnn8QA/Ewx8E3ZSsmscqsIjhhpxuy9vqdgbX2ceceM= github.com/mholt/archiver/v3 v3.5.0 h1:nE8gZIrw66cu4osS/U7UW7YDuGMHssxKutU8IfWxwWE= diff --git a/vendor/github.com/chavacava/garif/.gitignore b/vendor/github.com/chavacava/garif/.gitignore deleted file mode 100644 index 5dee1052c..000000000 --- a/vendor/github.com/chavacava/garif/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.test -*.out -.devcontainer/ \ No newline at end of file diff --git a/vendor/github.com/chavacava/garif/LICENSE b/vendor/github.com/chavacava/garif/LICENSE deleted file mode 100644 index 2bba73fb7..000000000 --- a/vendor/github.com/chavacava/garif/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021 Salvador Cavadini - -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/chavacava/garif/README.md b/vendor/github.com/chavacava/garif/README.md deleted file mode 100644 index 6a19c6147..000000000 --- a/vendor/github.com/chavacava/garif/README.md +++ /dev/null @@ -1,52 +0,0 @@ -# garif - -A GO package to create and manipulate SARIF logs. - -SARIF, from _Static Analysis Results Interchange Format_, is a standard JSON-based format for the output of static analysis tools defined and promoted by [OASIS](https://www.oasis-open.org/). - -Current supported version of the standard is [SARIF-v2.1.0](https://docs.oasis-open.org/sarif/sarif/v2.1.0/csprd01/sarif-v2.1.0-csprd01.html -). - -## Usage - -The package provides access to every element of the SARIF model, therefore you are free to manipulate it at every detail. - -The package also provides constructors functions (`New...`) and decorators methods (`With...`) that simplify the creation of SARIF files for common use cases. - -Using these constructors and decorators we can easily create the example SARIF file of the [Microsoft SARIF pages](https://github.com/microsoft/sarif-tutorials/blob/master/docs/1-Introduction.md) - - -```go -import to `github.com/chavacava/garif` - -// ... - -rule := garif.NewRule("no-unused-vars"). - WithHelpUri("https://eslint.org/docs/rules/no-unused-vars"). - WithShortDescription("disallow unused variables"). - WithProperties("category", "Variables") - -driver := garif.NewDriver("ESLint"). - WithInformationUri("https://eslint.org"). - WithRules(rule) - -run := garif.NewRun(NewTool(driver)). - WithArtifactsURIs("file:///C:/dev/sarif/sarif-tutorials/samples/Introduction/simple-example.js") - -run.WithResult(rule.Id, "'x' is assigned a value but never used.", "file:///C:/dev/sarif/sarif-tutorials/samples/Introduction/simple-example.js", 1, 5) - -logFile := garif.NewLogFile([]*Run{run}, Version210) - -logFile.Write(os.Stdout) -``` - -## Why this package? -This package was initiated during my works on adding to [`revive`](https://github.com/mgechev/revive) a SARIF output formatter. -I've tried to use [go-sarif](https://github.com/owenrumney/go-sarif) by [Owen Rumney](https://github.com/owenrumney) but it is too focused in the use case of the static analyzer [tfsec](https://tfsec.dev) so I've decided to create a package flexible enough to generate SARIF files in broader cases. - -## More information about SARIF -For more information about SARIF, you can visit the [Oasis Open](https://www.oasis-open.org/committees/tc_home.php?wg_abbrev=sarif) site. - - -## Contributing -Of course, contributions are welcome! \ No newline at end of file diff --git a/vendor/github.com/chavacava/garif/constructors.go b/vendor/github.com/chavacava/garif/constructors.go deleted file mode 100644 index 8910e396e..000000000 --- a/vendor/github.com/chavacava/garif/constructors.go +++ /dev/null @@ -1,338 +0,0 @@ -package garif - -// NewAddress creates a valid Address -func NewAddress() *Address { - return &Address{} -} - -// NewArtifact creates a valid Artifact -func NewArtifact() *Artifact { - return &Artifact{} -} - -// NewArtifactChange creates a valid ArtifactChange -func NewArtifactChange(location *ArtifactLocation, replacements ...*Replacement) *ArtifactChange { - return &ArtifactChange{ - ArtifactLocation: location, - Replacements: replacements, - } -} - -// NewArtifactContent creates a valid ArtifactContent -func NewArtifactContent() *ArtifactContent { - return &ArtifactContent{} -} - -// NewArtifactLocation creates a valid ArtifactLocation -func NewArtifactLocation() *ArtifactLocation { - return &ArtifactLocation{} -} - -// NewAttachment creates a valid Attachment -func NewAttachment(location *ArtifactLocation) *Attachment { - return &Attachment{ArtifactLocation: location} -} - -// NewCodeFlow creates a valid CodeFlow -func NewCodeFlow(threadFlows ...*ThreadFlow) *CodeFlow { - return &CodeFlow{ThreadFlows: threadFlows} -} - -// NewConfigurationOverride creates a valid ConfigurationOverride -func NewConfigurationOverride(configuration *ReportingConfiguration, descriptor *ReportingDescriptorReference) *ConfigurationOverride { - return &ConfigurationOverride{ - Configuration: configuration, - Descriptor: descriptor, - } -} - -// NewConversion creates a valid Conversion -func NewConversion(tool *Tool) *Conversion { - return &Conversion{Tool: tool} -} - -// NewEdge creates a valid Edge -func NewEdge(id, sourceNodeId, targetNodeId string) *Edge { - return &Edge{ - Id: id, - SourceNodeId: sourceNodeId, - TargetNodeId: targetNodeId, - } -} - -// NewEdgeTraversal creates a valid EdgeTraversal -func NewEdgeTraversal(edgeId string) *EdgeTraversal { - return &EdgeTraversal{ - EdgeId: edgeId, - } -} - -// NewException creates a valid Exception -func NewException() *Exception { - return &Exception{} -} - -// NewExternalProperties creates a valid ExternalProperties -func NewExternalProperties() *ExternalProperties { - return &ExternalProperties{} -} - -// NewExternalPropertyFileReference creates a valid ExternalPropertyFileReference -func NewExternalPropertyFileReference() *ExternalPropertyFileReference { - return &ExternalPropertyFileReference{} -} - -// NewExternalPropertyFileReferences creates a valid ExternalPropertyFileReferences -func NewExternalPropertyFileReferences() *ExternalPropertyFileReferences { - return &ExternalPropertyFileReferences{} -} - -// NewFix creates a valid Fix -func NewFix(artifactChanges ...*ArtifactChange) *Fix { - return &Fix{ - ArtifactChanges: artifactChanges, - } -} - -// NewGraph creates a valid Graph -func NewGraph() *Graph { - return &Graph{} -} - -// NewGraphTraversal creates a valid GraphTraversal -func NewGraphTraversal() *GraphTraversal { - return &GraphTraversal{} -} - -// NewInvocation creates a valid Invocation -func NewInvocation(executionSuccessful bool) *Invocation { - return &Invocation{ - ExecutionSuccessful: executionSuccessful, - } -} - -// NewLocation creates a valid Location -func NewLocation() *Location { - return &Location{} -} - -// NewLocationRelationship creates a valid LocationRelationship -func NewLocationRelationship(target int) *LocationRelationship { - return &LocationRelationship{ - Target: target, - } -} - -type LogFileVersion string - -const Version210 LogFileVersion = "2.1.0" - -// NewLogFile creates a valid LogFile -func NewLogFile(runs []*Run, version LogFileVersion) *LogFile { - return &LogFile{ - Runs: runs, - Version: version, - } -} - -// NewLogicalLocation creates a valid LogicalLocation -func NewLogicalLocation() *LogicalLocation { - return &LogicalLocation{} -} - -// NewMessage creates a valid Message -func NewMessage() *Message { - return &Message{} -} - -// NewMessageFromText creates a valid Message with the given text -func NewMessageFromText(text string) *Message { - return &Message{ - Text: text, - } -} - -// NewMultiformatMessageString creates a valid MultiformatMessageString -func NewMultiformatMessageString(text string) *MultiformatMessageString { - return &MultiformatMessageString{ - Text: text, - } -} - -// NewNode creates a valid Node -func NewNode(id string) *Node { - return &Node{ - Id: id, - } -} - -// NewNotification creates a valid Notification -func NewNotification(message *Message) *Notification { - return &Notification{ - Message: message, - } -} - -// NewPhysicalLocation creates a valid PhysicalLocation -func NewPhysicalLocation() *PhysicalLocation { - return &PhysicalLocation{} -} - -// NewPropertyBag creates a valid PropertyBag -func NewPropertyBag() *PropertyBag { - return &PropertyBag{} -} - -// NewRectangle creates a valid Rectangle -func NewRectangle() *Rectangle { - return &Rectangle{} -} - -// NewRegion creates a valid Region -func NewRegion() *Region { - return &Region{} -} - -// NewReplacement creates a valid Replacement -func NewReplacement(deletedRegion *Region) *Replacement { - return &Replacement{ - DeletedRegion: deletedRegion, - } -} - -// NewReportingConfiguration creates a valid ReportingConfiguration -func NewReportingConfiguration() *ReportingConfiguration { - return &ReportingConfiguration{} -} - -// NewReportingDescriptor creates a valid ReportingDescriptor -func NewReportingDescriptor(id string) *ReportingDescriptor { - return &ReportingDescriptor{ - Id: id, - } -} - -// NewRule is an alias for NewReportingDescriptor -func NewRule(id string) *ReportingDescriptor { - return NewReportingDescriptor(id) -} - -// NewReportingDescriptorReference creates a valid ReportingDescriptorReference -func NewReportingDescriptorReference() *ReportingDescriptorReference { - return &ReportingDescriptorReference{} -} - -// NewReportingDescriptorRelationship creates a valid ReportingDescriptorRelationship -func NewReportingDescriptorRelationship(target *ReportingDescriptorReference) *ReportingDescriptorRelationship { - return &ReportingDescriptorRelationship{ - Target: target, - } -} - -// NewResult creates a valid Result -func NewResult(message *Message) *Result { - return &Result{ - Message: message, - } -} - -// NewResultProvenance creates a valid ResultProvenance -func NewResultProvenance() *ResultProvenance { - return &ResultProvenance{} -} - -// NewRun creates a valid Run -func NewRun(tool *Tool) *Run { - return &Run{ - Tool: tool, - } -} - -// NewRunAutomationDetails creates a valid RunAutomationDetails -func NewRunAutomationDetails() *RunAutomationDetails { - return &RunAutomationDetails{} -} - -// New creates a valid -func NewSpecialLocations() *SpecialLocations { - return &SpecialLocations{} -} - -// NewStack creates a valid Stack -func NewStack(frames ...*StackFrame) *Stack { - return &Stack{ - Frames: frames, - } -} - -// NewStackFrame creates a valid StackFrame -func NewStackFrame() *StackFrame { - return &StackFrame{} -} - -// NewSuppression creates a valid Suppression -func NewSuppression(kind string) *Suppression { - return &Suppression{ - Kind: kind, - } -} - -// NewThreadFlow creates a valid ThreadFlow -func NewThreadFlow(locations []*ThreadFlowLocation) *ThreadFlow { - return &ThreadFlow{ - Locations: locations, - } -} - -// NewThreadFlowLocation creates a valid ThreadFlowLocation -func NewThreadFlowLocation() *ThreadFlowLocation { - return &ThreadFlowLocation{} -} - -// NewTool creates a valid Tool -func NewTool(driver *ToolComponent) *Tool { - return &Tool{ - Driver: driver, - } -} - -// NewToolComponent creates a valid ToolComponent -func NewToolComponent(name string) *ToolComponent { - return &ToolComponent{ - Name: name, - } -} - -// NewDriver is an alias for NewToolComponent -func NewDriver(name string) *ToolComponent { - return NewToolComponent(name) -} - -// NewToolComponentReference creates a valid ToolComponentReference -func NewToolComponentReference() *ToolComponentReference { - return &ToolComponentReference{} -} - -// NewTranslationMetadata creates a valid TranslationMetadata -func NewTranslationMetadata(name string) *TranslationMetadata { - return &TranslationMetadata{ - Name: name, - } -} - -// NewVersionControlDetails creates a valid VersionControlDetails -func NewVersionControlDetails(repositoryUri string) *VersionControlDetails { - return &VersionControlDetails{ - RepositoryUri: repositoryUri, - } -} - -// NewWebRequest creates a valid WebRequest -func NewWebRequest() *WebRequest { - return &WebRequest{} -} - -// NewWebResponse creates a valid WebResponse -func NewWebResponse() *WebResponse { - return &WebResponse{} -} diff --git a/vendor/github.com/chavacava/garif/decorators.go b/vendor/github.com/chavacava/garif/decorators.go deleted file mode 100644 index 00b599fb8..000000000 --- a/vendor/github.com/chavacava/garif/decorators.go +++ /dev/null @@ -1,94 +0,0 @@ -package garif - -// WithLineColumn sets a physical location with the given line and column -func (l *Location) WithLineColumn(line, column int) *Location { - if l.PhysicalLocation == nil { - l.PhysicalLocation = NewPhysicalLocation() - } - - l.PhysicalLocation.Region = NewRegion() - l.PhysicalLocation.Region.StartLine = line - l.PhysicalLocation.Region.StartColumn = column - - return l -} - -// WithURI sets a physical location with the given URI -func (l *Location) WithURI(uri string) *Location { - if l.PhysicalLocation == nil { - l.PhysicalLocation = NewPhysicalLocation() - } - - l.PhysicalLocation.ArtifactLocation = NewArtifactLocation() - l.PhysicalLocation.ArtifactLocation.Uri = uri - - return l -} - -// WithKeyValue sets (overwrites) the value of the given key -func (b PropertyBag) WithKeyValue(key string, value interface{}) PropertyBag { - b[key] = value - return b -} - -// WithHelpUri sets the help URI for this ReportingDescriptor -func (r *ReportingDescriptor) WithHelpUri(uri string) *ReportingDescriptor { - r.HelpUri = uri - return r -} - -// WithProperties adds the key & value to the properties of this ReportingDescriptor -func (r *ReportingDescriptor) WithProperties(key string, value interface{}) *ReportingDescriptor { - if r.Properties == nil { - r.Properties = NewPropertyBag() - } - - r.Properties.WithKeyValue(key, value) - - return r -} - -// WithArtifactsURIs adds the given URI as artifacts of this Run -func (r *Run) WithArtifactsURIs(uris ...string) *Run { - if r.Artifacts == nil { - r.Artifacts = []*Artifact{} - } - - for _, uri := range uris { - a := NewArtifact() - a.Location = NewArtifactLocation() - a.Location.Uri = uri - r.Artifacts = append(r.Artifacts, a) - } - - return r -} - -// WithResult adds a result to this Run -func (r *Run) WithResult(ruleId string, message string, uri string, line int, column int) *Run { - if r.Results == nil { - r.Results = []*Result{} - } - - msg := NewMessage() - msg.Text = message - result := NewResult(msg) - location := NewLocation().WithURI(uri).WithLineColumn(line, column) - - result.Locations = append(result.Locations, location) - result.RuleId = ruleId - r.Results = append(r.Results, result) - return r -} - -// WithInformationUri sets the information URI -func (t *ToolComponent) WithInformationUri(uri string) *ToolComponent { - t.InformationUri = uri - return t -} - -// WithRules sets (overwrites) the rules -func (t *ToolComponent) WithRules(rules ...*ReportingDescriptor) *ToolComponent { - t.Rules = rules - return t -} diff --git a/vendor/github.com/chavacava/garif/doc.go b/vendor/github.com/chavacava/garif/doc.go deleted file mode 100644 index 50fa6dfe5..000000000 --- a/vendor/github.com/chavacava/garif/doc.go +++ /dev/null @@ -1,11 +0,0 @@ -// Package garif defines all the GO structures required to model a SARIF log file. -// These structures were created using the JSON-schema sarif-schema-2.1.0.json of SARIF logfiles -// available at https://github.com/oasis-tcs/sarif-spec/tree/master/Schemata. -// -// The package provides constructors for all structures (see constructors.go) These constructors -// ensure that the returned structure instantiation is valid with respect to the JSON schema and -// should be used in place of plain structure instantiation. -// The root structure is LogFile. -// -// The package provides utility decorators for the most commonly used structures (see decorators.go) -package garif diff --git a/vendor/github.com/chavacava/garif/go.mod b/vendor/github.com/chavacava/garif/go.mod deleted file mode 100644 index 4c8a7f5ce..000000000 --- a/vendor/github.com/chavacava/garif/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module github.com/chavacava/garif - -go 1.16 - -require github.com/stretchr/testify v1.7.0 diff --git a/vendor/github.com/chavacava/garif/go.sum b/vendor/github.com/chavacava/garif/go.sum deleted file mode 100644 index acb88a48f..000000000 --- a/vendor/github.com/chavacava/garif/go.sum +++ /dev/null @@ -1,11 +0,0 @@ -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= -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/chavacava/garif/io.go b/vendor/github.com/chavacava/garif/io.go deleted file mode 100644 index ce5719c96..000000000 --- a/vendor/github.com/chavacava/garif/io.go +++ /dev/null @@ -1,26 +0,0 @@ -package garif - -import ( - "encoding/json" - "io" -) - -// Write writes the JSON -func (l *LogFile) Write(w io.Writer) error { - marshal, err := json.Marshal(l) - if err != nil { - return err - } - _, err = w.Write(marshal) - return err -} - -// PrettyWrite writes indented JSON -func (l *LogFile) PrettyWrite(w io.Writer) error { - marshal, err := json.MarshalIndent(l, "", " ") - if err != nil { - return err - } - _, err = w.Write(marshal) - return err -} diff --git a/vendor/github.com/chavacava/garif/models.go b/vendor/github.com/chavacava/garif/models.go deleted file mode 100644 index 3668436a3..000000000 --- a/vendor/github.com/chavacava/garif/models.go +++ /dev/null @@ -1,1486 +0,0 @@ -package garif - -// Address A physical or virtual address, or a range of addresses, in an 'addressable region' (memory or a binary file). -type Address struct { - - // The address expressed as a byte offset from the start of the addressable region. - AbsoluteAddress int `json:"absoluteAddress,omitempty"` - - // A human-readable fully qualified name that is associated with the address. - FullyQualifiedName string `json:"fullyQualifiedName,omitempty"` - - // The index within run.addresses of the cached object for this address. - Index int `json:"index,omitempty"` - - // An open-ended string that identifies the address kind. - // 'data', 'function', 'header','instruction', 'module', 'page', 'section', - // 'segment', 'stack', 'stackFrame', 'table' are well-known values. - Kind string `json:"kind,omitempty"` - - // The number of bytes in this range of addresses. - Length int `json:"length,omitempty"` - - // A name that is associated with the address, e.g., '.text'. - Name string `json:"name,omitempty"` - - // The byte offset of this address from the absolute or relative address of the parent object. - OffsetFromParent int `json:"offsetFromParent,omitempty"` - - // The index within run.addresses of the parent object. - ParentIndex int `json:"parentIndex,omitempty"` - - // Key/value pairs that provide additional information about the address. - Properties *PropertyBag `json:"properties,omitempty"` - - // The address expressed as a byte offset from the absolute address of the top-most parent object. - RelativeAddress int `json:"relativeAddress,omitempty"` -} - -// Artifact A single artifact. In some cases, this artifact might be nested within another artifact. -type Artifact struct { - - // The contents of the artifact. - Contents *ArtifactContent `json:"contents,omitempty"` - - // A short description of the artifact. - Description *Message `json:"description,omitempty"` - - // Specifies the encoding for an artifact object that refers to a text file. - Encoding string `json:"encoding,omitempty"` - - // A dictionary, each of whose keys is the name of a hash function and each of whose values is - // the hashed value of the artifact produced by the specified hash function. - Hashes map[string]string `json:"hashes,omitempty"` - - // The Coordinated Universal Time (UTC) date and time at which the artifact was most recently modified. - // See "Date/time properties" in the SARIF spec for the required format. - LastModifiedTimeUtc string `json:"lastModifiedTimeUtc,omitempty"` - - // The length of the artifact in bytes. - Length int `json:"length,omitempty"` - - // The location of the artifact. - Location *ArtifactLocation `json:"location,omitempty"` - - // The MIME type (RFC 2045) of the artifact. - MimeType string `json:"mimeType,omitempty"` - - // The offset in bytes of the artifact within its containing artifact. - Offset int `json:"offset,omitempty"` - - // Identifies the index of the immediate parent of the artifact, if this artifact is nested. - ParentIndex int `json:"parentIndex,omitempty"` - - // Key/value pairs that provide additional information about the artifact. - Properties *PropertyBag `json:"properties,omitempty"` - - // The role or roles played by the artifact in the analysis. - Roles []interface{} `json:"roles,omitempty"` - - // Specifies the source language for any artifact object that refers to a text file that contains source code. - SourceLanguage string `json:"sourceLanguage,omitempty"` -} - -// ArtifactChange A change to a single artifact. -type ArtifactChange struct { - - // The location of the artifact to change. - ArtifactLocation *ArtifactLocation `json:"artifactLocation"` - - // Key/value pairs that provide additional information about the change. - Properties *PropertyBag `json:"properties,omitempty"` - - // An array of replacement objects, each of which represents the replacement of a single region in a - // single artifact specified by 'artifactLocation'. - Replacements []*Replacement `json:"replacements"` -} - -// ArtifactContent Represents the contents of an artifact. -type ArtifactContent struct { - - // MIME Base64-encoded content from a binary artifact, or from a text artifact in its original encoding. - Binary string `json:"binary,omitempty"` - - // Key/value pairs that provide additional information about the artifact content. - Properties *PropertyBag `json:"properties,omitempty"` - - // An alternate rendered representation of the artifact (e.g., a decompiled representation of a binary region). - Rendered *MultiformatMessageString `json:"rendered,omitempty"` - - // UTF-8-encoded content from a text artifact. - Text string `json:"text,omitempty"` -} - -// ArtifactLocation Specifies the location of an artifact. -type ArtifactLocation struct { - - // A short description of the artifact location. - Description *Message `json:"description,omitempty"` - - // The index within the run artifacts array of the artifact object associated with the artifact location. - Index int `json:"index,omitempty"` - - // Key/value pairs that provide additional information about the artifact location. - Properties *PropertyBag `json:"properties,omitempty"` - - // A string containing a valid relative or absolute URI. - Uri string `json:"uri,omitempty"` - - // A string which indirectly specifies the absolute URI with respect to which a relative URI in the "uri" property is interpreted. - UriBaseId string `json:"uriBaseId,omitempty"` -} - -// Attachment An artifact relevant to a result. -type Attachment struct { - - // The location of the attachment. - ArtifactLocation *ArtifactLocation `json:"artifactLocation"` - - // A message describing the role played by the attachment. - Description *Message `json:"description,omitempty"` - - // Key/value pairs that provide additional information about the attachment. - Properties *PropertyBag `json:"properties,omitempty"` - - // An array of rectangles specifying areas of interest within the image. - Rectangles []*Rectangle `json:"rectangles,omitempty"` - - // An array of regions of interest within the attachment. - Regions []*Region `json:"regions,omitempty"` -} - -// CodeFlow A set of threadFlows which together describe a pattern of code execution relevant to detecting a result. -type CodeFlow struct { - - // A message relevant to the code flow. - Message *Message `json:"message,omitempty"` - - // Key/value pairs that provide additional information about the code flow. - Properties *PropertyBag `json:"properties,omitempty"` - - // An array of one or more unique threadFlow objects, each of which describes the progress of a program - // through a thread of execution. - ThreadFlows []*ThreadFlow `json:"threadFlows"` -} - -// ConfigurationOverride Information about how a specific rule or notification was reconfigured at runtime. -type ConfigurationOverride struct { - - // Specifies how the rule or notification was configured during the scan. - Configuration *ReportingConfiguration `json:"configuration"` - - // A reference used to locate the descriptor whose configuration was overridden. - Descriptor *ReportingDescriptorReference `json:"descriptor"` - - // Key/value pairs that provide additional information about the configuration override. - Properties *PropertyBag `json:"properties,omitempty"` -} - -// Conversion Describes how a converter transformed the output of a static analysis tool from the analysis tool's native output format into the SARIF format. -type Conversion struct { - - // The locations of the analysis tool's per-run log files. - AnalysisToolLogFiles []*ArtifactLocation `json:"analysisToolLogFiles,omitempty"` - - // An invocation object that describes the invocation of the converter. - Invocation *Invocation `json:"invocation,omitempty"` - - // Key/value pairs that provide additional information about the conversion. - Properties *PropertyBag `json:"properties,omitempty"` - - // A tool object that describes the converter. - Tool *Tool `json:"tool"` -} - -// Edge Represents a directed edge in a graph. -type Edge struct { - - // A string that uniquely identifies the edge within its graph. - Id string `json:"id"` - - // A short description of the edge. - Label *Message `json:"label,omitempty"` - - // Key/value pairs that provide additional information about the edge. - Properties *PropertyBag `json:"properties,omitempty"` - - // Identifies the source node (the node at which the edge starts). - SourceNodeId string `json:"sourceNodeId"` - - // Identifies the target node (the node at which the edge ends). - TargetNodeId string `json:"targetNodeId"` -} - -// EdgeTraversal Represents the traversal of a single edge during a graph traversal. -type EdgeTraversal struct { - - // Identifies the edge being traversed. - EdgeId string `json:"edgeId"` - - // The values of relevant expressions after the edge has been traversed. - FinalState map[string]*MultiformatMessageString `json:"finalState,omitempty"` - - // A message to display to the user as the edge is traversed. - Message *Message `json:"message,omitempty"` - - // Key/value pairs that provide additional information about the edge traversal. - Properties *PropertyBag `json:"properties,omitempty"` - - // The number of edge traversals necessary to return from a nested graph. - StepOverEdgeCount int `json:"stepOverEdgeCount,omitempty"` -} - -// Exception Describes a runtime exception encountered during the execution of an analysis tool. -type Exception struct { - - // An array of exception objects each of which is considered a cause of this exception. - InnerExceptions []*Exception `json:"innerExceptions,omitempty"` - - // A string that identifies the kind of exception, for example, the fully qualified type name of an object that was thrown, or the symbolic name of a signal. - Kind string `json:"kind,omitempty"` - - // A message that describes the exception. - Message string `json:"message,omitempty"` - - // Key/value pairs that provide additional information about the exception. - Properties *PropertyBag `json:"properties,omitempty"` - - // The sequence of function calls leading to the exception. - Stack *Stack `json:"stack,omitempty"` -} - -// ExternalProperties The top-level element of an external property file. -type ExternalProperties struct { - - // Addresses that will be merged with a separate run. - Addresses []*Address `json:"addresses,omitempty"` - - // An array of artifact objects that will be merged with a separate run. - Artifacts []*Artifact `json:"artifacts,omitempty"` - - // A conversion object that will be merged with a separate run. - Conversion *Conversion `json:"conversion,omitempty"` - - // The analysis tool object that will be merged with a separate run. - Driver *ToolComponent `json:"driver,omitempty"` - - // Tool extensions that will be merged with a separate run. - Extensions []*ToolComponent `json:"extensions,omitempty"` - - // Key/value pairs that provide additional information that will be merged with a separate run. - ExternalizedProperties *PropertyBag `json:"externalizedProperties,omitempty"` - - // An array of graph objects that will be merged with a separate run. - Graphs []*Graph `json:"graphs,omitempty"` - - // A stable, unique identifer for this external properties object, in the form of a GUID. - Guid string `json:"guid,omitempty"` - - // Describes the invocation of the analysis tool that will be merged with a separate run. - Invocations []*Invocation `json:"invocations,omitempty"` - - // An array of logical locations such as namespaces, types or functions that will be merged with a separate run. - LogicalLocations []*LogicalLocation `json:"logicalLocations,omitempty"` - - // Tool policies that will be merged with a separate run. - Policies []*ToolComponent `json:"policies,omitempty"` - - // Key/value pairs that provide additional information about the external properties. - Properties *PropertyBag `json:"properties,omitempty"` - - // An array of result objects that will be merged with a separate run. - Results []*Result `json:"results,omitempty"` - - // A stable, unique identifer for the run associated with this external properties object, in the form of a GUID. - RunGuid string `json:"runGuid,omitempty"` - - // The URI of the JSON schema corresponding to the version of the external property file format. - Schema string `json:"schema,omitempty"` - - // Tool taxonomies that will be merged with a separate run. - Taxonomies []*ToolComponent `json:"taxonomies,omitempty"` - - // An array of threadFlowLocation objects that will be merged with a separate run. - ThreadFlowLocations []*ThreadFlowLocation `json:"threadFlowLocations,omitempty"` - - // Tool translations that will be merged with a separate run. - Translations []*ToolComponent `json:"translations,omitempty"` - - // The SARIF format version of this external properties object. - Version interface{} `json:"version,omitempty"` - - // Requests that will be merged with a separate run. - WebRequests []*WebRequest `json:"webRequests,omitempty"` - - // Responses that will be merged with a separate run. - WebResponses []*WebResponse `json:"webResponses,omitempty"` -} - -// ExternalPropertyFileReference Contains information that enables a SARIF consumer to locate the external property file that contains the value of an externalized property associated with the run. -type ExternalPropertyFileReference struct { - - // A stable, unique identifer for the external property file in the form of a GUID. - Guid string `json:"guid,omitempty"` - - // A non-negative integer specifying the number of items contained in the external property file. - ItemCount int `json:"itemCount,omitempty"` - - // The location of the external property file. - Location *ArtifactLocation `json:"location,omitempty"` - - // Key/value pairs that provide additional information about the external property file. - Properties *PropertyBag `json:"properties,omitempty"` -} - -// ExternalPropertyFileReferences References to external property files that should be inlined with the content of a root log file. -type ExternalPropertyFileReferences struct { - - // An array of external property files containing run.addresses arrays to be merged with the root log file. - Addresses []*ExternalPropertyFileReference `json:"addresses,omitempty"` - - // An array of external property files containing run.artifacts arrays to be merged with the root log file. - Artifacts []*ExternalPropertyFileReference `json:"artifacts,omitempty"` - - // An external property file containing a run.conversion object to be merged with the root log file. - Conversion *ExternalPropertyFileReference `json:"conversion,omitempty"` - - // An external property file containing a run.driver object to be merged with the root log file. - Driver *ExternalPropertyFileReference `json:"driver,omitempty"` - - // An array of external property files containing run.extensions arrays to be merged with the root log file. - Extensions []*ExternalPropertyFileReference `json:"extensions,omitempty"` - - // An external property file containing a run.properties object to be merged with the root log file. - ExternalizedProperties *ExternalPropertyFileReference `json:"externalizedProperties,omitempty"` - - // An array of external property files containing a run.graphs object to be merged with the root log file. - Graphs []*ExternalPropertyFileReference `json:"graphs,omitempty"` - - // An array of external property files containing run.invocations arrays to be merged with the root log file. - Invocations []*ExternalPropertyFileReference `json:"invocations,omitempty"` - - // An array of external property files containing run.logicalLocations arrays to be merged with the root log file. - LogicalLocations []*ExternalPropertyFileReference `json:"logicalLocations,omitempty"` - - // An array of external property files containing run.policies arrays to be merged with the root log file. - Policies []*ExternalPropertyFileReference `json:"policies,omitempty"` - - // Key/value pairs that provide additional information about the external property files. - Properties *PropertyBag `json:"properties,omitempty"` - - // An array of external property files containing run.results arrays to be merged with the root log file. - Results []*ExternalPropertyFileReference `json:"results,omitempty"` - - // An array of external property files containing run.taxonomies arrays to be merged with the root log file. - Taxonomies []*ExternalPropertyFileReference `json:"taxonomies,omitempty"` - - // An array of external property files containing run.threadFlowLocations arrays to be merged with the root log file. - ThreadFlowLocations []*ExternalPropertyFileReference `json:"threadFlowLocations,omitempty"` - - // An array of external property files containing run.translations arrays to be merged with the root log file. - Translations []*ExternalPropertyFileReference `json:"translations,omitempty"` - - // An array of external property files containing run.requests arrays to be merged with the root log file. - WebRequests []*ExternalPropertyFileReference `json:"webRequests,omitempty"` - - // An array of external property files containing run.responses arrays to be merged with the root log file. - WebResponses []*ExternalPropertyFileReference `json:"webResponses,omitempty"` -} - -// Fix A proposed fix for the problem represented by a result object. -// A fix specifies a set of artifacts to modify. For each artifact, -// it specifies a set of bytes to remove, and provides a set of new bytes to replace them. -type Fix struct { - - // One or more artifact changes that comprise a fix for a result. - ArtifactChanges []*ArtifactChange `json:"artifactChanges"` - - // A message that describes the proposed fix, enabling viewers to present the proposed change to an end user. - Description *Message `json:"description,omitempty"` - - // Key/value pairs that provide additional information about the fix. - Properties *PropertyBag `json:"properties,omitempty"` -} - -// Graph A network of nodes and directed edges that describes some aspect of the -// structure of the code (for example, a call graph). -type Graph struct { - - // A description of the graph. - Description *Message `json:"description,omitempty"` - - // An array of edge objects representing the edges of the graph. - Edges []*Edge `json:"edges,omitempty"` - - // An array of node objects representing the nodes of the graph. - Nodes []*Node `json:"nodes,omitempty"` - - // Key/value pairs that provide additional information about the graph. - Properties *PropertyBag `json:"properties,omitempty"` -} - -// GraphTraversal Represents a path through a graph. -type GraphTraversal struct { - - // A description of this graph traversal. - Description *Message `json:"description,omitempty"` - - // The sequences of edges traversed by this graph traversal. - EdgeTraversals []*EdgeTraversal `json:"edgeTraversals,omitempty"` - - // Values of relevant expressions at the start of the graph traversal that remain constant for the graph traversal. - ImmutableState map[string]*MultiformatMessageString `json:"immutableState,omitempty"` - - // Values of relevant expressions at the start of the graph traversal that may change during graph traversal. - InitialState map[string]*MultiformatMessageString `json:"initialState,omitempty"` - - // Key/value pairs that provide additional information about the graph traversal. - Properties *PropertyBag `json:"properties,omitempty"` - - // The index within the result.graphs to be associated with the result. - ResultGraphIndex int `json:"resultGraphIndex,omitempty"` - - // The index within the run.graphs to be associated with the result. - RunGraphIndex int `json:"runGraphIndex,omitempty"` -} - -// Invocation The runtime environment of the analysis tool run. -type Invocation struct { - - // The account under which the invocation occurred. - Account string `json:"account,omitempty"` - - // An array of strings, containing in order the command line arguments passed to the tool from the operating system. - Arguments []string `json:"arguments,omitempty"` - - // The command line used to invoke the tool. - CommandLine string `json:"commandLine,omitempty"` - - // The Coordinated Universal Time (UTC) date and time at which the invocation ended. See "Date/time properties" in the SARIF spec for the required format. - EndTimeUtc string `json:"endTimeUtc,omitempty"` - - // The environment variables associated with the analysis tool process, expressed as key/value pairs. - EnvironmentVariables map[string]string `json:"environmentVariables,omitempty"` - - // An absolute URI specifying the location of the executable that was invoked. - ExecutableLocation *ArtifactLocation `json:"executableLocation,omitempty"` - - // Specifies whether the tool's execution completed successfully. - ExecutionSuccessful bool `json:"executionSuccessful"` - - // The process exit code. - ExitCode int `json:"exitCode,omitempty"` - - // The reason for the process exit. - ExitCodeDescription string `json:"exitCodeDescription,omitempty"` - - // The name of the signal that caused the process to exit. - ExitSignalName string `json:"exitSignalName,omitempty"` - - // The numeric value of the signal that caused the process to exit. - ExitSignalNumber int `json:"exitSignalNumber,omitempty"` - - // The machine on which the invocation occurred. - Machine string `json:"machine,omitempty"` - - // An array of configurationOverride objects that describe notifications related runtime overrides. - NotificationConfigurationOverrides []*ConfigurationOverride `json:"notificationConfigurationOverrides,omitempty"` - - // The id of the process in which the invocation occurred. - ProcessId int `json:"processId,omitempty"` - - // The reason given by the operating system that the process failed to start. - ProcessStartFailureMessage string `json:"processStartFailureMessage,omitempty"` - - // Key/value pairs that provide additional information about the invocation. - Properties *PropertyBag `json:"properties,omitempty"` - - // The locations of any response files specified on the tool's command line. - ResponseFiles []*ArtifactLocation `json:"responseFiles,omitempty"` - - // An array of configurationOverride objects that describe rules related runtime overrides. - RuleConfigurationOverrides []*ConfigurationOverride `json:"ruleConfigurationOverrides,omitempty"` - - // The Coordinated Universal Time (UTC) date and time at which the invocation started. See "Date/time properties" in the SARIF spec for the required format. - StartTimeUtc string `json:"startTimeUtc,omitempty"` - - // A file containing the standard error stream from the process that was invoked. - Stderr *ArtifactLocation `json:"stderr,omitempty"` - - // A file containing the standard input stream to the process that was invoked. - Stdin *ArtifactLocation `json:"stdin,omitempty"` - - // A file containing the standard output stream from the process that was invoked. - Stdout *ArtifactLocation `json:"stdout,omitempty"` - - // A file containing the interleaved standard output and standard error stream from the process that was invoked. - StdoutStderr *ArtifactLocation `json:"stdoutStderr,omitempty"` - - // A list of conditions detected by the tool that are relevant to the tool's configuration. - ToolConfigurationNotifications []*Notification `json:"toolConfigurationNotifications,omitempty"` - - // A list of runtime conditions detected by the tool during the analysis. - ToolExecutionNotifications []*Notification `json:"toolExecutionNotifications,omitempty"` - - // The working directory for the invocation. - WorkingDirectory *ArtifactLocation `json:"workingDirectory,omitempty"` -} - -// Location A location within a programming artifact. -type Location struct { - - // A set of regions relevant to the location. - Annotations []*Region `json:"annotations,omitempty"` - - // Value that distinguishes this location from all other locations within a single result object. - Id int `json:"id,omitempty"` - - // The logical locations associated with the result. - LogicalLocations []*LogicalLocation `json:"logicalLocations,omitempty"` - - // A message relevant to the location. - Message *Message `json:"message,omitempty"` - - // Identifies the artifact and region. - PhysicalLocation *PhysicalLocation `json:"physicalLocation,omitempty"` - - // Key/value pairs that provide additional information about the location. - Properties *PropertyBag `json:"properties,omitempty"` - - // An array of objects that describe relationships between this location and others. - Relationships []*LocationRelationship `json:"relationships,omitempty"` -} - -// LocationRelationship Information about the relation of one location to another. -type LocationRelationship struct { - - // A description of the location relationship. - Description *Message `json:"description,omitempty"` - - // A set of distinct strings that categorize the relationship. Well-known kinds include 'includes', 'isIncludedBy' and 'relevant'. - Kinds []string `json:"kinds,omitempty"` - - // Key/value pairs that provide additional information about the location relationship. - Properties *PropertyBag `json:"properties,omitempty"` - - // A reference to the related location. - Target int `json:"target"` -} - -// LogFile Static Analysis Results Format (SARIF) Version 2.1.0 JSON Schema. -type LogFile struct { - - // References to external property files that share data between runs. - InlineExternalProperties []*ExternalProperties `json:"inlineExternalProperties,omitempty"` - - // Key/value pairs that provide additional information about the log file. - Properties *PropertyBag `json:"properties,omitempty"` - - // The set of runs contained in this log file. - Runs []*Run `json:"runs"` - - // The URI of the JSON schema corresponding to the version. - Schema string `json:"$schema,omitempty"` - - // The SARIF format version of this log file. - Version interface{} `json:"version"` -} - -// LogicalLocation A logical location of a construct that produced a result. -type LogicalLocation struct { - - // The machine-readable name for the logical location, such as a mangled function name provided by a C++ compiler that encodes calling convention, return type and other details along with the function name. - DecoratedName string `json:"decoratedName,omitempty"` - - // The human-readable fully qualified name of the logical location. - FullyQualifiedName string `json:"fullyQualifiedName,omitempty"` - - // The index within the logical locations array. - Index int `json:"index,omitempty"` - - // The type of construct this logical location component refers to. Should be one of 'function', 'member', 'module', 'namespace', 'parameter', 'resource', 'returnType', 'type', 'variable', 'object', 'array', 'property', 'value', 'element', 'text', 'attribute', 'comment', 'declaration', 'dtd' or 'processingInstruction', if any of those accurately describe the construct. - Kind string `json:"kind,omitempty"` - - // Identifies the construct in which the result occurred. For example, this property might contain the name of a class or a method. - Name string `json:"name,omitempty"` - - // Identifies the index of the immediate parent of the construct in which the result was detected. For example, this property might point to a logical location that represents the namespace that holds a type. - ParentIndex int `json:"parentIndex,omitempty"` - - // Key/value pairs that provide additional information about the logical location. - Properties *PropertyBag `json:"properties,omitempty"` -} - -// Message Encapsulates a message intended to be read by the end user. -type Message struct { - - // An array of strings to substitute into the message string. - Arguments []string `json:"arguments,omitempty"` - - // The identifier for this message. - Id string `json:"id,omitempty"` - - // A Markdown message string. - Markdown string `json:"markdown,omitempty"` - - // Key/value pairs that provide additional information about the message. - Properties *PropertyBag `json:"properties,omitempty"` - - // A plain text message string. - Text string `json:"text,omitempty"` -} - -// MultiformatMessageString A message string or message format string rendered in multiple formats. -type MultiformatMessageString struct { - - // A Markdown message string or format string. - Markdown string `json:"markdown,omitempty"` - - // Key/value pairs that provide additional information about the message. - Properties *PropertyBag `json:"properties,omitempty"` - - // A plain text message string or format string. - Text string `json:"text"` -} - -// Node Represents a node in a graph. -type Node struct { - - // Array of child nodes. - Children []*Node `json:"children,omitempty"` - - // A string that uniquely identifies the node within its graph. - Id string `json:"id"` - - // A short description of the node. - Label *Message `json:"label,omitempty"` - - // A code location associated with the node. - Location *Location `json:"location,omitempty"` - - // Key/value pairs that provide additional information about the node. - Properties *PropertyBag `json:"properties,omitempty"` -} - -// Notification Describes a condition relevant to the tool itself, as opposed to being relevant to a target being analyzed by the tool. -type Notification struct { - - // A reference used to locate the rule descriptor associated with this notification. - AssociatedRule *ReportingDescriptorReference `json:"associatedRule,omitempty"` - - // A reference used to locate the descriptor relevant to this notification. - Descriptor *ReportingDescriptorReference `json:"descriptor,omitempty"` - - // The runtime exception, if any, relevant to this notification. - Exception *Exception `json:"exception,omitempty"` - - // A value specifying the severity level of the notification. - Level interface{} `json:"level,omitempty"` - - // The locations relevant to this notification. - Locations []*Location `json:"locations,omitempty"` - - // A message that describes the condition that was encountered. - Message *Message `json:"message"` - - // Key/value pairs that provide additional information about the notification. - Properties *PropertyBag `json:"properties,omitempty"` - - // The thread identifier of the code that generated the notification. - ThreadId int `json:"threadId,omitempty"` - - // The Coordinated Universal Time (UTC) date and time at which the analysis tool generated the notification. - TimeUtc string `json:"timeUtc,omitempty"` -} - -// PhysicalLocation A physical location relevant to a result. Specifies a reference to a programming artifact together with a range of bytes or characters within that artifact. -type PhysicalLocation struct { - - // The address of the location. - Address *Address `json:"address,omitempty"` - - // The location of the artifact. - ArtifactLocation *ArtifactLocation `json:"artifactLocation,omitempty"` - - // Specifies a portion of the artifact that encloses the region. Allows a viewer to display additional context around the region. - ContextRegion *Region `json:"contextRegion,omitempty"` - - // Key/value pairs that provide additional information about the physical location. - Properties *PropertyBag `json:"properties,omitempty"` - - // Specifies a portion of the artifact. - Region *Region `json:"region,omitempty"` -} - -type PropertyBag map[string]interface{} - -/* -// PropertyBag Key/value pairs that provide additional information about the object. -type PropertyBag struct { - AdditionalProperties map[string]interface{} `json:"-,omitempty"` - - // A set of distinct strings that provide additional information. - Tags []string `json:"tags,omitempty"` -} -*/ -// Rectangle An area within an image. -type Rectangle struct { - - // The Y coordinate of the bottom edge of the rectangle, measured in the image's natural units. - Bottom float64 `json:"bottom,omitempty"` - - // The X coordinate of the left edge of the rectangle, measured in the image's natural units. - Left float64 `json:"left,omitempty"` - - // A message relevant to the rectangle. - Message *Message `json:"message,omitempty"` - - // Key/value pairs that provide additional information about the rectangle. - Properties *PropertyBag `json:"properties,omitempty"` - - // The X coordinate of the right edge of the rectangle, measured in the image's natural units. - Right float64 `json:"right,omitempty"` - - // The Y coordinate of the top edge of the rectangle, measured in the image's natural units. - Top float64 `json:"top,omitempty"` -} - -// Region A region within an artifact where a result was detected. -type Region struct { - - // The length of the region in bytes. - ByteLength int `json:"byteLength,omitempty"` - - // The zero-based offset from the beginning of the artifact of the first byte in the region. - ByteOffset int `json:"byteOffset,omitempty"` - - // The length of the region in characters. - CharLength int `json:"charLength,omitempty"` - - // The zero-based offset from the beginning of the artifact of the first character in the region. - CharOffset int `json:"charOffset,omitempty"` - - // The column number of the character following the end of the region. - EndColumn int `json:"endColumn,omitempty"` - - // The line number of the last character in the region. - EndLine int `json:"endLine,omitempty"` - - // A message relevant to the region. - Message *Message `json:"message,omitempty"` - - // Key/value pairs that provide additional information about the region. - Properties *PropertyBag `json:"properties,omitempty"` - - // The portion of the artifact contents within the specified region. - Snippet *ArtifactContent `json:"snippet,omitempty"` - - // Specifies the source language, if any, of the portion of the artifact specified by the region object. - SourceLanguage string `json:"sourceLanguage,omitempty"` - - // The column number of the first character in the region. - StartColumn int `json:"startColumn,omitempty"` - - // The line number of the first character in the region. - StartLine int `json:"startLine,omitempty"` -} - -// Replacement The replacement of a single region of an artifact. -type Replacement struct { - - // The region of the artifact to delete. - DeletedRegion *Region `json:"deletedRegion"` - - // The content to insert at the location specified by the 'deletedRegion' property. - InsertedContent *ArtifactContent `json:"insertedContent,omitempty"` - - // Key/value pairs that provide additional information about the replacement. - Properties *PropertyBag `json:"properties,omitempty"` -} - -// ReportingConfiguration Information about a rule or notification that can be configured at runtime. -type ReportingConfiguration struct { - - // Specifies whether the report may be produced during the scan. - Enabled bool `json:"enabled,omitempty"` - - // Specifies the failure level for the report. - Level interface{} `json:"level,omitempty"` - - // Contains configuration information specific to a report. - Parameters *PropertyBag `json:"parameters,omitempty"` - - // Key/value pairs that provide additional information about the reporting configuration. - Properties *PropertyBag `json:"properties,omitempty"` - - // Specifies the relative priority of the report. Used for analysis output only. - Rank float64 `json:"rank,omitempty"` -} - -// ReportingDescriptor Metadata that describes a specific report produced by the tool, as part of the analysis it provides or its runtime reporting. -type ReportingDescriptor struct { - - // Default reporting configuration information. - DefaultConfiguration *ReportingConfiguration `json:"defaultConfiguration,omitempty"` - - // An array of unique identifies in the form of a GUID by which this report was known in some previous version of the analysis tool. - DeprecatedGuids []string `json:"deprecatedGuids,omitempty"` - - // An array of stable, opaque identifiers by which this report was known in some previous version of the analysis tool. - DeprecatedIds []string `json:"deprecatedIds,omitempty"` - - // An array of readable identifiers by which this report was known in some previous version of the analysis tool. - DeprecatedNames []string `json:"deprecatedNames,omitempty"` - - // A description of the report. Should, as far as possible, provide details sufficient to enable resolution of any problem indicated by the result. - FullDescription *MultiformatMessageString `json:"fullDescription,omitempty"` - - // A unique identifer for the reporting descriptor in the form of a GUID. - Guid string `json:"guid,omitempty"` - - // Provides the primary documentation for the report, useful when there is no online documentation. - Help *MultiformatMessageString `json:"help,omitempty"` - - // A URI where the primary documentation for the report can be found. - HelpUri string `json:"helpUri,omitempty"` - - // A stable, opaque identifier for the report. - Id string `json:"id"` - - // A set of name/value pairs with arbitrary names. Each value is a multiformatMessageString object, which holds message strings in plain text and (optionally) Markdown format. The strings can include placeholders, which can be used to construct a message in combination with an arbitrary number of additional string arguments. - MessageStrings map[string]*MultiformatMessageString `json:"messageStrings,omitempty"` - - // A report identifier that is understandable to an end user. - Name string `json:"name,omitempty"` - - // Key/value pairs that provide additional information about the report. - Properties *PropertyBag `json:"properties,omitempty"` - - // An array of objects that describe relationships between this reporting descriptor and others. - Relationships []*ReportingDescriptorRelationship `json:"relationships,omitempty"` - - // A concise description of the report. Should be a single sentence that is understandable when visible space is limited to a single line of text. - ShortDescription *MultiformatMessageString `json:"shortDescription,omitempty"` -} - -// ReportingDescriptorReference Information about how to locate a relevant reporting descriptor. -type ReportingDescriptorReference struct { - - // A guid that uniquely identifies the descriptor. - Guid string `json:"guid,omitempty"` - - // The id of the descriptor. - Id string `json:"id,omitempty"` - - // The index into an array of descriptors in toolComponent.ruleDescriptors, toolComponent.notificationDescriptors, or toolComponent.taxonomyDescriptors, depending on context. - Index int `json:"index,omitempty"` - - // Key/value pairs that provide additional information about the reporting descriptor reference. - Properties *PropertyBag `json:"properties,omitempty"` - - // A reference used to locate the toolComponent associated with the descriptor. - ToolComponent *ToolComponentReference `json:"toolComponent,omitempty"` -} - -// ReportingDescriptorRelationship Information about the relation of one reporting descriptor to another. -type ReportingDescriptorRelationship struct { - - // A description of the reporting descriptor relationship. - Description *Message `json:"description,omitempty"` - - // A set of distinct strings that categorize the relationship. Well-known kinds include 'canPrecede', 'canFollow', 'willPrecede', 'willFollow', 'superset', 'subset', 'equal', 'disjoint', 'relevant', and 'incomparable'. - Kinds []string `json:"kinds,omitempty"` - - // Key/value pairs that provide additional information about the reporting descriptor reference. - Properties *PropertyBag `json:"properties,omitempty"` - - // A reference to the related reporting descriptor. - Target *ReportingDescriptorReference `json:"target"` -} - -// Result A result produced by an analysis tool. -type Result struct { - - // Identifies the artifact that the analysis tool was instructed to scan. This need not be the same as the artifact where the result actually occurred. - AnalysisTarget *ArtifactLocation `json:"analysisTarget,omitempty"` - - // A set of artifacts relevant to the result. - Attachments []*Attachment `json:"attachments,omitempty"` - - // The state of a result relative to a baseline of a previous run. - BaselineState interface{} `json:"baselineState,omitempty"` - - // An array of 'codeFlow' objects relevant to the result. - CodeFlows []*CodeFlow `json:"codeFlows,omitempty"` - - // A stable, unique identifier for the equivalence class of logically identical results to which this result belongs, in the form of a GUID. - CorrelationGuid string `json:"correlationGuid,omitempty"` - - // A set of strings each of which individually defines a stable, unique identity for the result. - Fingerprints map[string]string `json:"fingerprints,omitempty"` - - // An array of 'fix' objects, each of which represents a proposed fix to the problem indicated by the result. - Fixes []*Fix `json:"fixes,omitempty"` - - // An array of one or more unique 'graphTraversal' objects. - GraphTraversals []*GraphTraversal `json:"graphTraversals,omitempty"` - - // An array of zero or more unique graph objects associated with the result. - Graphs []*Graph `json:"graphs,omitempty"` - - // A stable, unique identifer for the result in the form of a GUID. - Guid string `json:"guid,omitempty"` - - // An absolute URI at which the result can be viewed. - HostedViewerUri string `json:"hostedViewerUri,omitempty"` - - // A value that categorizes results by evaluation state. - Kind interface{} `json:"kind,omitempty"` - - // A value specifying the severity level of the result. - Level interface{} `json:"level,omitempty"` - - // The set of locations where the result was detected. Specify only one location unless the problem indicated by the result can only be corrected by making a change at every specified location. - Locations []*Location `json:"locations,omitempty"` - - // A message that describes the result. The first sentence of the message only will be displayed when visible space is limited. - Message *Message `json:"message"` - - // A positive integer specifying the number of times this logically unique result was observed in this run. - OccurrenceCount int `json:"occurrenceCount,omitempty"` - - // A set of strings that contribute to the stable, unique identity of the result. - PartialFingerprints map[string]string `json:"partialFingerprints,omitempty"` - - // Key/value pairs that provide additional information about the result. - Properties *PropertyBag `json:"properties,omitempty"` - - // Information about how and when the result was detected. - Provenance *ResultProvenance `json:"provenance,omitempty"` - - // A number representing the priority or importance of the result. - Rank float64 `json:"rank,omitempty"` - - // A set of locations relevant to this result. - RelatedLocations []*Location `json:"relatedLocations,omitempty"` - - // A reference used to locate the rule descriptor relevant to this result. - Rule *ReportingDescriptorReference `json:"rule,omitempty"` - - // The stable, unique identifier of the rule, if any, to which this result is relevant. - RuleId string `json:"ruleId,omitempty"` - - // The index within the tool component rules array of the rule object associated with this result. - RuleIndex int `json:"ruleIndex,omitempty"` - - // An array of 'stack' objects relevant to the result. - Stacks []*Stack `json:"stacks,omitempty"` - - // A set of suppressions relevant to this result. - Suppressions []*Suppression `json:"suppressions,omitempty"` - - // An array of references to taxonomy reporting descriptors that are applicable to the result. - Taxa []*ReportingDescriptorReference `json:"taxa,omitempty"` - - // A web request associated with this result. - WebRequest *WebRequest `json:"webRequest,omitempty"` - - // A web response associated with this result. - WebResponse *WebResponse `json:"webResponse,omitempty"` - - // The URIs of the work items associated with this result. - WorkItemUris []string `json:"workItemUris,omitempty"` -} - -// ResultProvenance Contains information about how and when a result was detected. -type ResultProvenance struct { - - // An array of physicalLocation objects which specify the portions of an analysis tool's output that a converter transformed into the result. - ConversionSources []*PhysicalLocation `json:"conversionSources,omitempty"` - - // A GUID-valued string equal to the automationDetails.guid property of the run in which the result was first detected. - FirstDetectionRunGuid string `json:"firstDetectionRunGuid,omitempty"` - - // The Coordinated Universal Time (UTC) date and time at which the result was first detected. See "Date/time properties" in the SARIF spec for the required format. - FirstDetectionTimeUtc string `json:"firstDetectionTimeUtc,omitempty"` - - // The index within the run.invocations array of the invocation object which describes the tool invocation that detected the result. - InvocationIndex int `json:"invocationIndex,omitempty"` - - // A GUID-valued string equal to the automationDetails.guid property of the run in which the result was most recently detected. - LastDetectionRunGuid string `json:"lastDetectionRunGuid,omitempty"` - - // The Coordinated Universal Time (UTC) date and time at which the result was most recently detected. See "Date/time properties" in the SARIF spec for the required format. - LastDetectionTimeUtc string `json:"lastDetectionTimeUtc,omitempty"` - - // Key/value pairs that provide additional information about the result. - Properties *PropertyBag `json:"properties,omitempty"` -} - -// Run Describes a single run of an analysis tool, and contains the reported output of that run. -type Run struct { - - // Addresses associated with this run instance, if any. - Addresses []*Address `json:"addresses,omitempty"` - - // An array of artifact objects relevant to the run. - Artifacts []*Artifact `json:"artifacts,omitempty"` - - // Automation details that describe this run. - AutomationDetails *RunAutomationDetails `json:"automationDetails,omitempty"` - - // The 'guid' property of a previous SARIF 'run' that comprises the baseline that was used to compute result 'baselineState' properties for the run. - BaselineGuid string `json:"baselineGuid,omitempty"` - - // Specifies the unit in which the tool measures columns. - ColumnKind interface{} `json:"columnKind,omitempty"` - - // A conversion object that describes how a converter transformed an analysis tool's native reporting format into the SARIF format. - Conversion *Conversion `json:"conversion,omitempty"` - - // Specifies the default encoding for any artifact object that refers to a text file. - DefaultEncoding string `json:"defaultEncoding,omitempty"` - - // Specifies the default source language for any artifact object that refers to a text file that contains source code. - DefaultSourceLanguage string `json:"defaultSourceLanguage,omitempty"` - - // References to external property files that should be inlined with the content of a root log file. - ExternalPropertyFileReferences *ExternalPropertyFileReferences `json:"externalPropertyFileReferences,omitempty"` - - // An array of zero or more unique graph objects associated with the run. - Graphs []*Graph `json:"graphs,omitempty"` - - // Describes the invocation of the analysis tool. - Invocations []*Invocation `json:"invocations,omitempty"` - - // The language of the messages emitted into the log file during this run (expressed as an ISO 639-1 two-letter lowercase culture code) and an optional region (expressed as an ISO 3166-1 two-letter uppercase subculture code associated with a country or region). The casing is recommended but not required (in order for this data to conform to RFC5646). - Language string `json:"language,omitempty"` - - // An array of logical locations such as namespaces, types or functions. - LogicalLocations []*LogicalLocation `json:"logicalLocations,omitempty"` - - // An ordered list of character sequences that were treated as line breaks when computing region information for the run. - NewlineSequences []string `json:"newlineSequences,omitempty"` - - // The artifact location specified by each uriBaseId symbol on the machine where the tool originally ran. - OriginalUriBaseIds map[string]*ArtifactLocation `json:"originalUriBaseIds,omitempty"` - - // Contains configurations that may potentially override both reportingDescriptor.defaultConfiguration (the tool's default severities) and invocation.configurationOverrides (severities established at run-time from the command line). - Policies []*ToolComponent `json:"policies,omitempty"` - - // Key/value pairs that provide additional information about the run. - Properties *PropertyBag `json:"properties,omitempty"` - - // An array of strings used to replace sensitive information in a redaction-aware property. - RedactionTokens []string `json:"redactionTokens,omitempty"` - - // The set of results contained in an SARIF log. The results array can be omitted when a run is solely exporting rules metadata. It must be present (but may be empty) if a log file represents an actual scan. - Results []*Result `json:"results,omitempty"` - - // Automation details that describe the aggregate of runs to which this run belongs. - RunAggregates []*RunAutomationDetails `json:"runAggregates,omitempty"` - - // A specialLocations object that defines locations of special significance to SARIF consumers. - SpecialLocations *SpecialLocations `json:"specialLocations,omitempty"` - - // An array of toolComponent objects relevant to a taxonomy in which results are categorized. - Taxonomies []*ToolComponent `json:"taxonomies,omitempty"` - - // An array of threadFlowLocation objects cached at run level. - ThreadFlowLocations []*ThreadFlowLocation `json:"threadFlowLocations,omitempty"` - - // Information about the tool or tool pipeline that generated the results in this run. A run can only contain results produced by a single tool or tool pipeline. A run can aggregate results from multiple log files, as long as context around the tool run (tool command-line arguments and the like) is identical for all aggregated files. - Tool *Tool `json:"tool"` - - // The set of available translations of the localized data provided by the tool. - Translations []*ToolComponent `json:"translations,omitempty"` - - // Specifies the revision in version control of the artifacts that were scanned. - VersionControlProvenance []*VersionControlDetails `json:"versionControlProvenance,omitempty"` - - // An array of request objects cached at run level. - WebRequests []*WebRequest `json:"webRequests,omitempty"` - - // An array of response objects cached at run level. - WebResponses []*WebResponse `json:"webResponses,omitempty"` -} - -// RunAutomationDetails Information that describes a run's identity and role within an engineering system process. -type RunAutomationDetails struct { - - // A stable, unique identifier for the equivalence class of runs to which this object's containing run object belongs in the form of a GUID. - CorrelationGuid string `json:"correlationGuid,omitempty"` - - // A description of the identity and role played within the engineering system by this object's containing run object. - Description *Message `json:"description,omitempty"` - - // A stable, unique identifer for this object's containing run object in the form of a GUID. - Guid string `json:"guid,omitempty"` - - // A hierarchical string that uniquely identifies this object's containing run object. - Id string `json:"id,omitempty"` - - // Key/value pairs that provide additional information about the run automation details. - Properties *PropertyBag `json:"properties,omitempty"` -} - -// SpecialLocations Defines locations of special significance to SARIF consumers. -type SpecialLocations struct { - - // Provides a suggestion to SARIF consumers to display file paths relative to the specified location. - DisplayBase *ArtifactLocation `json:"displayBase,omitempty"` - - // Key/value pairs that provide additional information about the special locations. - Properties *PropertyBag `json:"properties,omitempty"` -} - -// Stack A call stack that is relevant to a result. -type Stack struct { - - // An array of stack frames that represents a sequence of calls, rendered in reverse chronological order, that comprise the call stack. - Frames []*StackFrame `json:"frames"` - - // A message relevant to this call stack. - Message *Message `json:"message,omitempty"` - - // Key/value pairs that provide additional information about the stack. - Properties *PropertyBag `json:"properties,omitempty"` -} - -// StackFrame A function call within a stack trace. -type StackFrame struct { - - // The location to which this stack frame refers. - Location *Location `json:"location,omitempty"` - - // The name of the module that contains the code of this stack frame. - Module string `json:"module,omitempty"` - - // The parameters of the call that is executing. - Parameters []string `json:"parameters,omitempty"` - - // Key/value pairs that provide additional information about the stack frame. - Properties *PropertyBag `json:"properties,omitempty"` - - // The thread identifier of the stack frame. - ThreadId int `json:"threadId,omitempty"` -} - -// Suppression A suppression that is relevant to a result. -type Suppression struct { - - // A stable, unique identifer for the supression in the form of a GUID. - Guid string `json:"guid,omitempty"` - - // A string representing the justification for the suppression. - Justification string `json:"justification,omitempty"` - - // A string that indicates where the suppression is persisted. - Kind string `json:"kind"` - - // Identifies the location associated with the suppression. - Location *Location `json:"location,omitempty"` - - // Key/value pairs that provide additional information about the suppression. - Properties *PropertyBag `json:"properties,omitempty"` - - // A string that indicates the review status of the suppression. - Status interface{} `json:"status,omitempty"` -} - -// ThreadFlow Describes a sequence of code locations that specify a path through a single thread of execution such as an operating system or fiber. -type ThreadFlow struct { - - // An string that uniquely identifies the threadFlow within the codeFlow in which it occurs. - Id string `json:"id,omitempty"` - - // Values of relevant expressions at the start of the thread flow that remain constant. - ImmutableState map[string]*MultiformatMessageString `json:"immutableState,omitempty"` - - // Values of relevant expressions at the start of the thread flow that may change during thread flow execution. - InitialState map[string]*MultiformatMessageString `json:"initialState,omitempty"` - - // A temporally ordered array of 'threadFlowLocation' objects, each of which describes a location visited by the tool while producing the result. - Locations []*ThreadFlowLocation `json:"locations"` - - // A message relevant to the thread flow. - Message *Message `json:"message,omitempty"` - - // Key/value pairs that provide additional information about the thread flow. - Properties *PropertyBag `json:"properties,omitempty"` -} - -// ThreadFlowLocation A location visited by an analysis tool while simulating or monitoring the execution of a program. -type ThreadFlowLocation struct { - - // An integer representing the temporal order in which execution reached this location. - ExecutionOrder int `json:"executionOrder,omitempty"` - - // The Coordinated Universal Time (UTC) date and time at which this location was executed. - ExecutionTimeUtc string `json:"executionTimeUtc,omitempty"` - - // Specifies the importance of this location in understanding the code flow in which it occurs. The order from most to least important is "essential", "important", "unimportant". Default: "important". - Importance interface{} `json:"importance,omitempty"` - - // The index within the run threadFlowLocations array. - Index int `json:"index,omitempty"` - - // A set of distinct strings that categorize the thread flow location. Well-known kinds include 'acquire', 'release', 'enter', 'exit', 'call', 'return', 'branch', 'implicit', 'false', 'true', 'caution', 'danger', 'unknown', 'unreachable', 'taint', 'function', 'handler', 'lock', 'memory', 'resource', 'scope' and 'value'. - Kinds []string `json:"kinds,omitempty"` - - // The code location. - Location *Location `json:"location,omitempty"` - - // The name of the module that contains the code that is executing. - Module string `json:"module,omitempty"` - - // An integer representing a containment hierarchy within the thread flow. - NestingLevel int `json:"nestingLevel,omitempty"` - - // Key/value pairs that provide additional information about the threadflow location. - Properties *PropertyBag `json:"properties,omitempty"` - - // The call stack leading to this location. - Stack *Stack `json:"stack,omitempty"` - - // A dictionary, each of whose keys specifies a variable or expression, the associated value of which represents the variable or expression value. For an annotation of kind 'continuation', for example, this dictionary might hold the current assumed values of a set of global variables. - State map[string]*MultiformatMessageString `json:"state,omitempty"` - - // An array of references to rule or taxonomy reporting descriptors that are applicable to the thread flow location. - Taxa []*ReportingDescriptorReference `json:"taxa,omitempty"` - - // A web request associated with this thread flow location. - WebRequest *WebRequest `json:"webRequest,omitempty"` - - // A web response associated with this thread flow location. - WebResponse *WebResponse `json:"webResponse,omitempty"` -} - -// Tool The analysis tool that was run. -type Tool struct { - - // The analysis tool that was run. - Driver *ToolComponent `json:"driver"` - - // Tool extensions that contributed to or reconfigured the analysis tool that was run. - Extensions []*ToolComponent `json:"extensions,omitempty"` - - // Key/value pairs that provide additional information about the tool. - Properties *PropertyBag `json:"properties,omitempty"` -} - -// ToolComponent A component, such as a plug-in or the driver, of the analysis tool that was run. -type ToolComponent struct { - - // The component which is strongly associated with this component. For a translation, this refers to the component which has been translated. For an extension, this is the driver that provides the extension's plugin model. - AssociatedComponent *ToolComponentReference `json:"associatedComponent,omitempty"` - - // The kinds of data contained in this object. - Contents []interface{} `json:"contents,omitempty"` - - // The binary version of the tool component's primary executable file expressed as four non-negative integers separated by a period (for operating systems that express file versions in this way). - DottedQuadFileVersion string `json:"dottedQuadFileVersion,omitempty"` - - // The absolute URI from which the tool component can be downloaded. - DownloadUri string `json:"downloadUri,omitempty"` - - // A comprehensive description of the tool component. - FullDescription *MultiformatMessageString `json:"fullDescription,omitempty"` - - // The name of the tool component along with its version and any other useful identifying information, such as its locale. - FullName string `json:"fullName,omitempty"` - - // A dictionary, each of whose keys is a resource identifier and each of whose values is a multiformatMessageString object, which holds message strings in plain text and (optionally) Markdown format. The strings can include placeholders, which can be used to construct a message in combination with an arbitrary number of additional string arguments. - GlobalMessageStrings map[string]*MultiformatMessageString `json:"globalMessageStrings,omitempty"` - - // A unique identifer for the tool component in the form of a GUID. - Guid string `json:"guid,omitempty"` - - // The absolute URI at which information about this version of the tool component can be found. - InformationUri string `json:"informationUri,omitempty"` - - // Specifies whether this object contains a complete definition of the localizable and/or non-localizable data for this component, as opposed to including only data that is relevant to the results persisted to this log file. - IsComprehensive bool `json:"isComprehensive,omitempty"` - - // The language of the messages emitted into the log file during this run (expressed as an ISO 639-1 two-letter lowercase language code) and an optional region (expressed as an ISO 3166-1 two-letter uppercase subculture code associated with a country or region). The casing is recommended but not required (in order for this data to conform to RFC5646). - Language string `json:"language,omitempty"` - - // The semantic version of the localized strings defined in this component; maintained by components that provide translations. - LocalizedDataSemanticVersion string `json:"localizedDataSemanticVersion,omitempty"` - - // An array of the artifactLocation objects associated with the tool component. - Locations []*ArtifactLocation `json:"locations,omitempty"` - - // The minimum value of localizedDataSemanticVersion required in translations consumed by this component; used by components that consume translations. - MinimumRequiredLocalizedDataSemanticVersion string `json:"minimumRequiredLocalizedDataSemanticVersion,omitempty"` - - // The name of the tool component. - Name string `json:"name"` - - // An array of reportingDescriptor objects relevant to the notifications related to the configuration and runtime execution of the tool component. - Notifications []*ReportingDescriptor `json:"notifications,omitempty"` - - // The organization or company that produced the tool component. - Organization string `json:"organization,omitempty"` - - // A product suite to which the tool component belongs. - Product string `json:"product,omitempty"` - - // A localizable string containing the name of the suite of products to which the tool component belongs. - ProductSuite string `json:"productSuite,omitempty"` - - // Key/value pairs that provide additional information about the tool component. - Properties *PropertyBag `json:"properties,omitempty"` - - // A string specifying the UTC date (and optionally, the time) of the component's release. - ReleaseDateUtc string `json:"releaseDateUtc,omitempty"` - - // An array of reportingDescriptor objects relevant to the analysis performed by the tool component. - Rules []*ReportingDescriptor `json:"rules,omitempty"` - - // The tool component version in the format specified by Semantic Versioning 2.0. - SemanticVersion string `json:"semanticVersion,omitempty"` - - // A brief description of the tool component. - ShortDescription *MultiformatMessageString `json:"shortDescription,omitempty"` - - // An array of toolComponentReference objects to declare the taxonomies supported by the tool component. - SupportedTaxonomies []*ToolComponentReference `json:"supportedTaxonomies,omitempty"` - - // An array of reportingDescriptor objects relevant to the definitions of both standalone and tool-defined taxonomies. - Taxa []*ReportingDescriptor `json:"taxa,omitempty"` - - // Translation metadata, required for a translation, not populated by other component types. - TranslationMetadata *TranslationMetadata `json:"translationMetadata,omitempty"` - - // The tool component version, in whatever format the component natively provides. - Version string `json:"version,omitempty"` -} - -// ToolComponentReference Identifies a particular toolComponent object, either the driver or an extension. -type ToolComponentReference struct { - - // The 'guid' property of the referenced toolComponent. - Guid string `json:"guid,omitempty"` - - // An index into the referenced toolComponent in tool.extensions. - Index int `json:"index,omitempty"` - - // The 'name' property of the referenced toolComponent. - Name string `json:"name,omitempty"` - - // Key/value pairs that provide additional information about the toolComponentReference. - Properties *PropertyBag `json:"properties,omitempty"` -} - -// TranslationMetadata Provides additional metadata related to translation. -type TranslationMetadata struct { - - // The absolute URI from which the translation metadata can be downloaded. - DownloadUri string `json:"downloadUri,omitempty"` - - // A comprehensive description of the translation metadata. - FullDescription *MultiformatMessageString `json:"fullDescription,omitempty"` - - // The full name associated with the translation metadata. - FullName string `json:"fullName,omitempty"` - - // The absolute URI from which information related to the translation metadata can be downloaded. - InformationUri string `json:"informationUri,omitempty"` - - // The name associated with the translation metadata. - Name string `json:"name"` - - // Key/value pairs that provide additional information about the translation metadata. - Properties *PropertyBag `json:"properties,omitempty"` - - // A brief description of the translation metadata. - ShortDescription *MultiformatMessageString `json:"shortDescription,omitempty"` -} - -// VersionControlDetails Specifies the information necessary to retrieve a desired revision from a version control system. -type VersionControlDetails struct { - - // A Coordinated Universal Time (UTC) date and time that can be used to synchronize an enlistment to the state of the repository at that time. - AsOfTimeUtc string `json:"asOfTimeUtc,omitempty"` - - // The name of a branch containing the revision. - Branch string `json:"branch,omitempty"` - - // The location in the local file system to which the root of the repository was mapped at the time of the analysis. - MappedTo *ArtifactLocation `json:"mappedTo,omitempty"` - - // Key/value pairs that provide additional information about the version control details. - Properties *PropertyBag `json:"properties,omitempty"` - - // The absolute URI of the repository. - RepositoryUri string `json:"repositoryUri"` - - // A string that uniquely and permanently identifies the revision within the repository. - RevisionId string `json:"revisionId,omitempty"` - - // A tag that has been applied to the revision. - RevisionTag string `json:"revisionTag,omitempty"` -} - -// WebRequest Describes an HTTP request. -type WebRequest struct { - - // The body of the request. - Body *ArtifactContent `json:"body,omitempty"` - - // The request headers. - Headers map[string]string `json:"headers,omitempty"` - - // The index within the run.webRequests array of the request object associated with this result. - Index int `json:"index,omitempty"` - - // The HTTP method. Well-known values are 'GET', 'PUT', 'POST', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS', 'TRACE', 'CONNECT'. - Method string `json:"method,omitempty"` - - // The request parameters. - Parameters map[string]string `json:"parameters,omitempty"` - - // Key/value pairs that provide additional information about the request. - Properties *PropertyBag `json:"properties,omitempty"` - - // The request protocol. Example: 'http'. - Protocol string `json:"protocol,omitempty"` - - // The target of the request. - Target string `json:"target,omitempty"` - - // The request version. Example: '1.1'. - Version string `json:"version,omitempty"` -} - -// WebResponse Describes the response to an HTTP request. -type WebResponse struct { - - // The body of the response. - Body *ArtifactContent `json:"body,omitempty"` - - // The response headers. - Headers map[string]string `json:"headers,omitempty"` - - // The index within the run.webResponses array of the response object associated with this result. - Index int `json:"index,omitempty"` - - // Specifies whether a response was received from the server. - NoResponseReceived bool `json:"noResponseReceived,omitempty"` - - // Key/value pairs that provide additional information about the response. - Properties *PropertyBag `json:"properties,omitempty"` - - // The response protocol. Example: 'http'. - Protocol string `json:"protocol,omitempty"` - - // The response reason. Example: 'Not found'. - ReasonPhrase string `json:"reasonPhrase,omitempty"` - - // The response status code. Example: 451. - StatusCode int `json:"statusCode,omitempty"` - - // The response version. Example: '1.1'. - Version string `json:"version,omitempty"` -} diff --git a/vendor/github.com/fatih/color/LICENSE.md b/vendor/github.com/fatih/color/LICENSE.md deleted file mode 100644 index 25fdaf639..000000000 --- a/vendor/github.com/fatih/color/LICENSE.md +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2013 Fatih Arslan - -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/fatih/color/README.md b/vendor/github.com/fatih/color/README.md deleted file mode 100644 index d62e4024a..000000000 --- a/vendor/github.com/fatih/color/README.md +++ /dev/null @@ -1,173 +0,0 @@ -# color [![](https://github.com/fatih/color/workflows/build/badge.svg)](https://github.com/fatih/color/actions) [![PkgGoDev](https://pkg.go.dev/badge/github.com/fatih/color)](https://pkg.go.dev/github.com/fatih/color) - -Color lets you use colorized outputs in terms of [ANSI Escape -Codes](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors) in Go (Golang). It -has support for Windows too! The API can be used in several ways, pick one that -suits you. - -![Color](https://user-images.githubusercontent.com/438920/96832689-03b3e000-13f4-11eb-9803-46f4c4de3406.jpg) - - -## Install - -```bash -go get github.com/fatih/color -``` - -## Examples - -### Standard colors - -```go -// Print with default helper functions -color.Cyan("Prints text in cyan.") - -// A newline will be appended automatically -color.Blue("Prints %s in blue.", "text") - -// These are using the default foreground colors -color.Red("We have red") -color.Magenta("And many others ..") - -``` - -### Mix and reuse colors - -```go -// Create a new color object -c := color.New(color.FgCyan).Add(color.Underline) -c.Println("Prints cyan text with an underline.") - -// Or just add them to New() -d := color.New(color.FgCyan, color.Bold) -d.Printf("This prints bold cyan %s\n", "too!.") - -// Mix up foreground and background colors, create new mixes! -red := color.New(color.FgRed) - -boldRed := red.Add(color.Bold) -boldRed.Println("This will print text in bold red.") - -whiteBackground := red.Add(color.BgWhite) -whiteBackground.Println("Red text with white background.") -``` - -### Use your own output (io.Writer) - -```go -// Use your own io.Writer output -color.New(color.FgBlue).Fprintln(myWriter, "blue color!") - -blue := color.New(color.FgBlue) -blue.Fprint(writer, "This will print text in blue.") -``` - -### Custom print functions (PrintFunc) - -```go -// Create a custom print function for convenience -red := color.New(color.FgRed).PrintfFunc() -red("Warning") -red("Error: %s", err) - -// Mix up multiple attributes -notice := color.New(color.Bold, color.FgGreen).PrintlnFunc() -notice("Don't forget this...") -``` - -### Custom fprint functions (FprintFunc) - -```go -blue := color.New(FgBlue).FprintfFunc() -blue(myWriter, "important notice: %s", stars) - -// Mix up with multiple attributes -success := color.New(color.Bold, color.FgGreen).FprintlnFunc() -success(myWriter, "Don't forget this...") -``` - -### Insert into noncolor strings (SprintFunc) - -```go -// Create SprintXxx functions to mix strings with other non-colorized strings: -yellow := color.New(color.FgYellow).SprintFunc() -red := color.New(color.FgRed).SprintFunc() -fmt.Printf("This is a %s and this is %s.\n", yellow("warning"), red("error")) - -info := color.New(color.FgWhite, color.BgGreen).SprintFunc() -fmt.Printf("This %s rocks!\n", info("package")) - -// Use helper functions -fmt.Println("This", color.RedString("warning"), "should be not neglected.") -fmt.Printf("%v %v\n", color.GreenString("Info:"), "an important message.") - -// Windows supported too! Just don't forget to change the output to color.Output -fmt.Fprintf(color.Output, "Windows support: %s", color.GreenString("PASS")) -``` - -### Plug into existing code - -```go -// Use handy standard colors -color.Set(color.FgYellow) - -fmt.Println("Existing text will now be in yellow") -fmt.Printf("This one %s\n", "too") - -color.Unset() // Don't forget to unset - -// You can mix up parameters -color.Set(color.FgMagenta, color.Bold) -defer color.Unset() // Use it in your function - -fmt.Println("All text will now be bold magenta.") -``` - -### Disable/Enable color - -There might be a case where you want to explicitly disable/enable color output. the -`go-isatty` package will automatically disable color output for non-tty output streams -(for example if the output were piped directly to `less`) - -`Color` has support to disable/enable colors both globally and for single color -definitions. For example suppose you have a CLI app and a `--no-color` bool flag. You -can easily disable the color output with: - -```go - -var flagNoColor = flag.Bool("no-color", false, "Disable color output") - -if *flagNoColor { - color.NoColor = true // disables colorized output -} -``` - -It also has support for single color definitions (local). You can -disable/enable color output on the fly: - -```go -c := color.New(color.FgCyan) -c.Println("Prints cyan text") - -c.DisableColor() -c.Println("This is printed without any color") - -c.EnableColor() -c.Println("This prints again cyan...") -``` - -## Todo - -* Save/Return previous values -* Evaluate fmt.Formatter interface - - -## Credits - - * [Fatih Arslan](https://github.com/fatih) - * Windows support via @mattn: [colorable](https://github.com/mattn/go-colorable) - -## License - -The MIT License (MIT) - see [`LICENSE.md`](https://github.com/fatih/color/blob/master/LICENSE.md) for more details - diff --git a/vendor/github.com/fatih/color/color.go b/vendor/github.com/fatih/color/color.go deleted file mode 100644 index 91c8e9f06..000000000 --- a/vendor/github.com/fatih/color/color.go +++ /dev/null @@ -1,603 +0,0 @@ -package color - -import ( - "fmt" - "io" - "os" - "strconv" - "strings" - "sync" - - "github.com/mattn/go-colorable" - "github.com/mattn/go-isatty" -) - -var ( - // NoColor defines if the output is colorized or not. It's dynamically set to - // false or true based on the stdout's file descriptor referring to a terminal - // or not. This is a global option and affects all colors. For more control - // over each color block use the methods DisableColor() individually. - NoColor = os.Getenv("TERM") == "dumb" || - (!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd())) - - // Output defines the standard output of the print functions. By default - // os.Stdout is used. - Output = colorable.NewColorableStdout() - - // Error defines a color supporting writer for os.Stderr. - Error = colorable.NewColorableStderr() - - // colorsCache is used to reduce the count of created Color objects and - // allows to reuse already created objects with required Attribute. - colorsCache = make(map[Attribute]*Color) - colorsCacheMu sync.Mutex // protects colorsCache -) - -// Color defines a custom color object which is defined by SGR parameters. -type Color struct { - params []Attribute - noColor *bool -} - -// Attribute defines a single SGR Code -type Attribute int - -const escape = "\x1b" - -// Base attributes -const ( - Reset Attribute = iota - Bold - Faint - Italic - Underline - BlinkSlow - BlinkRapid - ReverseVideo - Concealed - CrossedOut -) - -// Foreground text colors -const ( - FgBlack Attribute = iota + 30 - FgRed - FgGreen - FgYellow - FgBlue - FgMagenta - FgCyan - FgWhite -) - -// Foreground Hi-Intensity text colors -const ( - FgHiBlack Attribute = iota + 90 - FgHiRed - FgHiGreen - FgHiYellow - FgHiBlue - FgHiMagenta - FgHiCyan - FgHiWhite -) - -// Background text colors -const ( - BgBlack Attribute = iota + 40 - BgRed - BgGreen - BgYellow - BgBlue - BgMagenta - BgCyan - BgWhite -) - -// Background Hi-Intensity text colors -const ( - BgHiBlack Attribute = iota + 100 - BgHiRed - BgHiGreen - BgHiYellow - BgHiBlue - BgHiMagenta - BgHiCyan - BgHiWhite -) - -// New returns a newly created color object. -func New(value ...Attribute) *Color { - c := &Color{params: make([]Attribute, 0)} - c.Add(value...) - return c -} - -// Set sets the given parameters immediately. It will change the color of -// output with the given SGR parameters until color.Unset() is called. -func Set(p ...Attribute) *Color { - c := New(p...) - c.Set() - return c -} - -// Unset resets all escape attributes and clears the output. Usually should -// be called after Set(). -func Unset() { - if NoColor { - return - } - - fmt.Fprintf(Output, "%s[%dm", escape, Reset) -} - -// Set sets the SGR sequence. -func (c *Color) Set() *Color { - if c.isNoColorSet() { - return c - } - - fmt.Fprintf(Output, c.format()) - return c -} - -func (c *Color) unset() { - if c.isNoColorSet() { - return - } - - Unset() -} - -func (c *Color) setWriter(w io.Writer) *Color { - if c.isNoColorSet() { - return c - } - - fmt.Fprintf(w, c.format()) - return c -} - -func (c *Color) unsetWriter(w io.Writer) { - if c.isNoColorSet() { - return - } - - if NoColor { - return - } - - fmt.Fprintf(w, "%s[%dm", escape, Reset) -} - -// Add is used to chain SGR parameters. Use as many as parameters to combine -// and create custom color objects. Example: Add(color.FgRed, color.Underline). -func (c *Color) Add(value ...Attribute) *Color { - c.params = append(c.params, value...) - return c -} - -func (c *Color) prepend(value Attribute) { - c.params = append(c.params, 0) - copy(c.params[1:], c.params[0:]) - c.params[0] = value -} - -// Fprint formats using the default formats for its operands and writes to w. -// Spaces are added between operands when neither is a string. -// It returns the number of bytes written and any write error encountered. -// On Windows, users should wrap w with colorable.NewColorable() if w is of -// type *os.File. -func (c *Color) Fprint(w io.Writer, a ...interface{}) (n int, err error) { - c.setWriter(w) - defer c.unsetWriter(w) - - return fmt.Fprint(w, a...) -} - -// Print formats using the default formats for its operands and writes to -// standard output. Spaces are added between operands when neither is a -// string. It returns the number of bytes written and any write error -// encountered. This is the standard fmt.Print() method wrapped with the given -// color. -func (c *Color) Print(a ...interface{}) (n int, err error) { - c.Set() - defer c.unset() - - return fmt.Fprint(Output, a...) -} - -// Fprintf formats according to a format specifier and writes to w. -// It returns the number of bytes written and any write error encountered. -// On Windows, users should wrap w with colorable.NewColorable() if w is of -// type *os.File. -func (c *Color) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) { - c.setWriter(w) - defer c.unsetWriter(w) - - return fmt.Fprintf(w, format, a...) -} - -// Printf formats according to a format specifier and writes to standard output. -// It returns the number of bytes written and any write error encountered. -// This is the standard fmt.Printf() method wrapped with the given color. -func (c *Color) Printf(format string, a ...interface{}) (n int, err error) { - c.Set() - defer c.unset() - - return fmt.Fprintf(Output, format, a...) -} - -// Fprintln formats using the default formats for its operands and writes to w. -// Spaces are always added between operands and a newline is appended. -// On Windows, users should wrap w with colorable.NewColorable() if w is of -// type *os.File. -func (c *Color) Fprintln(w io.Writer, a ...interface{}) (n int, err error) { - c.setWriter(w) - defer c.unsetWriter(w) - - return fmt.Fprintln(w, a...) -} - -// Println formats using the default formats for its operands and writes to -// standard output. Spaces are always added between operands and a newline is -// appended. It returns the number of bytes written and any write error -// encountered. This is the standard fmt.Print() method wrapped with the given -// color. -func (c *Color) Println(a ...interface{}) (n int, err error) { - c.Set() - defer c.unset() - - return fmt.Fprintln(Output, a...) -} - -// Sprint is just like Print, but returns a string instead of printing it. -func (c *Color) Sprint(a ...interface{}) string { - return c.wrap(fmt.Sprint(a...)) -} - -// Sprintln is just like Println, but returns a string instead of printing it. -func (c *Color) Sprintln(a ...interface{}) string { - return c.wrap(fmt.Sprintln(a...)) -} - -// Sprintf is just like Printf, but returns a string instead of printing it. -func (c *Color) Sprintf(format string, a ...interface{}) string { - return c.wrap(fmt.Sprintf(format, a...)) -} - -// FprintFunc returns a new function that prints the passed arguments as -// colorized with color.Fprint(). -func (c *Color) FprintFunc() func(w io.Writer, a ...interface{}) { - return func(w io.Writer, a ...interface{}) { - c.Fprint(w, a...) - } -} - -// PrintFunc returns a new function that prints the passed arguments as -// colorized with color.Print(). -func (c *Color) PrintFunc() func(a ...interface{}) { - return func(a ...interface{}) { - c.Print(a...) - } -} - -// FprintfFunc returns a new function that prints the passed arguments as -// colorized with color.Fprintf(). -func (c *Color) FprintfFunc() func(w io.Writer, format string, a ...interface{}) { - return func(w io.Writer, format string, a ...interface{}) { - c.Fprintf(w, format, a...) - } -} - -// PrintfFunc returns a new function that prints the passed arguments as -// colorized with color.Printf(). -func (c *Color) PrintfFunc() func(format string, a ...interface{}) { - return func(format string, a ...interface{}) { - c.Printf(format, a...) - } -} - -// FprintlnFunc returns a new function that prints the passed arguments as -// colorized with color.Fprintln(). -func (c *Color) FprintlnFunc() func(w io.Writer, a ...interface{}) { - return func(w io.Writer, a ...interface{}) { - c.Fprintln(w, a...) - } -} - -// PrintlnFunc returns a new function that prints the passed arguments as -// colorized with color.Println(). -func (c *Color) PrintlnFunc() func(a ...interface{}) { - return func(a ...interface{}) { - c.Println(a...) - } -} - -// SprintFunc returns a new function that returns colorized strings for the -// given arguments with fmt.Sprint(). Useful to put into or mix into other -// string. Windows users should use this in conjunction with color.Output, example: -// -// put := New(FgYellow).SprintFunc() -// fmt.Fprintf(color.Output, "This is a %s", put("warning")) -func (c *Color) SprintFunc() func(a ...interface{}) string { - return func(a ...interface{}) string { - return c.wrap(fmt.Sprint(a...)) - } -} - -// SprintfFunc returns a new function that returns colorized strings for the -// given arguments with fmt.Sprintf(). Useful to put into or mix into other -// string. Windows users should use this in conjunction with color.Output. -func (c *Color) SprintfFunc() func(format string, a ...interface{}) string { - return func(format string, a ...interface{}) string { - return c.wrap(fmt.Sprintf(format, a...)) - } -} - -// SprintlnFunc returns a new function that returns colorized strings for the -// given arguments with fmt.Sprintln(). Useful to put into or mix into other -// string. Windows users should use this in conjunction with color.Output. -func (c *Color) SprintlnFunc() func(a ...interface{}) string { - return func(a ...interface{}) string { - return c.wrap(fmt.Sprintln(a...)) - } -} - -// sequence returns a formatted SGR sequence to be plugged into a "\x1b[...m" -// an example output might be: "1;36" -> bold cyan -func (c *Color) sequence() string { - format := make([]string, len(c.params)) - for i, v := range c.params { - format[i] = strconv.Itoa(int(v)) - } - - return strings.Join(format, ";") -} - -// wrap wraps the s string with the colors attributes. The string is ready to -// be printed. -func (c *Color) wrap(s string) string { - if c.isNoColorSet() { - return s - } - - return c.format() + s + c.unformat() -} - -func (c *Color) format() string { - return fmt.Sprintf("%s[%sm", escape, c.sequence()) -} - -func (c *Color) unformat() string { - return fmt.Sprintf("%s[%dm", escape, Reset) -} - -// DisableColor disables the color output. Useful to not change any existing -// code and still being able to output. Can be used for flags like -// "--no-color". To enable back use EnableColor() method. -func (c *Color) DisableColor() { - c.noColor = boolPtr(true) -} - -// EnableColor enables the color output. Use it in conjunction with -// DisableColor(). Otherwise this method has no side effects. -func (c *Color) EnableColor() { - c.noColor = boolPtr(false) -} - -func (c *Color) isNoColorSet() bool { - // check first if we have user setted action - if c.noColor != nil { - return *c.noColor - } - - // if not return the global option, which is disabled by default - return NoColor -} - -// Equals returns a boolean value indicating whether two colors are equal. -func (c *Color) Equals(c2 *Color) bool { - if len(c.params) != len(c2.params) { - return false - } - - for _, attr := range c.params { - if !c2.attrExists(attr) { - return false - } - } - - return true -} - -func (c *Color) attrExists(a Attribute) bool { - for _, attr := range c.params { - if attr == a { - return true - } - } - - return false -} - -func boolPtr(v bool) *bool { - return &v -} - -func getCachedColor(p Attribute) *Color { - colorsCacheMu.Lock() - defer colorsCacheMu.Unlock() - - c, ok := colorsCache[p] - if !ok { - c = New(p) - colorsCache[p] = c - } - - return c -} - -func colorPrint(format string, p Attribute, a ...interface{}) { - c := getCachedColor(p) - - if !strings.HasSuffix(format, "\n") { - format += "\n" - } - - if len(a) == 0 { - c.Print(format) - } else { - c.Printf(format, a...) - } -} - -func colorString(format string, p Attribute, a ...interface{}) string { - c := getCachedColor(p) - - if len(a) == 0 { - return c.SprintFunc()(format) - } - - return c.SprintfFunc()(format, a...) -} - -// Black is a convenient helper function to print with black foreground. A -// newline is appended to format by default. -func Black(format string, a ...interface{}) { colorPrint(format, FgBlack, a...) } - -// Red is a convenient helper function to print with red foreground. A -// newline is appended to format by default. -func Red(format string, a ...interface{}) { colorPrint(format, FgRed, a...) } - -// Green is a convenient helper function to print with green foreground. A -// newline is appended to format by default. -func Green(format string, a ...interface{}) { colorPrint(format, FgGreen, a...) } - -// Yellow is a convenient helper function to print with yellow foreground. -// A newline is appended to format by default. -func Yellow(format string, a ...interface{}) { colorPrint(format, FgYellow, a...) } - -// Blue is a convenient helper function to print with blue foreground. A -// newline is appended to format by default. -func Blue(format string, a ...interface{}) { colorPrint(format, FgBlue, a...) } - -// Magenta is a convenient helper function to print with magenta foreground. -// A newline is appended to format by default. -func Magenta(format string, a ...interface{}) { colorPrint(format, FgMagenta, a...) } - -// Cyan is a convenient helper function to print with cyan foreground. A -// newline is appended to format by default. -func Cyan(format string, a ...interface{}) { colorPrint(format, FgCyan, a...) } - -// White is a convenient helper function to print with white foreground. A -// newline is appended to format by default. -func White(format string, a ...interface{}) { colorPrint(format, FgWhite, a...) } - -// BlackString is a convenient helper function to return a string with black -// foreground. -func BlackString(format string, a ...interface{}) string { return colorString(format, FgBlack, a...) } - -// RedString is a convenient helper function to return a string with red -// foreground. -func RedString(format string, a ...interface{}) string { return colorString(format, FgRed, a...) } - -// GreenString is a convenient helper function to return a string with green -// foreground. -func GreenString(format string, a ...interface{}) string { return colorString(format, FgGreen, a...) } - -// YellowString is a convenient helper function to return a string with yellow -// foreground. -func YellowString(format string, a ...interface{}) string { return colorString(format, FgYellow, a...) } - -// BlueString is a convenient helper function to return a string with blue -// foreground. -func BlueString(format string, a ...interface{}) string { return colorString(format, FgBlue, a...) } - -// MagentaString is a convenient helper function to return a string with magenta -// foreground. -func MagentaString(format string, a ...interface{}) string { - return colorString(format, FgMagenta, a...) -} - -// CyanString is a convenient helper function to return a string with cyan -// foreground. -func CyanString(format string, a ...interface{}) string { return colorString(format, FgCyan, a...) } - -// WhiteString is a convenient helper function to return a string with white -// foreground. -func WhiteString(format string, a ...interface{}) string { return colorString(format, FgWhite, a...) } - -// HiBlack is a convenient helper function to print with hi-intensity black foreground. A -// newline is appended to format by default. -func HiBlack(format string, a ...interface{}) { colorPrint(format, FgHiBlack, a...) } - -// HiRed is a convenient helper function to print with hi-intensity red foreground. A -// newline is appended to format by default. -func HiRed(format string, a ...interface{}) { colorPrint(format, FgHiRed, a...) } - -// HiGreen is a convenient helper function to print with hi-intensity green foreground. A -// newline is appended to format by default. -func HiGreen(format string, a ...interface{}) { colorPrint(format, FgHiGreen, a...) } - -// HiYellow is a convenient helper function to print with hi-intensity yellow foreground. -// A newline is appended to format by default. -func HiYellow(format string, a ...interface{}) { colorPrint(format, FgHiYellow, a...) } - -// HiBlue is a convenient helper function to print with hi-intensity blue foreground. A -// newline is appended to format by default. -func HiBlue(format string, a ...interface{}) { colorPrint(format, FgHiBlue, a...) } - -// HiMagenta is a convenient helper function to print with hi-intensity magenta foreground. -// A newline is appended to format by default. -func HiMagenta(format string, a ...interface{}) { colorPrint(format, FgHiMagenta, a...) } - -// HiCyan is a convenient helper function to print with hi-intensity cyan foreground. A -// newline is appended to format by default. -func HiCyan(format string, a ...interface{}) { colorPrint(format, FgHiCyan, a...) } - -// HiWhite is a convenient helper function to print with hi-intensity white foreground. A -// newline is appended to format by default. -func HiWhite(format string, a ...interface{}) { colorPrint(format, FgHiWhite, a...) } - -// HiBlackString is a convenient helper function to return a string with hi-intensity black -// foreground. -func HiBlackString(format string, a ...interface{}) string { - return colorString(format, FgHiBlack, a...) -} - -// HiRedString is a convenient helper function to return a string with hi-intensity red -// foreground. -func HiRedString(format string, a ...interface{}) string { return colorString(format, FgHiRed, a...) } - -// HiGreenString is a convenient helper function to return a string with hi-intensity green -// foreground. -func HiGreenString(format string, a ...interface{}) string { - return colorString(format, FgHiGreen, a...) -} - -// HiYellowString is a convenient helper function to return a string with hi-intensity yellow -// foreground. -func HiYellowString(format string, a ...interface{}) string { - return colorString(format, FgHiYellow, a...) -} - -// HiBlueString is a convenient helper function to return a string with hi-intensity blue -// foreground. -func HiBlueString(format string, a ...interface{}) string { return colorString(format, FgHiBlue, a...) } - -// HiMagentaString is a convenient helper function to return a string with hi-intensity magenta -// foreground. -func HiMagentaString(format string, a ...interface{}) string { - return colorString(format, FgHiMagenta, a...) -} - -// HiCyanString is a convenient helper function to return a string with hi-intensity cyan -// foreground. -func HiCyanString(format string, a ...interface{}) string { return colorString(format, FgHiCyan, a...) } - -// HiWhiteString is a convenient helper function to return a string with hi-intensity white -// foreground. -func HiWhiteString(format string, a ...interface{}) string { - return colorString(format, FgHiWhite, a...) -} diff --git a/vendor/github.com/fatih/color/doc.go b/vendor/github.com/fatih/color/doc.go deleted file mode 100644 index cf1e96500..000000000 --- a/vendor/github.com/fatih/color/doc.go +++ /dev/null @@ -1,133 +0,0 @@ -/* -Package color is an ANSI color package to output colorized or SGR defined -output to the standard output. The API can be used in several way, pick one -that suits you. - -Use simple and default helper functions with predefined foreground colors: - - color.Cyan("Prints text in cyan.") - - // a newline will be appended automatically - color.Blue("Prints %s in blue.", "text") - - // More default foreground colors.. - color.Red("We have red") - color.Yellow("Yellow color too!") - color.Magenta("And many others ..") - - // Hi-intensity colors - color.HiGreen("Bright green color.") - color.HiBlack("Bright black means gray..") - color.HiWhite("Shiny white color!") - -However there are times where custom color mixes are required. Below are some -examples to create custom color objects and use the print functions of each -separate color object. - - // Create a new color object - c := color.New(color.FgCyan).Add(color.Underline) - c.Println("Prints cyan text with an underline.") - - // Or just add them to New() - d := color.New(color.FgCyan, color.Bold) - d.Printf("This prints bold cyan %s\n", "too!.") - - - // Mix up foreground and background colors, create new mixes! - red := color.New(color.FgRed) - - boldRed := red.Add(color.Bold) - boldRed.Println("This will print text in bold red.") - - whiteBackground := red.Add(color.BgWhite) - whiteBackground.Println("Red text with White background.") - - // Use your own io.Writer output - color.New(color.FgBlue).Fprintln(myWriter, "blue color!") - - blue := color.New(color.FgBlue) - blue.Fprint(myWriter, "This will print text in blue.") - -You can create PrintXxx functions to simplify even more: - - // Create a custom print function for convenient - red := color.New(color.FgRed).PrintfFunc() - red("warning") - red("error: %s", err) - - // Mix up multiple attributes - notice := color.New(color.Bold, color.FgGreen).PrintlnFunc() - notice("don't forget this...") - -You can also FprintXxx functions to pass your own io.Writer: - - blue := color.New(FgBlue).FprintfFunc() - blue(myWriter, "important notice: %s", stars) - - // Mix up with multiple attributes - success := color.New(color.Bold, color.FgGreen).FprintlnFunc() - success(myWriter, don't forget this...") - - -Or create SprintXxx functions to mix strings with other non-colorized strings: - - yellow := New(FgYellow).SprintFunc() - red := New(FgRed).SprintFunc() - - fmt.Printf("this is a %s and this is %s.\n", yellow("warning"), red("error")) - - info := New(FgWhite, BgGreen).SprintFunc() - fmt.Printf("this %s rocks!\n", info("package")) - -Windows support is enabled by default. All Print functions work as intended. -However only for color.SprintXXX functions, user should use fmt.FprintXXX and -set the output to color.Output: - - fmt.Fprintf(color.Output, "Windows support: %s", color.GreenString("PASS")) - - info := New(FgWhite, BgGreen).SprintFunc() - fmt.Fprintf(color.Output, "this %s rocks!\n", info("package")) - -Using with existing code is possible. Just use the Set() method to set the -standard output to the given parameters. That way a rewrite of an existing -code is not required. - - // Use handy standard colors. - color.Set(color.FgYellow) - - fmt.Println("Existing text will be now in Yellow") - fmt.Printf("This one %s\n", "too") - - color.Unset() // don't forget to unset - - // You can mix up parameters - color.Set(color.FgMagenta, color.Bold) - defer color.Unset() // use it in your function - - fmt.Println("All text will be now bold magenta.") - -There might be a case where you want to disable color output (for example to -pipe the standard output of your app to somewhere else). `Color` has support to -disable colors both globally and for single color definition. For example -suppose you have a CLI app and a `--no-color` bool flag. You can easily disable -the color output with: - - var flagNoColor = flag.Bool("no-color", false, "Disable color output") - - if *flagNoColor { - color.NoColor = true // disables colorized output - } - -It also has support for single color definitions (local). You can -disable/enable color output on the fly: - - c := color.New(color.FgCyan) - c.Println("Prints cyan text") - - c.DisableColor() - c.Println("This is printed without any color") - - c.EnableColor() - c.Println("This prints again cyan...") -*/ -package color diff --git a/vendor/github.com/fatih/color/go.mod b/vendor/github.com/fatih/color/go.mod deleted file mode 100644 index 78872815e..000000000 --- a/vendor/github.com/fatih/color/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module github.com/fatih/color - -go 1.13 - -require ( - github.com/mattn/go-colorable v0.1.8 - github.com/mattn/go-isatty v0.0.12 -) diff --git a/vendor/github.com/fatih/color/go.sum b/vendor/github.com/fatih/color/go.sum deleted file mode 100644 index 54f7c46e8..000000000 --- a/vendor/github.com/fatih/color/go.sum +++ /dev/null @@ -1,7 +0,0 @@ -github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= -github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/vendor/github.com/fatih/structtag/LICENSE b/vendor/github.com/fatih/structtag/LICENSE deleted file mode 100644 index 4fd15f9f8..000000000 --- a/vendor/github.com/fatih/structtag/LICENSE +++ /dev/null @@ -1,60 +0,0 @@ -Copyright (c) 2017, Fatih Arslan -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* 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. - -* Neither the name of structtag 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. - -This software includes some portions from Go. Go is used under the terms of the -BSD like license. - -Copyright (c) 2012 The Go Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * 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. - * Neither the name of Google Inc. 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 -OWNER 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. - -The Go gopher was designed by Renee French. http://reneefrench.blogspot.com/ The design is licensed under the Creative Commons 3.0 Attributions license. Read this article for more details: https://blog.golang.org/gopher diff --git a/vendor/github.com/fatih/structtag/README.md b/vendor/github.com/fatih/structtag/README.md deleted file mode 100644 index c4e8b1e86..000000000 --- a/vendor/github.com/fatih/structtag/README.md +++ /dev/null @@ -1,73 +0,0 @@ -# structtag [![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](http://godoc.org/github.com/fatih/structtag) - -structtag provides an easy way of parsing and manipulating struct tag fields. -Please vendor the library as it might change in future versions. - -# Install - -```bash -go get github.com/fatih/structtag -``` - -# Example - -```go -package main - -import ( - "fmt" - "reflect" - "sort" - - "github.com/fatih/structtag" -) - -func main() { - type t struct { - t string `json:"foo,omitempty,string" xml:"foo"` - } - - // get field tag - tag := reflect.TypeOf(t{}).Field(0).Tag - - // ... and start using structtag by parsing the tag - tags, err := structtag.Parse(string(tag)) - if err != nil { - panic(err) - } - - // iterate over all tags - for _, t := range tags.Tags() { - fmt.Printf("tag: %+v\n", t) - } - - // get a single tag - jsonTag, err := tags.Get("json") - if err != nil { - panic(err) - } - fmt.Println(jsonTag) // Output: json:"foo,omitempty,string" - fmt.Println(jsonTag.Key) // Output: json - fmt.Println(jsonTag.Name) // Output: foo - fmt.Println(jsonTag.Options) // Output: [omitempty string] - - // change existing tag - jsonTag.Name = "foo_bar" - jsonTag.Options = nil - tags.Set(jsonTag) - - // add new tag - tags.Set(&structtag.Tag{ - Key: "hcl", - Name: "foo", - Options: []string{"squash"}, - }) - - // print the tags - fmt.Println(tags) // Output: json:"foo_bar" xml:"foo" hcl:"foo,squash" - - // sort tags according to keys - sort.Sort(tags) - fmt.Println(tags) // Output: hcl:"foo,squash" json:"foo_bar" xml:"foo" -} -``` diff --git a/vendor/github.com/fatih/structtag/go.mod b/vendor/github.com/fatih/structtag/go.mod deleted file mode 100644 index 660d6a1f1..000000000 --- a/vendor/github.com/fatih/structtag/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/fatih/structtag - -go 1.12 diff --git a/vendor/github.com/fatih/structtag/tags.go b/vendor/github.com/fatih/structtag/tags.go deleted file mode 100644 index c168fb21c..000000000 --- a/vendor/github.com/fatih/structtag/tags.go +++ /dev/null @@ -1,315 +0,0 @@ -package structtag - -import ( - "bytes" - "errors" - "fmt" - "strconv" - "strings" -) - -var ( - errTagSyntax = errors.New("bad syntax for struct tag pair") - errTagKeySyntax = errors.New("bad syntax for struct tag key") - errTagValueSyntax = errors.New("bad syntax for struct tag value") - - errKeyNotSet = errors.New("tag key does not exist") - errTagNotExist = errors.New("tag does not exist") - errTagKeyMismatch = errors.New("mismatch between key and tag.key") -) - -// Tags represent a set of tags from a single struct field -type Tags struct { - tags []*Tag -} - -// Tag defines a single struct's string literal tag -type Tag struct { - // Key is the tag key, such as json, xml, etc.. - // i.e: `json:"foo,omitempty". Here key is: "json" - Key string - - // Name is a part of the value - // i.e: `json:"foo,omitempty". Here name is: "foo" - Name string - - // Options is a part of the value. It contains a slice of tag options i.e: - // `json:"foo,omitempty". Here options is: ["omitempty"] - Options []string -} - -// Parse parses a single struct field tag and returns the set of tags. -func Parse(tag string) (*Tags, error) { - var tags []*Tag - - hasTag := tag != "" - - // NOTE(arslan) following code is from reflect and vet package with some - // modifications to collect all necessary information and extend it with - // usable methods - for tag != "" { - // Skip leading space. - i := 0 - for i < len(tag) && tag[i] == ' ' { - i++ - } - tag = tag[i:] - if tag == "" { - break - } - - // Scan to colon. A space, a quote or a control character is a syntax - // error. Strictly speaking, control chars include the range [0x7f, - // 0x9f], not just [0x00, 0x1f], but in practice, we ignore the - // multi-byte control characters as it is simpler to inspect the tag's - // bytes than the tag's runes. - i = 0 - for i < len(tag) && tag[i] > ' ' && tag[i] != ':' && tag[i] != '"' && tag[i] != 0x7f { - i++ - } - - if i == 0 { - return nil, errTagKeySyntax - } - if i+1 >= len(tag) || tag[i] != ':' { - return nil, errTagSyntax - } - if tag[i+1] != '"' { - return nil, errTagValueSyntax - } - - key := string(tag[:i]) - tag = tag[i+1:] - - // Scan quoted string to find value. - i = 1 - for i < len(tag) && tag[i] != '"' { - if tag[i] == '\\' { - i++ - } - i++ - } - if i >= len(tag) { - return nil, errTagValueSyntax - } - - qvalue := string(tag[:i+1]) - tag = tag[i+1:] - - value, err := strconv.Unquote(qvalue) - if err != nil { - return nil, errTagValueSyntax - } - - res := strings.Split(value, ",") - name := res[0] - options := res[1:] - if len(options) == 0 { - options = nil - } - - tags = append(tags, &Tag{ - Key: key, - Name: name, - Options: options, - }) - } - - if hasTag && len(tags) == 0 { - return nil, nil - } - - return &Tags{ - tags: tags, - }, nil -} - -// Get returns the tag associated with the given key. If the key is present -// in the tag the value (which may be empty) is returned. Otherwise the -// returned value will be the empty string. The ok return value reports whether -// the tag exists or not (which the return value is nil). -func (t *Tags) Get(key string) (*Tag, error) { - for _, tag := range t.tags { - if tag.Key == key { - return tag, nil - } - } - - return nil, errTagNotExist -} - -// Set sets the given tag. If the tag key already exists it'll override it -func (t *Tags) Set(tag *Tag) error { - if tag.Key == "" { - return errKeyNotSet - } - - added := false - for i, tg := range t.tags { - if tg.Key == tag.Key { - added = true - t.tags[i] = tag - } - } - - if !added { - // this means this is a new tag, add it - t.tags = append(t.tags, tag) - } - - return nil -} - -// AddOptions adds the given option for the given key. If the option already -// exists it doesn't add it again. -func (t *Tags) AddOptions(key string, options ...string) { - for i, tag := range t.tags { - if tag.Key != key { - continue - } - - for _, opt := range options { - if !tag.HasOption(opt) { - tag.Options = append(tag.Options, opt) - } - } - - t.tags[i] = tag - } -} - -// DeleteOptions deletes the given options for the given key -func (t *Tags) DeleteOptions(key string, options ...string) { - hasOption := func(option string) bool { - for _, opt := range options { - if opt == option { - return true - } - } - return false - } - - for i, tag := range t.tags { - if tag.Key != key { - continue - } - - var updated []string - for _, opt := range tag.Options { - if !hasOption(opt) { - updated = append(updated, opt) - } - } - - tag.Options = updated - t.tags[i] = tag - } -} - -// Delete deletes the tag for the given keys -func (t *Tags) Delete(keys ...string) { - hasKey := func(key string) bool { - for _, k := range keys { - if k == key { - return true - } - } - return false - } - - var updated []*Tag - for _, tag := range t.tags { - if !hasKey(tag.Key) { - updated = append(updated, tag) - } - } - - t.tags = updated -} - -// Tags returns a slice of tags. The order is the original tag order unless it -// was changed. -func (t *Tags) Tags() []*Tag { - return t.tags -} - -// Tags returns a slice of tags. The order is the original tag order unless it -// was changed. -func (t *Tags) Keys() []string { - var keys []string - for _, tag := range t.tags { - keys = append(keys, tag.Key) - } - return keys -} - -// String reassembles the tags into a valid literal tag field representation -func (t *Tags) String() string { - tags := t.Tags() - if len(tags) == 0 { - return "" - } - - var buf bytes.Buffer - for i, tag := range t.Tags() { - buf.WriteString(tag.String()) - if i != len(tags)-1 { - buf.WriteString(" ") - } - } - return buf.String() -} - -// HasOption returns true if the given option is available in options -func (t *Tag) HasOption(opt string) bool { - for _, tagOpt := range t.Options { - if tagOpt == opt { - return true - } - } - - return false -} - -// Value returns the raw value of the tag, i.e. if the tag is -// `json:"foo,omitempty", the Value is "foo,omitempty" -func (t *Tag) Value() string { - options := strings.Join(t.Options, ",") - if options != "" { - return fmt.Sprintf(`%s,%s`, t.Name, options) - } - return t.Name -} - -// String reassembles the tag into a valid tag field representation -func (t *Tag) String() string { - return fmt.Sprintf(`%s:%q`, t.Key, t.Value()) -} - -// GoString implements the fmt.GoStringer interface -func (t *Tag) GoString() string { - template := `{ - Key: '%s', - Name: '%s', - Option: '%s', - }` - - if t.Options == nil { - return fmt.Sprintf(template, t.Key, t.Name, "nil") - } - - options := strings.Join(t.Options, ",") - return fmt.Sprintf(template, t.Key, t.Name, options) -} - -func (t *Tags) Len() int { - return len(t.tags) -} - -func (t *Tags) Less(i int, j int) bool { - return t.tags[i].Key < t.tags[j].Key -} - -func (t *Tags) Swap(i int, j int) { - t.tags[i], t.tags[j] = t.tags[j], t.tags[i] -} diff --git a/vendor/github.com/mattn/go-colorable/.travis.yml b/vendor/github.com/mattn/go-colorable/.travis.yml deleted file mode 100644 index 7942c565c..000000000 --- a/vendor/github.com/mattn/go-colorable/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -language: go -sudo: false -go: - - 1.13.x - - tip - -before_install: - - go get -t -v ./... - -script: - - ./go.test.sh - -after_success: - - bash <(curl -s https://codecov.io/bash) - diff --git a/vendor/github.com/mattn/go-colorable/LICENSE b/vendor/github.com/mattn/go-colorable/LICENSE deleted file mode 100644 index 91b5cef30..000000000 --- a/vendor/github.com/mattn/go-colorable/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2016 Yasuhiro Matsumoto - -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/mattn/go-colorable/README.md b/vendor/github.com/mattn/go-colorable/README.md deleted file mode 100644 index e055952b6..000000000 --- a/vendor/github.com/mattn/go-colorable/README.md +++ /dev/null @@ -1,48 +0,0 @@ -# go-colorable - -[![Build Status](https://travis-ci.org/mattn/go-colorable.svg?branch=master)](https://travis-ci.org/mattn/go-colorable) -[![Codecov](https://codecov.io/gh/mattn/go-colorable/branch/master/graph/badge.svg)](https://codecov.io/gh/mattn/go-colorable) -[![GoDoc](https://godoc.org/github.com/mattn/go-colorable?status.svg)](http://godoc.org/github.com/mattn/go-colorable) -[![Go Report Card](https://goreportcard.com/badge/mattn/go-colorable)](https://goreportcard.com/report/mattn/go-colorable) - -Colorable writer for windows. - -For example, most of logger packages doesn't show colors on windows. (I know we can do it with ansicon. But I don't want.) -This package is possible to handle escape sequence for ansi color on windows. - -## Too Bad! - -![](https://raw.githubusercontent.com/mattn/go-colorable/gh-pages/bad.png) - - -## So Good! - -![](https://raw.githubusercontent.com/mattn/go-colorable/gh-pages/good.png) - -## Usage - -```go -logrus.SetFormatter(&logrus.TextFormatter{ForceColors: true}) -logrus.SetOutput(colorable.NewColorableStdout()) - -logrus.Info("succeeded") -logrus.Warn("not correct") -logrus.Error("something error") -logrus.Fatal("panic") -``` - -You can compile above code on non-windows OSs. - -## Installation - -``` -$ go get github.com/mattn/go-colorable -``` - -# License - -MIT - -# Author - -Yasuhiro Matsumoto (a.k.a mattn) diff --git a/vendor/github.com/mattn/go-colorable/colorable_appengine.go b/vendor/github.com/mattn/go-colorable/colorable_appengine.go deleted file mode 100644 index 1f7806fe1..000000000 --- a/vendor/github.com/mattn/go-colorable/colorable_appengine.go +++ /dev/null @@ -1,37 +0,0 @@ -// +build appengine - -package colorable - -import ( - "io" - "os" - - _ "github.com/mattn/go-isatty" -) - -// NewColorable returns new instance of Writer which handles escape sequence. -func NewColorable(file *os.File) io.Writer { - if file == nil { - panic("nil passed instead of *os.File to NewColorable()") - } - - return file -} - -// NewColorableStdout returns new instance of Writer which handles escape sequence for stdout. -func NewColorableStdout() io.Writer { - return os.Stdout -} - -// NewColorableStderr returns new instance of Writer which handles escape sequence for stderr. -func NewColorableStderr() io.Writer { - return os.Stderr -} - -// EnableColorsStdout enable colors if possible. -func EnableColorsStdout(enabled *bool) func() { - if enabled != nil { - *enabled = true - } - return func() {} -} diff --git a/vendor/github.com/mattn/go-colorable/colorable_others.go b/vendor/github.com/mattn/go-colorable/colorable_others.go deleted file mode 100644 index 08cbd1e0f..000000000 --- a/vendor/github.com/mattn/go-colorable/colorable_others.go +++ /dev/null @@ -1,38 +0,0 @@ -// +build !windows -// +build !appengine - -package colorable - -import ( - "io" - "os" - - _ "github.com/mattn/go-isatty" -) - -// NewColorable returns new instance of Writer which handles escape sequence. -func NewColorable(file *os.File) io.Writer { - if file == nil { - panic("nil passed instead of *os.File to NewColorable()") - } - - return file -} - -// NewColorableStdout returns new instance of Writer which handles escape sequence for stdout. -func NewColorableStdout() io.Writer { - return os.Stdout -} - -// NewColorableStderr returns new instance of Writer which handles escape sequence for stderr. -func NewColorableStderr() io.Writer { - return os.Stderr -} - -// EnableColorsStdout enable colors if possible. -func EnableColorsStdout(enabled *bool) func() { - if enabled != nil { - *enabled = true - } - return func() {} -} diff --git a/vendor/github.com/mattn/go-colorable/colorable_windows.go b/vendor/github.com/mattn/go-colorable/colorable_windows.go deleted file mode 100644 index 41215d7fc..000000000 --- a/vendor/github.com/mattn/go-colorable/colorable_windows.go +++ /dev/null @@ -1,1043 +0,0 @@ -// +build windows -// +build !appengine - -package colorable - -import ( - "bytes" - "io" - "math" - "os" - "strconv" - "strings" - "sync" - "syscall" - "unsafe" - - "github.com/mattn/go-isatty" -) - -const ( - foregroundBlue = 0x1 - foregroundGreen = 0x2 - foregroundRed = 0x4 - foregroundIntensity = 0x8 - foregroundMask = (foregroundRed | foregroundBlue | foregroundGreen | foregroundIntensity) - backgroundBlue = 0x10 - backgroundGreen = 0x20 - backgroundRed = 0x40 - backgroundIntensity = 0x80 - backgroundMask = (backgroundRed | backgroundBlue | backgroundGreen | backgroundIntensity) - commonLvbUnderscore = 0x8000 - - cENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4 -) - -const ( - genericRead = 0x80000000 - genericWrite = 0x40000000 -) - -const ( - consoleTextmodeBuffer = 0x1 -) - -type wchar uint16 -type short int16 -type dword uint32 -type word uint16 - -type coord struct { - x short - y short -} - -type smallRect struct { - left short - top short - right short - bottom short -} - -type consoleScreenBufferInfo struct { - size coord - cursorPosition coord - attributes word - window smallRect - maximumWindowSize coord -} - -type consoleCursorInfo struct { - size dword - visible int32 -} - -var ( - kernel32 = syscall.NewLazyDLL("kernel32.dll") - procGetConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo") - procSetConsoleTextAttribute = kernel32.NewProc("SetConsoleTextAttribute") - procSetConsoleCursorPosition = kernel32.NewProc("SetConsoleCursorPosition") - procFillConsoleOutputCharacter = kernel32.NewProc("FillConsoleOutputCharacterW") - procFillConsoleOutputAttribute = kernel32.NewProc("FillConsoleOutputAttribute") - procGetConsoleCursorInfo = kernel32.NewProc("GetConsoleCursorInfo") - procSetConsoleCursorInfo = kernel32.NewProc("SetConsoleCursorInfo") - procSetConsoleTitle = kernel32.NewProc("SetConsoleTitleW") - procGetConsoleMode = kernel32.NewProc("GetConsoleMode") - procSetConsoleMode = kernel32.NewProc("SetConsoleMode") - procCreateConsoleScreenBuffer = kernel32.NewProc("CreateConsoleScreenBuffer") -) - -// Writer provides colorable Writer to the console -type Writer struct { - out io.Writer - handle syscall.Handle - althandle syscall.Handle - oldattr word - oldpos coord - rest bytes.Buffer - mutex sync.Mutex -} - -// NewColorable returns new instance of Writer which handles escape sequence from File. -func NewColorable(file *os.File) io.Writer { - if file == nil { - panic("nil passed instead of *os.File to NewColorable()") - } - - if isatty.IsTerminal(file.Fd()) { - var mode uint32 - if r, _, _ := procGetConsoleMode.Call(file.Fd(), uintptr(unsafe.Pointer(&mode))); r != 0 && mode&cENABLE_VIRTUAL_TERMINAL_PROCESSING != 0 { - return file - } - var csbi consoleScreenBufferInfo - handle := syscall.Handle(file.Fd()) - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) - return &Writer{out: file, handle: handle, oldattr: csbi.attributes, oldpos: coord{0, 0}} - } - return file -} - -// NewColorableStdout returns new instance of Writer which handles escape sequence for stdout. -func NewColorableStdout() io.Writer { - return NewColorable(os.Stdout) -} - -// NewColorableStderr returns new instance of Writer which handles escape sequence for stderr. -func NewColorableStderr() io.Writer { - return NewColorable(os.Stderr) -} - -var color256 = map[int]int{ - 0: 0x000000, - 1: 0x800000, - 2: 0x008000, - 3: 0x808000, - 4: 0x000080, - 5: 0x800080, - 6: 0x008080, - 7: 0xc0c0c0, - 8: 0x808080, - 9: 0xff0000, - 10: 0x00ff00, - 11: 0xffff00, - 12: 0x0000ff, - 13: 0xff00ff, - 14: 0x00ffff, - 15: 0xffffff, - 16: 0x000000, - 17: 0x00005f, - 18: 0x000087, - 19: 0x0000af, - 20: 0x0000d7, - 21: 0x0000ff, - 22: 0x005f00, - 23: 0x005f5f, - 24: 0x005f87, - 25: 0x005faf, - 26: 0x005fd7, - 27: 0x005fff, - 28: 0x008700, - 29: 0x00875f, - 30: 0x008787, - 31: 0x0087af, - 32: 0x0087d7, - 33: 0x0087ff, - 34: 0x00af00, - 35: 0x00af5f, - 36: 0x00af87, - 37: 0x00afaf, - 38: 0x00afd7, - 39: 0x00afff, - 40: 0x00d700, - 41: 0x00d75f, - 42: 0x00d787, - 43: 0x00d7af, - 44: 0x00d7d7, - 45: 0x00d7ff, - 46: 0x00ff00, - 47: 0x00ff5f, - 48: 0x00ff87, - 49: 0x00ffaf, - 50: 0x00ffd7, - 51: 0x00ffff, - 52: 0x5f0000, - 53: 0x5f005f, - 54: 0x5f0087, - 55: 0x5f00af, - 56: 0x5f00d7, - 57: 0x5f00ff, - 58: 0x5f5f00, - 59: 0x5f5f5f, - 60: 0x5f5f87, - 61: 0x5f5faf, - 62: 0x5f5fd7, - 63: 0x5f5fff, - 64: 0x5f8700, - 65: 0x5f875f, - 66: 0x5f8787, - 67: 0x5f87af, - 68: 0x5f87d7, - 69: 0x5f87ff, - 70: 0x5faf00, - 71: 0x5faf5f, - 72: 0x5faf87, - 73: 0x5fafaf, - 74: 0x5fafd7, - 75: 0x5fafff, - 76: 0x5fd700, - 77: 0x5fd75f, - 78: 0x5fd787, - 79: 0x5fd7af, - 80: 0x5fd7d7, - 81: 0x5fd7ff, - 82: 0x5fff00, - 83: 0x5fff5f, - 84: 0x5fff87, - 85: 0x5fffaf, - 86: 0x5fffd7, - 87: 0x5fffff, - 88: 0x870000, - 89: 0x87005f, - 90: 0x870087, - 91: 0x8700af, - 92: 0x8700d7, - 93: 0x8700ff, - 94: 0x875f00, - 95: 0x875f5f, - 96: 0x875f87, - 97: 0x875faf, - 98: 0x875fd7, - 99: 0x875fff, - 100: 0x878700, - 101: 0x87875f, - 102: 0x878787, - 103: 0x8787af, - 104: 0x8787d7, - 105: 0x8787ff, - 106: 0x87af00, - 107: 0x87af5f, - 108: 0x87af87, - 109: 0x87afaf, - 110: 0x87afd7, - 111: 0x87afff, - 112: 0x87d700, - 113: 0x87d75f, - 114: 0x87d787, - 115: 0x87d7af, - 116: 0x87d7d7, - 117: 0x87d7ff, - 118: 0x87ff00, - 119: 0x87ff5f, - 120: 0x87ff87, - 121: 0x87ffaf, - 122: 0x87ffd7, - 123: 0x87ffff, - 124: 0xaf0000, - 125: 0xaf005f, - 126: 0xaf0087, - 127: 0xaf00af, - 128: 0xaf00d7, - 129: 0xaf00ff, - 130: 0xaf5f00, - 131: 0xaf5f5f, - 132: 0xaf5f87, - 133: 0xaf5faf, - 134: 0xaf5fd7, - 135: 0xaf5fff, - 136: 0xaf8700, - 137: 0xaf875f, - 138: 0xaf8787, - 139: 0xaf87af, - 140: 0xaf87d7, - 141: 0xaf87ff, - 142: 0xafaf00, - 143: 0xafaf5f, - 144: 0xafaf87, - 145: 0xafafaf, - 146: 0xafafd7, - 147: 0xafafff, - 148: 0xafd700, - 149: 0xafd75f, - 150: 0xafd787, - 151: 0xafd7af, - 152: 0xafd7d7, - 153: 0xafd7ff, - 154: 0xafff00, - 155: 0xafff5f, - 156: 0xafff87, - 157: 0xafffaf, - 158: 0xafffd7, - 159: 0xafffff, - 160: 0xd70000, - 161: 0xd7005f, - 162: 0xd70087, - 163: 0xd700af, - 164: 0xd700d7, - 165: 0xd700ff, - 166: 0xd75f00, - 167: 0xd75f5f, - 168: 0xd75f87, - 169: 0xd75faf, - 170: 0xd75fd7, - 171: 0xd75fff, - 172: 0xd78700, - 173: 0xd7875f, - 174: 0xd78787, - 175: 0xd787af, - 176: 0xd787d7, - 177: 0xd787ff, - 178: 0xd7af00, - 179: 0xd7af5f, - 180: 0xd7af87, - 181: 0xd7afaf, - 182: 0xd7afd7, - 183: 0xd7afff, - 184: 0xd7d700, - 185: 0xd7d75f, - 186: 0xd7d787, - 187: 0xd7d7af, - 188: 0xd7d7d7, - 189: 0xd7d7ff, - 190: 0xd7ff00, - 191: 0xd7ff5f, - 192: 0xd7ff87, - 193: 0xd7ffaf, - 194: 0xd7ffd7, - 195: 0xd7ffff, - 196: 0xff0000, - 197: 0xff005f, - 198: 0xff0087, - 199: 0xff00af, - 200: 0xff00d7, - 201: 0xff00ff, - 202: 0xff5f00, - 203: 0xff5f5f, - 204: 0xff5f87, - 205: 0xff5faf, - 206: 0xff5fd7, - 207: 0xff5fff, - 208: 0xff8700, - 209: 0xff875f, - 210: 0xff8787, - 211: 0xff87af, - 212: 0xff87d7, - 213: 0xff87ff, - 214: 0xffaf00, - 215: 0xffaf5f, - 216: 0xffaf87, - 217: 0xffafaf, - 218: 0xffafd7, - 219: 0xffafff, - 220: 0xffd700, - 221: 0xffd75f, - 222: 0xffd787, - 223: 0xffd7af, - 224: 0xffd7d7, - 225: 0xffd7ff, - 226: 0xffff00, - 227: 0xffff5f, - 228: 0xffff87, - 229: 0xffffaf, - 230: 0xffffd7, - 231: 0xffffff, - 232: 0x080808, - 233: 0x121212, - 234: 0x1c1c1c, - 235: 0x262626, - 236: 0x303030, - 237: 0x3a3a3a, - 238: 0x444444, - 239: 0x4e4e4e, - 240: 0x585858, - 241: 0x626262, - 242: 0x6c6c6c, - 243: 0x767676, - 244: 0x808080, - 245: 0x8a8a8a, - 246: 0x949494, - 247: 0x9e9e9e, - 248: 0xa8a8a8, - 249: 0xb2b2b2, - 250: 0xbcbcbc, - 251: 0xc6c6c6, - 252: 0xd0d0d0, - 253: 0xdadada, - 254: 0xe4e4e4, - 255: 0xeeeeee, -} - -// `\033]0;TITLESTR\007` -func doTitleSequence(er *bytes.Reader) error { - var c byte - var err error - - c, err = er.ReadByte() - if err != nil { - return err - } - if c != '0' && c != '2' { - return nil - } - c, err = er.ReadByte() - if err != nil { - return err - } - if c != ';' { - return nil - } - title := make([]byte, 0, 80) - for { - c, err = er.ReadByte() - if err != nil { - return err - } - if c == 0x07 || c == '\n' { - break - } - title = append(title, c) - } - if len(title) > 0 { - title8, err := syscall.UTF16PtrFromString(string(title)) - if err == nil { - procSetConsoleTitle.Call(uintptr(unsafe.Pointer(title8))) - } - } - return nil -} - -// returns Atoi(s) unless s == "" in which case it returns def -func atoiWithDefault(s string, def int) (int, error) { - if s == "" { - return def, nil - } - return strconv.Atoi(s) -} - -// Write writes data on console -func (w *Writer) Write(data []byte) (n int, err error) { - w.mutex.Lock() - defer w.mutex.Unlock() - var csbi consoleScreenBufferInfo - procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi))) - - handle := w.handle - - var er *bytes.Reader - if w.rest.Len() > 0 { - var rest bytes.Buffer - w.rest.WriteTo(&rest) - w.rest.Reset() - rest.Write(data) - er = bytes.NewReader(rest.Bytes()) - } else { - er = bytes.NewReader(data) - } - var bw [1]byte -loop: - for { - c1, err := er.ReadByte() - if err != nil { - break loop - } - if c1 != 0x1b { - bw[0] = c1 - w.out.Write(bw[:]) - continue - } - c2, err := er.ReadByte() - if err != nil { - break loop - } - - switch c2 { - case '>': - continue - case ']': - w.rest.WriteByte(c1) - w.rest.WriteByte(c2) - er.WriteTo(&w.rest) - if bytes.IndexByte(w.rest.Bytes(), 0x07) == -1 { - break loop - } - er = bytes.NewReader(w.rest.Bytes()[2:]) - err := doTitleSequence(er) - if err != nil { - break loop - } - w.rest.Reset() - continue - // https://github.com/mattn/go-colorable/issues/27 - case '7': - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) - w.oldpos = csbi.cursorPosition - continue - case '8': - procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&w.oldpos))) - continue - case 0x5b: - // execute part after switch - default: - continue - } - - w.rest.WriteByte(c1) - w.rest.WriteByte(c2) - er.WriteTo(&w.rest) - - var buf bytes.Buffer - var m byte - for i, c := range w.rest.Bytes()[2:] { - if ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '@' { - m = c - er = bytes.NewReader(w.rest.Bytes()[2+i+1:]) - w.rest.Reset() - break - } - buf.Write([]byte(string(c))) - } - if m == 0 { - break loop - } - - switch m { - case 'A': - n, err = atoiWithDefault(buf.String(), 1) - if err != nil { - continue - } - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) - csbi.cursorPosition.y -= short(n) - procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition))) - case 'B': - n, err = atoiWithDefault(buf.String(), 1) - if err != nil { - continue - } - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) - csbi.cursorPosition.y += short(n) - procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition))) - case 'C': - n, err = atoiWithDefault(buf.String(), 1) - if err != nil { - continue - } - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) - csbi.cursorPosition.x += short(n) - procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition))) - case 'D': - n, err = atoiWithDefault(buf.String(), 1) - if err != nil { - continue - } - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) - csbi.cursorPosition.x -= short(n) - if csbi.cursorPosition.x < 0 { - csbi.cursorPosition.x = 0 - } - procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition))) - case 'E': - n, err = strconv.Atoi(buf.String()) - if err != nil { - continue - } - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) - csbi.cursorPosition.x = 0 - csbi.cursorPosition.y += short(n) - procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition))) - case 'F': - n, err = strconv.Atoi(buf.String()) - if err != nil { - continue - } - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) - csbi.cursorPosition.x = 0 - csbi.cursorPosition.y -= short(n) - procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition))) - case 'G': - n, err = strconv.Atoi(buf.String()) - if err != nil { - continue - } - if n < 1 { - n = 1 - } - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) - csbi.cursorPosition.x = short(n - 1) - procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition))) - case 'H', 'f': - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) - if buf.Len() > 0 { - token := strings.Split(buf.String(), ";") - switch len(token) { - case 1: - n1, err := strconv.Atoi(token[0]) - if err != nil { - continue - } - csbi.cursorPosition.y = short(n1 - 1) - case 2: - n1, err := strconv.Atoi(token[0]) - if err != nil { - continue - } - n2, err := strconv.Atoi(token[1]) - if err != nil { - continue - } - csbi.cursorPosition.x = short(n2 - 1) - csbi.cursorPosition.y = short(n1 - 1) - } - } else { - csbi.cursorPosition.y = 0 - } - procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition))) - case 'J': - n := 0 - if buf.Len() > 0 { - n, err = strconv.Atoi(buf.String()) - if err != nil { - continue - } - } - var count, written dword - var cursor coord - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) - switch n { - case 0: - cursor = coord{x: csbi.cursorPosition.x, y: csbi.cursorPosition.y} - count = dword(csbi.size.x) - dword(csbi.cursorPosition.x) + dword(csbi.size.y-csbi.cursorPosition.y)*dword(csbi.size.x) - case 1: - cursor = coord{x: csbi.window.left, y: csbi.window.top} - count = dword(csbi.size.x) - dword(csbi.cursorPosition.x) + dword(csbi.window.top-csbi.cursorPosition.y)*dword(csbi.size.x) - case 2: - cursor = coord{x: csbi.window.left, y: csbi.window.top} - count = dword(csbi.size.x) - dword(csbi.cursorPosition.x) + dword(csbi.size.y-csbi.cursorPosition.y)*dword(csbi.size.x) - } - procFillConsoleOutputCharacter.Call(uintptr(handle), uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written))) - procFillConsoleOutputAttribute.Call(uintptr(handle), uintptr(csbi.attributes), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written))) - case 'K': - n := 0 - if buf.Len() > 0 { - n, err = strconv.Atoi(buf.String()) - if err != nil { - continue - } - } - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) - var cursor coord - var count, written dword - switch n { - case 0: - cursor = coord{x: csbi.cursorPosition.x, y: csbi.cursorPosition.y} - count = dword(csbi.size.x - csbi.cursorPosition.x) - case 1: - cursor = coord{x: csbi.window.left, y: csbi.cursorPosition.y} - count = dword(csbi.size.x - csbi.cursorPosition.x) - case 2: - cursor = coord{x: csbi.window.left, y: csbi.cursorPosition.y} - count = dword(csbi.size.x) - } - procFillConsoleOutputCharacter.Call(uintptr(handle), uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written))) - procFillConsoleOutputAttribute.Call(uintptr(handle), uintptr(csbi.attributes), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written))) - case 'X': - n := 0 - if buf.Len() > 0 { - n, err = strconv.Atoi(buf.String()) - if err != nil { - continue - } - } - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) - var cursor coord - var written dword - cursor = coord{x: csbi.cursorPosition.x, y: csbi.cursorPosition.y} - procFillConsoleOutputCharacter.Call(uintptr(handle), uintptr(' '), uintptr(n), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written))) - procFillConsoleOutputAttribute.Call(uintptr(handle), uintptr(csbi.attributes), uintptr(n), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written))) - case 'm': - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) - attr := csbi.attributes - cs := buf.String() - if cs == "" { - procSetConsoleTextAttribute.Call(uintptr(handle), uintptr(w.oldattr)) - continue - } - token := strings.Split(cs, ";") - for i := 0; i < len(token); i++ { - ns := token[i] - if n, err = strconv.Atoi(ns); err == nil { - switch { - case n == 0 || n == 100: - attr = w.oldattr - case n == 4: - attr |= commonLvbUnderscore - case (1 <= n && n <= 3) || n == 5: - attr |= foregroundIntensity - case n == 7 || n == 27: - attr = - (attr &^ (foregroundMask | backgroundMask)) | - ((attr & foregroundMask) << 4) | - ((attr & backgroundMask) >> 4) - case n == 22: - attr &^= foregroundIntensity - case n == 24: - attr &^= commonLvbUnderscore - case 30 <= n && n <= 37: - attr &= backgroundMask - if (n-30)&1 != 0 { - attr |= foregroundRed - } - if (n-30)&2 != 0 { - attr |= foregroundGreen - } - if (n-30)&4 != 0 { - attr |= foregroundBlue - } - case n == 38: // set foreground color. - if i < len(token)-2 && (token[i+1] == "5" || token[i+1] == "05") { - if n256, err := strconv.Atoi(token[i+2]); err == nil { - if n256foreAttr == nil { - n256setup() - } - attr &= backgroundMask - attr |= n256foreAttr[n256%len(n256foreAttr)] - i += 2 - } - } else if len(token) == 5 && token[i+1] == "2" { - var r, g, b int - r, _ = strconv.Atoi(token[i+2]) - g, _ = strconv.Atoi(token[i+3]) - b, _ = strconv.Atoi(token[i+4]) - i += 4 - if r > 127 { - attr |= foregroundRed - } - if g > 127 { - attr |= foregroundGreen - } - if b > 127 { - attr |= foregroundBlue - } - } else { - attr = attr & (w.oldattr & backgroundMask) - } - case n == 39: // reset foreground color. - attr &= backgroundMask - attr |= w.oldattr & foregroundMask - case 40 <= n && n <= 47: - attr &= foregroundMask - if (n-40)&1 != 0 { - attr |= backgroundRed - } - if (n-40)&2 != 0 { - attr |= backgroundGreen - } - if (n-40)&4 != 0 { - attr |= backgroundBlue - } - case n == 48: // set background color. - if i < len(token)-2 && token[i+1] == "5" { - if n256, err := strconv.Atoi(token[i+2]); err == nil { - if n256backAttr == nil { - n256setup() - } - attr &= foregroundMask - attr |= n256backAttr[n256%len(n256backAttr)] - i += 2 - } - } else if len(token) == 5 && token[i+1] == "2" { - var r, g, b int - r, _ = strconv.Atoi(token[i+2]) - g, _ = strconv.Atoi(token[i+3]) - b, _ = strconv.Atoi(token[i+4]) - i += 4 - if r > 127 { - attr |= backgroundRed - } - if g > 127 { - attr |= backgroundGreen - } - if b > 127 { - attr |= backgroundBlue - } - } else { - attr = attr & (w.oldattr & foregroundMask) - } - case n == 49: // reset foreground color. - attr &= foregroundMask - attr |= w.oldattr & backgroundMask - case 90 <= n && n <= 97: - attr = (attr & backgroundMask) - attr |= foregroundIntensity - if (n-90)&1 != 0 { - attr |= foregroundRed - } - if (n-90)&2 != 0 { - attr |= foregroundGreen - } - if (n-90)&4 != 0 { - attr |= foregroundBlue - } - case 100 <= n && n <= 107: - attr = (attr & foregroundMask) - attr |= backgroundIntensity - if (n-100)&1 != 0 { - attr |= backgroundRed - } - if (n-100)&2 != 0 { - attr |= backgroundGreen - } - if (n-100)&4 != 0 { - attr |= backgroundBlue - } - } - procSetConsoleTextAttribute.Call(uintptr(handle), uintptr(attr)) - } - } - case 'h': - var ci consoleCursorInfo - cs := buf.String() - if cs == "5>" { - procGetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&ci))) - ci.visible = 0 - procSetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&ci))) - } else if cs == "?25" { - procGetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&ci))) - ci.visible = 1 - procSetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&ci))) - } else if cs == "?1049" { - if w.althandle == 0 { - h, _, _ := procCreateConsoleScreenBuffer.Call(uintptr(genericRead|genericWrite), 0, 0, uintptr(consoleTextmodeBuffer), 0, 0) - w.althandle = syscall.Handle(h) - if w.althandle != 0 { - handle = w.althandle - } - } - } - case 'l': - var ci consoleCursorInfo - cs := buf.String() - if cs == "5>" { - procGetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&ci))) - ci.visible = 1 - procSetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&ci))) - } else if cs == "?25" { - procGetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&ci))) - ci.visible = 0 - procSetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&ci))) - } else if cs == "?1049" { - if w.althandle != 0 { - syscall.CloseHandle(w.althandle) - w.althandle = 0 - handle = w.handle - } - } - case 's': - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) - w.oldpos = csbi.cursorPosition - case 'u': - procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&w.oldpos))) - } - } - - return len(data), nil -} - -type consoleColor struct { - rgb int - red bool - green bool - blue bool - intensity bool -} - -func (c consoleColor) foregroundAttr() (attr word) { - if c.red { - attr |= foregroundRed - } - if c.green { - attr |= foregroundGreen - } - if c.blue { - attr |= foregroundBlue - } - if c.intensity { - attr |= foregroundIntensity - } - return -} - -func (c consoleColor) backgroundAttr() (attr word) { - if c.red { - attr |= backgroundRed - } - if c.green { - attr |= backgroundGreen - } - if c.blue { - attr |= backgroundBlue - } - if c.intensity { - attr |= backgroundIntensity - } - return -} - -var color16 = []consoleColor{ - {0x000000, false, false, false, false}, - {0x000080, false, false, true, false}, - {0x008000, false, true, false, false}, - {0x008080, false, true, true, false}, - {0x800000, true, false, false, false}, - {0x800080, true, false, true, false}, - {0x808000, true, true, false, false}, - {0xc0c0c0, true, true, true, false}, - {0x808080, false, false, false, true}, - {0x0000ff, false, false, true, true}, - {0x00ff00, false, true, false, true}, - {0x00ffff, false, true, true, true}, - {0xff0000, true, false, false, true}, - {0xff00ff, true, false, true, true}, - {0xffff00, true, true, false, true}, - {0xffffff, true, true, true, true}, -} - -type hsv struct { - h, s, v float32 -} - -func (a hsv) dist(b hsv) float32 { - dh := a.h - b.h - switch { - case dh > 0.5: - dh = 1 - dh - case dh < -0.5: - dh = -1 - dh - } - ds := a.s - b.s - dv := a.v - b.v - return float32(math.Sqrt(float64(dh*dh + ds*ds + dv*dv))) -} - -func toHSV(rgb int) hsv { - r, g, b := float32((rgb&0xFF0000)>>16)/256.0, - float32((rgb&0x00FF00)>>8)/256.0, - float32(rgb&0x0000FF)/256.0 - min, max := minmax3f(r, g, b) - h := max - min - if h > 0 { - if max == r { - h = (g - b) / h - if h < 0 { - h += 6 - } - } else if max == g { - h = 2 + (b-r)/h - } else { - h = 4 + (r-g)/h - } - } - h /= 6.0 - s := max - min - if max != 0 { - s /= max - } - v := max - return hsv{h: h, s: s, v: v} -} - -type hsvTable []hsv - -func toHSVTable(rgbTable []consoleColor) hsvTable { - t := make(hsvTable, len(rgbTable)) - for i, c := range rgbTable { - t[i] = toHSV(c.rgb) - } - return t -} - -func (t hsvTable) find(rgb int) consoleColor { - hsv := toHSV(rgb) - n := 7 - l := float32(5.0) - for i, p := range t { - d := hsv.dist(p) - if d < l { - l, n = d, i - } - } - return color16[n] -} - -func minmax3f(a, b, c float32) (min, max float32) { - if a < b { - if b < c { - return a, c - } else if a < c { - return a, b - } else { - return c, b - } - } else { - if a < c { - return b, c - } else if b < c { - return b, a - } else { - return c, a - } - } -} - -var n256foreAttr []word -var n256backAttr []word - -func n256setup() { - n256foreAttr = make([]word, 256) - n256backAttr = make([]word, 256) - t := toHSVTable(color16) - for i, rgb := range color256 { - c := t.find(rgb) - n256foreAttr[i] = c.foregroundAttr() - n256backAttr[i] = c.backgroundAttr() - } -} - -// EnableColorsStdout enable colors if possible. -func EnableColorsStdout(enabled *bool) func() { - var mode uint32 - h := os.Stdout.Fd() - if r, _, _ := procGetConsoleMode.Call(h, uintptr(unsafe.Pointer(&mode))); r != 0 { - if r, _, _ = procSetConsoleMode.Call(h, uintptr(mode|cENABLE_VIRTUAL_TERMINAL_PROCESSING)); r != 0 { - if enabled != nil { - *enabled = true - } - return func() { - procSetConsoleMode.Call(h, uintptr(mode)) - } - } - } - if enabled != nil { - *enabled = true - } - return func() {} -} diff --git a/vendor/github.com/mattn/go-colorable/go.mod b/vendor/github.com/mattn/go-colorable/go.mod deleted file mode 100644 index 1e590b819..000000000 --- a/vendor/github.com/mattn/go-colorable/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module github.com/mattn/go-colorable - -require ( - github.com/mattn/go-isatty v0.0.12 - golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect -) - -go 1.13 diff --git a/vendor/github.com/mattn/go-colorable/go.sum b/vendor/github.com/mattn/go-colorable/go.sum deleted file mode 100644 index cf5b95d97..000000000 --- a/vendor/github.com/mattn/go-colorable/go.sum +++ /dev/null @@ -1,5 +0,0 @@ -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/vendor/github.com/mattn/go-colorable/go.test.sh b/vendor/github.com/mattn/go-colorable/go.test.sh deleted file mode 100644 index 012162b07..000000000 --- a/vendor/github.com/mattn/go-colorable/go.test.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -set -e -echo "" > coverage.txt - -for d in $(go list ./... | grep -v vendor); do - go test -race -coverprofile=profile.out -covermode=atomic "$d" - if [ -f profile.out ]; then - cat profile.out >> coverage.txt - rm profile.out - fi -done diff --git a/vendor/github.com/mattn/go-colorable/noncolorable.go b/vendor/github.com/mattn/go-colorable/noncolorable.go deleted file mode 100644 index 95f2c6be2..000000000 --- a/vendor/github.com/mattn/go-colorable/noncolorable.go +++ /dev/null @@ -1,55 +0,0 @@ -package colorable - -import ( - "bytes" - "io" -) - -// NonColorable holds writer but removes escape sequence. -type NonColorable struct { - out io.Writer -} - -// NewNonColorable returns new instance of Writer which removes escape sequence from Writer. -func NewNonColorable(w io.Writer) io.Writer { - return &NonColorable{out: w} -} - -// Write writes data on console -func (w *NonColorable) Write(data []byte) (n int, err error) { - er := bytes.NewReader(data) - var bw [1]byte -loop: - for { - c1, err := er.ReadByte() - if err != nil { - break loop - } - if c1 != 0x1b { - bw[0] = c1 - w.out.Write(bw[:]) - continue - } - c2, err := er.ReadByte() - if err != nil { - break loop - } - if c2 != 0x5b { - continue - } - - var buf bytes.Buffer - for { - c, err := er.ReadByte() - if err != nil { - break loop - } - if ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '@' { - break - } - buf.Write([]byte(string(c))) - } - } - - return len(data), nil -} diff --git a/vendor/github.com/mgechev/dots/.travis.yml b/vendor/github.com/mgechev/dots/.travis.yml deleted file mode 100644 index f4a4a7363..000000000 --- a/vendor/github.com/mgechev/dots/.travis.yml +++ /dev/null @@ -1,2 +0,0 @@ -language: go -go: master diff --git a/vendor/github.com/mgechev/dots/LICENSE b/vendor/github.com/mgechev/dots/LICENSE deleted file mode 100644 index c617c7e01..000000000 --- a/vendor/github.com/mgechev/dots/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2018 Minko Gechev - -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/mgechev/dots/README.md b/vendor/github.com/mgechev/dots/README.md deleted file mode 100644 index 1203aef5f..000000000 --- a/vendor/github.com/mgechev/dots/README.md +++ /dev/null @@ -1,100 +0,0 @@ -[![Build Status](https://travis-ci.org/mgechev/dots.svg?branch=master)](https://travis-ci.org/mgechev/dots) - -# Dots - -Implements the wildcard file matching in Go used by golint, go test etc. - -## Usage - -```go -import "github.com/mgechev/dots" - -func main() { - result, err := dots.Resolve([]string{"./fixtures/..."}, []string{"./fixtures/foo"}) - for _, f := range result { - fmt.Println(f); - } -} -``` - -If we suppose that we have the following directory structure: - -```text -├── README.md -├── fixtures -│   ├── bar -│   │   ├── bar1.go -│   │   └── bar2.go -│   ├── baz -│   │   ├── baz1.go -│   │   ├── baz2.go -│   │   └── baz3.go -│   └── foo -│   ├── foo1.go -│   ├── foo2.go -│   └── foo3.go -└── main.go -``` - -The result will be: - -```text -fixtures/bar/bar1.go -fixtures/bar/bar2.go -fixtures/baz/baz1.go -fixtures/baz/baz2.go -fixtures/baz/baz3.go -``` - -`dots` supports wildcard in both - the first and the last argument of `Resolve`, which means that you can ignore files based on a wildcard: - -```go -dots.Resolve([]string{"github.com/mgechev/dots"}, []string{"./..."}) // empty list -dots.Resolve([]string{"./fixtures/bar/..."}, []string{"./fixture/foo/...", "./fixtures/baz/..."}) // bar1.go, bar2.go -``` - -## Preserve package structure - -`dots` allow you to receive a slice of slices where each nested slice represents an individual package: - -```go -dots.ResolvePackages([]string{"github.com/mgechev/dots/..."}, []string{}) -``` - -So we will get the result: - -```text -[ - [ - "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/bar/bar1.go", - "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/bar/bar2.go" - ], - [ - "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/baz/baz1.go", - "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/baz/baz2.go", - "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/baz/baz3.go" - ], - [ - "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/foo/foo1.go", - "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/foo/foo2.go", - "$GOROOT/src/github.com/mgechev/dots/fixtures/dummy/foo/foo3.go" - ], - [ - "$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/baz/baz1.go", - "$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/baz/baz2.go" - ], - [ - "$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/foo/foo1.go", - "$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/foo/foo2.go" - ], - [ - "$GOROOT/src/github.com/mgechev/dots/fixtures/pkg/foo/bar/bar1.go" - ] -] -``` - -This method is especially useful, when you want to perform type checking over given package from the result. - -## License - -MIT diff --git a/vendor/github.com/mgechev/dots/resolve.go b/vendor/github.com/mgechev/dots/resolve.go deleted file mode 100644 index 309ba18ad..000000000 --- a/vendor/github.com/mgechev/dots/resolve.go +++ /dev/null @@ -1,456 +0,0 @@ -package dots - -import ( - "go/build" - "log" - "os" - "path" - "path/filepath" - "regexp" - "runtime" - "strings" -) - -var ( - buildContext = build.Default - goroot = filepath.Clean(runtime.GOROOT()) - gorootSrc = filepath.Join(goroot, "src") -) - -func flatten(arr [][]string) []string { - var res []string - for _, e := range arr { - res = append(res, e...) - } - return res -} - -// Resolve accepts a slice of paths with optional "..." placeholder and a slice with paths to be skipped. -// The final result is the set of all files from the selected directories subtracted with -// the files in the skip slice. -func Resolve(includePatterns, skipPatterns []string) ([]string, error) { - skip, err := resolvePatterns(skipPatterns) - filter := newPathFilter(flatten(skip)) - if err != nil { - return nil, err - } - - pathSet := map[string]bool{} - includePackages, err := resolvePatterns(includePatterns) - include := flatten(includePackages) - if err != nil { - return nil, err - } - - var result []string - for _, i := range include { - if _, ok := pathSet[i]; !ok && !filter(i) { - pathSet[i] = true - result = append(result, i) - } - } - return result, err -} - -// ResolvePackages accepts a slice of paths with optional "..." placeholder and a slice with paths to be skipped. -// The final result is the set of all files from the selected directories subtracted with -// the files in the skip slice. The difference between `Resolve` and `ResolvePackages` -// is that `ResolvePackages` preserves the package structure in the nested slices. -func ResolvePackages(includePatterns, skipPatterns []string) ([][]string, error) { - skip, err := resolvePatterns(skipPatterns) - filter := newPathFilter(flatten(skip)) - if err != nil { - return nil, err - } - - pathSet := map[string]bool{} - include, err := resolvePatterns(includePatterns) - if err != nil { - return nil, err - } - - var result [][]string - for _, p := range include { - var packageFiles []string - for _, f := range p { - if _, ok := pathSet[f]; !ok && !filter(f) { - pathSet[f] = true - packageFiles = append(packageFiles, f) - } - } - result = append(result, packageFiles) - } - return result, err -} - -func isDir(filename string) bool { - fi, err := os.Stat(filename) - return err == nil && fi.IsDir() -} - -func exists(filename string) bool { - _, err := os.Stat(filename) - return err == nil -} - -func resolveDir(dirname string) ([]string, error) { - pkg, err := build.ImportDir(dirname, 0) - return resolveImportedPackage(pkg, err) -} - -func resolvePackage(pkgname string) ([]string, error) { - pkg, err := build.Import(pkgname, ".", 0) - return resolveImportedPackage(pkg, err) -} - -func resolveImportedPackage(pkg *build.Package, err error) ([]string, error) { - if err != nil { - if _, nogo := err.(*build.NoGoError); nogo { - // Don't complain if the failure is due to no Go source files. - return nil, nil - } - return nil, err - } - - var files []string - files = append(files, pkg.GoFiles...) - files = append(files, pkg.CgoFiles...) - files = append(files, pkg.TestGoFiles...) - if pkg.Dir != "." { - for i, f := range files { - files[i] = filepath.Join(pkg.Dir, f) - } - } - return files, nil -} - -func resolvePatterns(patterns []string) ([][]string, error) { - var files [][]string - for _, pattern := range patterns { - f, err := resolvePattern(pattern) - if err != nil { - return nil, err - } - files = append(files, f...) - } - return files, nil -} - -func resolvePattern(pattern string) ([][]string, error) { - // dirsRun, filesRun, and pkgsRun indicate whether golint is applied to - // directory, file or package targets. The distinction affects which - // checks are run. It is no valid to mix target types. - var dirsRun, filesRun, pkgsRun int - var matches []string - - if strings.HasSuffix(pattern, "/...") && isDir(pattern[:len(pattern)-len("/...")]) { - dirsRun = 1 - for _, dirname := range matchPackagesInFS(pattern) { - matches = append(matches, dirname) - } - } else if isDir(pattern) { - dirsRun = 1 - matches = append(matches, pattern) - } else if exists(pattern) { - filesRun = 1 - matches = append(matches, pattern) - } else { - pkgsRun = 1 - matches = append(matches, pattern) - } - - result := [][]string{} - switch { - case dirsRun == 1: - for _, dir := range matches { - res, err := resolveDir(dir) - if err != nil { - return nil, err - } - result = append(result, res) - } - case filesRun == 1: - return [][]string{matches}, nil - case pkgsRun == 1: - for _, pkg := range importPaths(matches) { - res, err := resolvePackage(pkg) - if err != nil { - return nil, err - } - result = append(result, res) - } - } - return result, nil -} - -func newPathFilter(skip []string) func(string) bool { - filter := map[string]bool{} - for _, name := range skip { - filter[name] = true - } - - return func(path string) bool { - base := filepath.Base(path) - if filter[base] || filter[path] { - return true - } - return base != "." && base != ".." && strings.ContainsAny(base[0:1], "_.") - } -} - -// importPathsNoDotExpansion returns the import paths to use for the given -// command line, but it does no ... expansion. -func importPathsNoDotExpansion(args []string) []string { - if len(args) == 0 { - return []string{"."} - } - var out []string - for _, a := range args { - // Arguments are supposed to be import paths, but - // as a courtesy to Windows developers, rewrite \ to / - // in command-line arguments. Handles .\... and so on. - if filepath.Separator == '\\' { - a = strings.Replace(a, `\`, `/`, -1) - } - - // Put argument in canonical form, but preserve leading ./. - if strings.HasPrefix(a, "./") { - a = "./" + path.Clean(a) - if a == "./." { - a = "." - } - } else { - a = path.Clean(a) - } - if a == "all" || a == "std" { - out = append(out, matchPackages(a)...) - continue - } - out = append(out, a) - } - return out -} - -// importPaths returns the import paths to use for the given command line. -func importPaths(args []string) []string { - args = importPathsNoDotExpansion(args) - var out []string - for _, a := range args { - if strings.Contains(a, "...") { - if build.IsLocalImport(a) { - out = append(out, matchPackagesInFS(a)...) - } else { - out = append(out, matchPackages(a)...) - } - continue - } - out = append(out, a) - } - return out -} - -// matchPattern(pattern)(name) reports whether -// name matches pattern. Pattern is a limited glob -// pattern in which '...' means 'any string' and there -// is no other special syntax. -func matchPattern(pattern string) func(name string) bool { - re := regexp.QuoteMeta(pattern) - re = strings.Replace(re, `\.\.\.`, `.*`, -1) - // Special case: foo/... matches foo too. - if strings.HasSuffix(re, `/.*`) { - re = re[:len(re)-len(`/.*`)] + `(/.*)?` - } - reg := regexp.MustCompile(`^` + re + `$`) - return func(name string) bool { - return reg.MatchString(name) - } -} - -// hasPathPrefix reports whether the path s begins with the -// elements in prefix. -func hasPathPrefix(s, prefix string) bool { - switch { - default: - return false - case len(s) == len(prefix): - return s == prefix - case len(s) > len(prefix): - if prefix != "" && prefix[len(prefix)-1] == '/' { - return strings.HasPrefix(s, prefix) - } - return s[len(prefix)] == '/' && s[:len(prefix)] == prefix - } -} - -// treeCanMatchPattern(pattern)(name) reports whether -// name or children of name can possibly match pattern. -// Pattern is the same limited glob accepted by matchPattern. -func treeCanMatchPattern(pattern string) func(name string) bool { - wildCard := false - if i := strings.Index(pattern, "..."); i >= 0 { - wildCard = true - pattern = pattern[:i] - } - return func(name string) bool { - return len(name) <= len(pattern) && hasPathPrefix(pattern, name) || - wildCard && strings.HasPrefix(name, pattern) - } -} - -func matchPackages(pattern string) []string { - match := func(string) bool { return true } - treeCanMatch := func(string) bool { return true } - if pattern != "all" && pattern != "std" { - match = matchPattern(pattern) - treeCanMatch = treeCanMatchPattern(pattern) - } - - have := map[string]bool{ - "builtin": true, // ignore pseudo-package that exists only for documentation - } - if !buildContext.CgoEnabled { - have["runtime/cgo"] = true // ignore during walk - } - var pkgs []string - - // Commands - cmd := filepath.Join(goroot, "src/cmd") + string(filepath.Separator) - filepath.Walk(cmd, func(path string, fi os.FileInfo, err error) error { - if err != nil || !fi.IsDir() || path == cmd { - return nil - } - name := path[len(cmd):] - if !treeCanMatch(name) { - return filepath.SkipDir - } - // Commands are all in cmd/, not in subdirectories. - if strings.Contains(name, string(filepath.Separator)) { - return filepath.SkipDir - } - - // We use, e.g., cmd/gofmt as the pseudo import path for gofmt. - name = "cmd/" + name - if have[name] { - return nil - } - have[name] = true - if !match(name) { - return nil - } - _, err = buildContext.ImportDir(path, 0) - if err != nil { - if _, noGo := err.(*build.NoGoError); !noGo { - log.Print(err) - } - return nil - } - pkgs = append(pkgs, name) - return nil - }) - - for _, src := range buildContext.SrcDirs() { - if (pattern == "std" || pattern == "cmd") && src != gorootSrc { - continue - } - src = filepath.Clean(src) + string(filepath.Separator) - root := src - if pattern == "cmd" { - root += "cmd" + string(filepath.Separator) - } - filepath.Walk(root, func(path string, fi os.FileInfo, err error) error { - if err != nil || !fi.IsDir() || path == src { - return nil - } - - // Avoid .foo, _foo, and testdata directory trees. - _, elem := filepath.Split(path) - if strings.HasPrefix(elem, ".") || strings.HasPrefix(elem, "_") || elem == "testdata" { - return filepath.SkipDir - } - - name := filepath.ToSlash(path[len(src):]) - if pattern == "std" && (strings.Contains(name, ".") || name == "cmd") { - // The name "std" is only the standard library. - // If the name is cmd, it's the root of the command tree. - return filepath.SkipDir - } - if !treeCanMatch(name) { - return filepath.SkipDir - } - if have[name] { - return nil - } - have[name] = true - if !match(name) { - return nil - } - _, err = buildContext.ImportDir(path, 0) - if err != nil { - if _, noGo := err.(*build.NoGoError); noGo { - return nil - } - } - pkgs = append(pkgs, name) - return nil - }) - } - return pkgs -} - -func matchPackagesInFS(pattern string) []string { - // Find directory to begin the scan. - // Could be smarter but this one optimization - // is enough for now, since ... is usually at the - // end of a path. - i := strings.Index(pattern, "...") - dir, _ := path.Split(pattern[:i]) - - // pattern begins with ./ or ../. - // path.Clean will discard the ./ but not the ../. - // We need to preserve the ./ for pattern matching - // and in the returned import paths. - prefix := "" - if strings.HasPrefix(pattern, "./") { - prefix = "./" - } - match := matchPattern(pattern) - - var pkgs []string - filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error { - if err != nil || !fi.IsDir() { - return nil - } - if path == dir { - // filepath.Walk starts at dir and recurses. For the recursive case, - // the path is the result of filepath.Join, which calls filepath.Clean. - // The initial case is not Cleaned, though, so we do this explicitly. - // - // This converts a path like "./io/" to "io". Without this step, running - // "cd $GOROOT/src/pkg; go list ./io/..." would incorrectly skip the io - // package, because prepending the prefix "./" to the unclean path would - // result in "././io", and match("././io") returns false. - path = filepath.Clean(path) - } - - // Avoid .foo, _foo, and testdata directory trees, but do not avoid "." or "..". - _, elem := filepath.Split(path) - dot := strings.HasPrefix(elem, ".") && elem != "." && elem != ".." - if dot || strings.HasPrefix(elem, "_") || elem == "testdata" { - return filepath.SkipDir - } - - name := prefix + filepath.ToSlash(path) - if !match(name) { - return nil - } - if _, err = build.ImportDir(path, 0); err != nil { - if _, noGo := err.(*build.NoGoError); !noGo { - log.Print(err) - } - return nil - } - pkgs = append(pkgs, name) - return nil - }) - return pkgs -} diff --git a/vendor/github.com/mgechev/revive/LICENSE b/vendor/github.com/mgechev/revive/LICENSE deleted file mode 100644 index c617c7e01..000000000 --- a/vendor/github.com/mgechev/revive/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2018 Minko Gechev - -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/mgechev/revive/formatter/checkstyle.go b/vendor/github.com/mgechev/revive/formatter/checkstyle.go deleted file mode 100644 index bd20da888..000000000 --- a/vendor/github.com/mgechev/revive/formatter/checkstyle.go +++ /dev/null @@ -1,76 +0,0 @@ -package formatter - -import ( - "bytes" - "encoding/xml" - "github.com/mgechev/revive/lint" - plainTemplate "text/template" -) - -// Checkstyle is an implementation of the Formatter interface -// which formats the errors to Checkstyle-like format. -type Checkstyle struct { - Metadata lint.FormatterMetadata -} - -// Name returns the name of the formatter -func (f *Checkstyle) Name() string { - return "checkstyle" -} - -type issue struct { - Line int - Col int - What string - Confidence float64 - Severity lint.Severity - RuleName string -} - -// Format formats the failures gotten from the lint. -func (f *Checkstyle) Format(failures <-chan lint.Failure, config lint.Config) (string, error) { - var issues = map[string][]issue{} - for failure := range failures { - buf := new(bytes.Buffer) - xml.Escape(buf, []byte(failure.Failure)) - what := buf.String() - iss := issue{ - Line: failure.Position.Start.Line, - Col: failure.Position.Start.Column, - What: what, - Confidence: failure.Confidence, - Severity: severity(config, failure), - RuleName: failure.RuleName, - } - fn := failure.GetFilename() - if issues[fn] == nil { - issues[fn] = make([]issue, 0) - } - issues[fn] = append(issues[fn], iss) - } - - t, err := plainTemplate.New("revive").Parse(checkstyleTemplate) - if err != nil { - return "", err - } - - buf := new(bytes.Buffer) - - err = t.Execute(buf, issues) - if err != nil { - return "", err - } - - return buf.String(), nil -} - -const checkstyleTemplate = ` - -{{- range $k, $v := . }} - - {{- range $i, $issue := $v }} - - {{- end }} - -{{- end }} -` diff --git a/vendor/github.com/mgechev/revive/formatter/default.go b/vendor/github.com/mgechev/revive/formatter/default.go deleted file mode 100644 index 145e6d548..000000000 --- a/vendor/github.com/mgechev/revive/formatter/default.go +++ /dev/null @@ -1,26 +0,0 @@ -package formatter - -import ( - "fmt" - - "github.com/mgechev/revive/lint" -) - -// Default is an implementation of the Formatter interface -// which formats the errors to text. -type Default struct { - Metadata lint.FormatterMetadata -} - -// Name returns the name of the formatter -func (f *Default) Name() string { - return "default" -} - -// Format formats the failures gotten from the lint. -func (f *Default) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) { - for failure := range failures { - fmt.Printf("%v: %s\n", failure.Position.Start, failure.Failure) - } - return "", nil -} diff --git a/vendor/github.com/mgechev/revive/formatter/friendly.go b/vendor/github.com/mgechev/revive/formatter/friendly.go deleted file mode 100644 index d0a3099f8..000000000 --- a/vendor/github.com/mgechev/revive/formatter/friendly.go +++ /dev/null @@ -1,149 +0,0 @@ -package formatter - -import ( - "bytes" - "fmt" - "sort" - - "github.com/fatih/color" - "github.com/mgechev/revive/lint" - "github.com/olekukonko/tablewriter" -) - -var newLines = map[rune]bool{ - 0x000A: true, - 0x000B: true, - 0x000C: true, - 0x000D: true, - 0x0085: true, - 0x2028: true, - 0x2029: true, -} - -func getErrorEmoji() string { - return color.RedString("✘") -} - -func getWarningEmoji() string { - return color.YellowString("⚠") -} - -// Friendly is an implementation of the Formatter interface -// which formats the errors to JSON. -type Friendly struct { - Metadata lint.FormatterMetadata -} - -// Name returns the name of the formatter -func (f *Friendly) Name() string { - return "friendly" -} - -// Format formats the failures gotten from the lint. -func (f *Friendly) Format(failures <-chan lint.Failure, config lint.Config) (string, error) { - errorMap := map[string]int{} - warningMap := map[string]int{} - totalErrors := 0 - totalWarnings := 0 - for failure := range failures { - sev := severity(config, failure) - f.printFriendlyFailure(failure, sev) - if sev == lint.SeverityWarning { - warningMap[failure.RuleName] = warningMap[failure.RuleName] + 1 - totalWarnings++ - } - if sev == lint.SeverityError { - errorMap[failure.RuleName] = errorMap[failure.RuleName] + 1 - totalErrors++ - } - } - f.printSummary(totalErrors, totalWarnings) - f.printStatistics(color.RedString("Errors:"), errorMap) - f.printStatistics(color.YellowString("Warnings:"), warningMap) - return "", nil -} - -func (f *Friendly) printFriendlyFailure(failure lint.Failure, severity lint.Severity) { - f.printHeaderRow(failure, severity) - f.printFilePosition(failure) - fmt.Println() - fmt.Println() -} - -func (f *Friendly) printHeaderRow(failure lint.Failure, severity lint.Severity) { - emoji := getWarningEmoji() - if severity == lint.SeverityError { - emoji = getErrorEmoji() - } - fmt.Print(f.table([][]string{{emoji, "https://revive.run/r#" + failure.RuleName, color.GreenString(failure.Failure)}})) -} - -func (f *Friendly) printFilePosition(failure lint.Failure) { - fmt.Printf(" %s:%d:%d", failure.GetFilename(), failure.Position.Start.Line, failure.Position.Start.Column) -} - -type statEntry struct { - name string - failures int -} - -func (f *Friendly) printSummary(errors, warnings int) { - emoji := getWarningEmoji() - if errors > 0 { - emoji = getErrorEmoji() - } - problemsLabel := "problems" - if errors+warnings == 1 { - problemsLabel = "problem" - } - warningsLabel := "warnings" - if warnings == 1 { - warningsLabel = "warning" - } - errorsLabel := "errors" - if errors == 1 { - errorsLabel = "error" - } - str := fmt.Sprintf("%d %s (%d %s, %d %s)", errors+warnings, problemsLabel, errors, errorsLabel, warnings, warningsLabel) - if errors > 0 { - fmt.Printf("%s %s\n", emoji, color.RedString(str)) - fmt.Println() - return - } - if warnings > 0 { - fmt.Printf("%s %s\n", emoji, color.YellowString(str)) - fmt.Println() - return - } -} - -func (f *Friendly) printStatistics(header string, stats map[string]int) { - if len(stats) == 0 { - return - } - var data []statEntry - for name, total := range stats { - data = append(data, statEntry{name, total}) - } - sort.Slice(data, func(i, j int) bool { - return data[i].failures > data[j].failures - }) - formatted := [][]string{} - for _, entry := range data { - formatted = append(formatted, []string{color.GreenString(fmt.Sprintf("%d", entry.failures)), entry.name}) - } - fmt.Println(header) - fmt.Println(f.table(formatted)) -} - -func (f *Friendly) table(rows [][]string) string { - buf := new(bytes.Buffer) - table := tablewriter.NewWriter(buf) - table.SetBorder(false) - table.SetColumnSeparator("") - table.SetRowSeparator("") - table.SetAutoWrapText(false) - table.AppendBulk(rows) - table.Render() - return buf.String() -} diff --git a/vendor/github.com/mgechev/revive/formatter/json.go b/vendor/github.com/mgechev/revive/formatter/json.go deleted file mode 100644 index 9c939face..000000000 --- a/vendor/github.com/mgechev/revive/formatter/json.go +++ /dev/null @@ -1,40 +0,0 @@ -package formatter - -import ( - "encoding/json" - - "github.com/mgechev/revive/lint" -) - -// JSON is an implementation of the Formatter interface -// which formats the errors to JSON. -type JSON struct { - Metadata lint.FormatterMetadata -} - -// Name returns the name of the formatter -func (f *JSON) Name() string { - return "json" -} - -// jsonObject defines a JSON object of an failure -type jsonObject struct { - Severity lint.Severity - lint.Failure `json:",inline"` -} - -// Format formats the failures gotten from the lint. -func (f *JSON) Format(failures <-chan lint.Failure, config lint.Config) (string, error) { - var slice []jsonObject - for failure := range failures { - obj := jsonObject{} - obj.Severity = severity(config, failure) - obj.Failure = failure - slice = append(slice, obj) - } - result, err := json.Marshal(slice) - if err != nil { - return "", err - } - return string(result), err -} diff --git a/vendor/github.com/mgechev/revive/formatter/ndjson.go b/vendor/github.com/mgechev/revive/formatter/ndjson.go deleted file mode 100644 index aa2b1d636..000000000 --- a/vendor/github.com/mgechev/revive/formatter/ndjson.go +++ /dev/null @@ -1,34 +0,0 @@ -package formatter - -import ( - "encoding/json" - "os" - - "github.com/mgechev/revive/lint" -) - -// NDJSON is an implementation of the Formatter interface -// which formats the errors to NDJSON stream. -type NDJSON struct { - Metadata lint.FormatterMetadata -} - -// Name returns the name of the formatter -func (f *NDJSON) Name() string { - return "ndjson" -} - -// Format formats the failures gotten from the lint. -func (f *NDJSON) Format(failures <-chan lint.Failure, config lint.Config) (string, error) { - enc := json.NewEncoder(os.Stdout) - for failure := range failures { - obj := jsonObject{} - obj.Severity = severity(config, failure) - obj.Failure = failure - err := enc.Encode(obj) - if err != nil { - return "", err - } - } - return "", nil -} diff --git a/vendor/github.com/mgechev/revive/formatter/plain.go b/vendor/github.com/mgechev/revive/formatter/plain.go deleted file mode 100644 index a854d2562..000000000 --- a/vendor/github.com/mgechev/revive/formatter/plain.go +++ /dev/null @@ -1,26 +0,0 @@ -package formatter - -import ( - "fmt" - - "github.com/mgechev/revive/lint" -) - -// Plain is an implementation of the Formatter interface -// which formats the errors to JSON. -type Plain struct { - Metadata lint.FormatterMetadata -} - -// Name returns the name of the formatter -func (f *Plain) Name() string { - return "plain" -} - -// Format formats the failures gotten from the lint. -func (f *Plain) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) { - for failure := range failures { - fmt.Printf("%v: %s %s\n", failure.Position.Start, failure.Failure, "https://revive.run/r#"+failure.RuleName) - } - return "", nil -} diff --git a/vendor/github.com/mgechev/revive/formatter/sarif.go b/vendor/github.com/mgechev/revive/formatter/sarif.go deleted file mode 100644 index 8968c3ffb..000000000 --- a/vendor/github.com/mgechev/revive/formatter/sarif.go +++ /dev/null @@ -1,107 +0,0 @@ -package formatter - -import ( - "bytes" - "fmt" - "strings" - - "github.com/chavacava/garif" - "github.com/mgechev/revive/lint" -) - -// Sarif is an implementation of the Formatter interface -// which formats revive failures into SARIF format. -type Sarif struct { - Metadata lint.FormatterMetadata -} - -// Name returns the name of the formatter -func (f *Sarif) Name() string { - return "sarif" -} - -const reviveSite = "https://revive.run" - -// Format formats the failures gotten from the lint. -func (f *Sarif) Format(failures <-chan lint.Failure, cfg lint.Config) (string, error) { - sarifLog := newReviveRunLog(cfg) - - for failure := range failures { - sarifLog.AddResult(failure) - } - - buf := new(bytes.Buffer) - sarifLog.PrettyWrite(buf) - - return buf.String(), nil -} - -type reviveRunLog struct { - *garif.LogFile - run *garif.Run - rules map[string]lint.RuleConfig -} - -func newReviveRunLog(cfg lint.Config) *reviveRunLog { - run := garif.NewRun(garif.NewTool(garif.NewDriver("revive").WithInformationUri(reviveSite))) - log := garif.NewLogFile([]*garif.Run{run}, garif.Version210) - - reviveLog := &reviveRunLog{ - log, - run, - cfg.Rules, - } - - reviveLog.addRules(cfg.Rules) - - return reviveLog -} - -func (l *reviveRunLog) addRules(cfg map[string]lint.RuleConfig) { - for name, ruleCfg := range cfg { - rule := garif.NewRule(name).WithHelpUri(reviveSite + "/r#" + name) - setRuleProperties(rule, ruleCfg) - driver := l.run.Tool.Driver - - if driver.Rules == nil { - driver.Rules = []*garif.ReportingDescriptor{rule} - return - } - - driver.Rules = append(driver.Rules, rule) - } -} - -func (l *reviveRunLog) AddResult(failure lint.Failure) { - positiveOrZero := func(x int) int { - if x > 0 { - return x - } - return 0 - } - position := failure.Position - filename := position.Start.Filename - line := positiveOrZero(position.Start.Line - 1) // https://docs.oasis-open.org/sarif/sarif/v2.1.0/csprd01/sarif-v2.1.0-csprd01.html#def_line - column := positiveOrZero(position.Start.Column - 1) // https://docs.oasis-open.org/sarif/sarif/v2.1.0/csprd01/sarif-v2.1.0-csprd01.html#def_column - - result := garif.NewResult(garif.NewMessageFromText(failure.Failure)) - location := garif.NewLocation().WithURI(filename).WithLineColumn(line, column) - result.Locations = append(result.Locations, location) - result.RuleId = failure.RuleName - result.Level = l.rules[failure.RuleName].Severity - - l.run.Results = append(l.run.Results, result) -} - -func setRuleProperties(sarifRule *garif.ReportingDescriptor, lintRule lint.RuleConfig) { - arguments := make([]string, len(lintRule.Arguments)) - for i, arg := range lintRule.Arguments { - arguments[i] = fmt.Sprintf("%+v", arg) - } - - if len(arguments) > 0 { - sarifRule.WithProperties("arguments", strings.Join(arguments, ",")) - } - - sarifRule.WithProperties("severity", string(lintRule.Severity)) -} diff --git a/vendor/github.com/mgechev/revive/formatter/severity.go b/vendor/github.com/mgechev/revive/formatter/severity.go deleted file mode 100644 index a43bf3192..000000000 --- a/vendor/github.com/mgechev/revive/formatter/severity.go +++ /dev/null @@ -1,13 +0,0 @@ -package formatter - -import "github.com/mgechev/revive/lint" - -func severity(config lint.Config, failure lint.Failure) lint.Severity { - if config, ok := config.Rules[failure.RuleName]; ok && config.Severity == lint.SeverityError { - return lint.SeverityError - } - if config, ok := config.Directives[failure.RuleName]; ok && config.Severity == lint.SeverityError { - return lint.SeverityError - } - return lint.SeverityWarning -} diff --git a/vendor/github.com/mgechev/revive/formatter/stylish.go b/vendor/github.com/mgechev/revive/formatter/stylish.go deleted file mode 100644 index cd81fdae7..000000000 --- a/vendor/github.com/mgechev/revive/formatter/stylish.go +++ /dev/null @@ -1,89 +0,0 @@ -package formatter - -import ( - "bytes" - "fmt" - - "github.com/fatih/color" - "github.com/mgechev/revive/lint" - "github.com/olekukonko/tablewriter" -) - -// Stylish is an implementation of the Formatter interface -// which formats the errors to JSON. -type Stylish struct { - Metadata lint.FormatterMetadata -} - -// Name returns the name of the formatter -func (f *Stylish) Name() string { - return "stylish" -} - -func formatFailure(failure lint.Failure, severity lint.Severity) []string { - fString := color.CyanString(failure.Failure) - fName := color.RedString("https://revive.run/r#" + failure.RuleName) - lineColumn := failure.Position - pos := fmt.Sprintf("(%d, %d)", lineColumn.Start.Line, lineColumn.Start.Column) - if severity == lint.SeverityWarning { - fName = color.YellowString("https://revive.run/r#" + failure.RuleName) - } - return []string{failure.GetFilename(), pos, fName, fString} -} - -// Format formats the failures gotten from the lint. -func (f *Stylish) Format(failures <-chan lint.Failure, config lint.Config) (string, error) { - var result [][]string - var totalErrors = 0 - var total = 0 - - for f := range failures { - total++ - currentType := severity(config, f) - if currentType == lint.SeverityError { - totalErrors++ - } - result = append(result, formatFailure(f, lint.Severity(currentType))) - } - ps := "problems" - if total == 1 { - ps = "problem" - } - - fileReport := make(map[string][][]string) - - for _, row := range result { - if _, ok := fileReport[row[0]]; !ok { - fileReport[row[0]] = [][]string{} - } - - fileReport[row[0]] = append(fileReport[row[0]], []string{row[1], row[2], row[3]}) - } - - output := "" - for filename, val := range fileReport { - buf := new(bytes.Buffer) - table := tablewriter.NewWriter(buf) - table.SetBorder(false) - table.SetColumnSeparator("") - table.SetRowSeparator("") - table.SetAutoWrapText(false) - table.AppendBulk(val) - table.Render() - c := color.New(color.Underline) - output += c.SprintfFunc()(filename + "\n") - output += buf.String() + "\n" - } - - suffix := fmt.Sprintf(" %d %s (%d errors) (%d warnings)", total, ps, totalErrors, total-totalErrors) - - if total > 0 && totalErrors > 0 { - suffix = color.RedString("\n ✖" + suffix) - } else if total > 0 && totalErrors == 0 { - suffix = color.YellowString("\n ✖" + suffix) - } else { - suffix, output = "", "" - } - - return output + suffix, nil -} diff --git a/vendor/github.com/mgechev/revive/formatter/unix.go b/vendor/github.com/mgechev/revive/formatter/unix.go deleted file mode 100644 index b9ae62d38..000000000 --- a/vendor/github.com/mgechev/revive/formatter/unix.go +++ /dev/null @@ -1,27 +0,0 @@ -package formatter - -import ( - "fmt" - - "github.com/mgechev/revive/lint" -) - -// Unix is an implementation of the Formatter interface -// which formats the errors to a simple line based error format -// main.go:24:9: [errorf] should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...) -type Unix struct { - Metadata lint.FormatterMetadata -} - -// Name returns the name of the formatter -func (f *Unix) Name() string { - return "unix" -} - -// Format formats the failures gotten from the lint. -func (f *Unix) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) { - for failure := range failures { - fmt.Printf("%v: [%s] %s\n", failure.Position.Start, failure.RuleName, failure.Failure) - } - return "", nil -} diff --git a/vendor/github.com/mgechev/revive/lint/config.go b/vendor/github.com/mgechev/revive/lint/config.go deleted file mode 100644 index e05460874..000000000 --- a/vendor/github.com/mgechev/revive/lint/config.go +++ /dev/null @@ -1,33 +0,0 @@ -package lint - -// Arguments is type used for the arguments of a rule. -type Arguments = []interface{} - -// RuleConfig is type used for the rule configuration. -type RuleConfig struct { - Arguments Arguments - Severity Severity -} - -// RulesConfig defines the config for all rules. -type RulesConfig = map[string]RuleConfig - -// DirectiveConfig is type used for the linter directive configuration. -type DirectiveConfig struct { - Severity Severity -} - -// DirectivesConfig defines the config for all directives. -type DirectivesConfig = map[string]DirectiveConfig - -// Config defines the config of the linter. -type Config struct { - IgnoreGeneratedHeader bool `toml:"ignoreGeneratedHeader"` - Confidence float64 - Severity Severity - Rules RulesConfig `toml:"rule"` - ErrorCode int `toml:"errorCode"` - WarningCode int `toml:"warningCode"` - Directives DirectivesConfig `toml:"directive"` - Exclude []string `toml:"exclude"` -} diff --git a/vendor/github.com/mgechev/revive/lint/failure.go b/vendor/github.com/mgechev/revive/lint/failure.go deleted file mode 100644 index 479b0cb48..000000000 --- a/vendor/github.com/mgechev/revive/lint/failure.go +++ /dev/null @@ -1,39 +0,0 @@ -package lint - -import ( - "go/ast" - "go/token" -) - -const ( - // SeverityWarning declares failures of type warning - SeverityWarning = "warning" - // SeverityError declares failures of type error. - SeverityError = "error" -) - -// Severity is the type for the failure types. -type Severity string - -// FailurePosition returns the failure position -type FailurePosition struct { - Start token.Position - End token.Position -} - -// Failure defines a struct for a linting failure. -type Failure struct { - Failure string - RuleName string - Category string - Position FailurePosition - Node ast.Node `json:"-"` - Confidence float64 - // For future use - ReplacementLine string -} - -// GetFilename returns the filename. -func (f *Failure) GetFilename() string { - return f.Position.Start.Filename -} diff --git a/vendor/github.com/mgechev/revive/lint/file.go b/vendor/github.com/mgechev/revive/lint/file.go deleted file mode 100644 index 8bef9c220..000000000 --- a/vendor/github.com/mgechev/revive/lint/file.go +++ /dev/null @@ -1,278 +0,0 @@ -package lint - -import ( - "bytes" - "go/ast" - "go/parser" - "go/printer" - "go/token" - "go/types" - "math" - "regexp" - "strings" -) - -// File abstraction used for representing files. -type File struct { - Name string - Pkg *Package - content []byte - AST *ast.File -} - -// IsTest returns if the file contains tests. -func (f *File) IsTest() bool { return strings.HasSuffix(f.Name, "_test.go") } - -// Content returns the file's content. -func (f *File) Content() []byte { - return f.content -} - -// NewFile creates a new file -func NewFile(name string, content []byte, pkg *Package) (*File, error) { - f, err := parser.ParseFile(pkg.fset, name, content, parser.ParseComments) - if err != nil { - return nil, err - } - return &File{ - Name: name, - content: content, - Pkg: pkg, - AST: f, - }, nil -} - -// ToPosition returns line and column for given position. -func (f *File) ToPosition(pos token.Pos) token.Position { - return f.Pkg.fset.Position(pos) -} - -// Render renters a node. -func (f *File) Render(x interface{}) string { - var buf bytes.Buffer - if err := printer.Fprint(&buf, f.Pkg.fset, x); err != nil { - panic(err) - } - return buf.String() -} - -// CommentMap builds a comment map for the file. -func (f *File) CommentMap() ast.CommentMap { - return ast.NewCommentMap(f.Pkg.fset, f.AST, f.AST.Comments) -} - -var basicTypeKinds = map[types.BasicKind]string{ - types.UntypedBool: "bool", - types.UntypedInt: "int", - types.UntypedRune: "rune", - types.UntypedFloat: "float64", - types.UntypedComplex: "complex128", - types.UntypedString: "string", -} - -// IsUntypedConst reports whether expr is an untyped constant, -// and indicates what its default type is. -// scope may be nil. -func (f *File) IsUntypedConst(expr ast.Expr) (defType string, ok bool) { - // Re-evaluate expr outside of its context to see if it's untyped. - // (An expr evaluated within, for example, an assignment context will get the type of the LHS.) - exprStr := f.Render(expr) - tv, err := types.Eval(f.Pkg.fset, f.Pkg.TypesPkg, expr.Pos(), exprStr) - if err != nil { - return "", false - } - if b, ok := tv.Type.(*types.Basic); ok { - if dt, ok := basicTypeKinds[b.Kind()]; ok { - return dt, true - } - } - - return "", false -} - -func (f *File) isMain() bool { - if f.AST.Name.Name == "main" { - return true - } - return false -} - -const directiveSpecifyDisableReason = "specify-disable-reason" - -func (f *File) lint(rules []Rule, config Config, failures chan Failure) { - rulesConfig := config.Rules - _, mustSpecifyDisableReason := config.Directives[directiveSpecifyDisableReason] - disabledIntervals := f.disabledIntervals(rules, mustSpecifyDisableReason, failures) - for _, currentRule := range rules { - ruleConfig := rulesConfig[currentRule.Name()] - currentFailures := currentRule.Apply(f, ruleConfig.Arguments) - for idx, failure := range currentFailures { - if failure.RuleName == "" { - failure.RuleName = currentRule.Name() - } - if failure.Node != nil { - failure.Position = ToFailurePosition(failure.Node.Pos(), failure.Node.End(), f) - } - currentFailures[idx] = failure - } - currentFailures = f.filterFailures(currentFailures, disabledIntervals) - for _, failure := range currentFailures { - if failure.Confidence >= config.Confidence { - failures <- failure - } - } - } -} - -type enableDisableConfig struct { - enabled bool - position int -} - -const directiveRE = `^//[\s]*revive:(enable|disable)(?:-(line|next-line))?(?::([^\s]+))?[\s]*(?: (.+))?$` -const directivePos = 1 -const modifierPos = 2 -const rulesPos = 3 -const reasonPos = 4 - -var re = regexp.MustCompile(directiveRE) - -func (f *File) disabledIntervals(rules []Rule, mustSpecifyDisableReason bool, failures chan Failure) disabledIntervalsMap { - enabledDisabledRulesMap := make(map[string][]enableDisableConfig) - - getEnabledDisabledIntervals := func() disabledIntervalsMap { - result := make(disabledIntervalsMap) - - for ruleName, disabledArr := range enabledDisabledRulesMap { - ruleResult := []DisabledInterval{} - for i := 0; i < len(disabledArr); i++ { - interval := DisabledInterval{ - RuleName: ruleName, - From: token.Position{ - Filename: f.Name, - Line: disabledArr[i].position, - }, - To: token.Position{ - Filename: f.Name, - Line: math.MaxInt32, - }, - } - if i%2 == 0 { - ruleResult = append(ruleResult, interval) - } else { - ruleResult[len(ruleResult)-1].To.Line = disabledArr[i].position - } - } - result[ruleName] = ruleResult - } - - return result - } - - handleConfig := func(isEnabled bool, line int, name string) { - existing, ok := enabledDisabledRulesMap[name] - if !ok { - existing = []enableDisableConfig{} - enabledDisabledRulesMap[name] = existing - } - if (len(existing) > 1 && existing[len(existing)-1].enabled == isEnabled) || - (len(existing) == 0 && isEnabled) { - return - } - existing = append(existing, enableDisableConfig{ - enabled: isEnabled, - position: line, - }) - enabledDisabledRulesMap[name] = existing - } - - handleRules := func(filename, modifier string, isEnabled bool, line int, ruleNames []string) []DisabledInterval { - var result []DisabledInterval - for _, name := range ruleNames { - if modifier == "line" { - handleConfig(isEnabled, line, name) - handleConfig(!isEnabled, line, name) - } else if modifier == "next-line" { - handleConfig(isEnabled, line+1, name) - handleConfig(!isEnabled, line+1, name) - } else { - handleConfig(isEnabled, line, name) - } - } - return result - } - - handleComment := func(filename string, c *ast.CommentGroup, line int) { - comments := c.List - for _, c := range comments { - match := re.FindStringSubmatch(c.Text) - if len(match) == 0 { - return - } - - ruleNames := []string{} - tempNames := strings.Split(match[rulesPos], ",") - for _, name := range tempNames { - name = strings.Trim(name, "\n") - if len(name) > 0 { - ruleNames = append(ruleNames, name) - } - } - - mustCheckDisablingReason := mustSpecifyDisableReason && match[directivePos] == "disable" - if mustCheckDisablingReason && strings.Trim(match[reasonPos], " ") == "" { - failures <- Failure{ - Confidence: 1, - RuleName: directiveSpecifyDisableReason, - Failure: "reason of lint disabling not found", - Position: ToFailurePosition(c.Pos(), c.End(), f), - Node: c, - } - continue // skip this linter disabling directive - } - - // TODO: optimize - if len(ruleNames) == 0 { - for _, rule := range rules { - ruleNames = append(ruleNames, rule.Name()) - } - } - - handleRules(filename, match[modifierPos], match[directivePos] == "enable", line, ruleNames) - } - } - - comments := f.AST.Comments - for _, c := range comments { - handleComment(f.Name, c, f.ToPosition(c.End()).Line) - } - - return getEnabledDisabledIntervals() -} - -func (f *File) filterFailures(failures []Failure, disabledIntervals disabledIntervalsMap) []Failure { - result := []Failure{} - for _, failure := range failures { - fStart := failure.Position.Start.Line - fEnd := failure.Position.End.Line - intervals, ok := disabledIntervals[failure.RuleName] - if !ok { - result = append(result, failure) - } else { - include := true - for _, interval := range intervals { - intStart := interval.From.Line - intEnd := interval.To.Line - if (fStart >= intStart && fStart <= intEnd) || - (fEnd >= intStart && fEnd <= intEnd) { - include = false - break - } - } - if include { - result = append(result, failure) - } - } - } - return result -} diff --git a/vendor/github.com/mgechev/revive/lint/formatter.go b/vendor/github.com/mgechev/revive/lint/formatter.go deleted file mode 100644 index 7c19af278..000000000 --- a/vendor/github.com/mgechev/revive/lint/formatter.go +++ /dev/null @@ -1,14 +0,0 @@ -package lint - -// FormatterMetadata configuration of a formatter -type FormatterMetadata struct { - Name string - Description string - Sample string -} - -// Formatter defines an interface for failure formatters -type Formatter interface { - Format(<-chan Failure, Config) (string, error) - Name() string -} diff --git a/vendor/github.com/mgechev/revive/lint/linter.go b/vendor/github.com/mgechev/revive/lint/linter.go deleted file mode 100644 index cdca84fb5..000000000 --- a/vendor/github.com/mgechev/revive/lint/linter.go +++ /dev/null @@ -1,99 +0,0 @@ -package lint - -import ( - "bufio" - "bytes" - "fmt" - "go/token" - "os" - "sync" -) - -// ReadFile defines an abstraction for reading files. -type ReadFile func(path string) (result []byte, err error) - -type disabledIntervalsMap = map[string][]DisabledInterval - -// Linter is used for linting set of files. -type Linter struct { - reader ReadFile -} - -// New creates a new Linter -func New(reader ReadFile) Linter { - return Linter{reader: reader} -} - -var ( - genHdr = []byte("// Code generated ") - genFtr = []byte(" DO NOT EDIT.") -) - -// Lint lints a set of files with the specified rule. -func (l *Linter) Lint(packages [][]string, ruleSet []Rule, config Config) (<-chan Failure, error) { - failures := make(chan Failure) - - var wg sync.WaitGroup - for _, pkg := range packages { - wg.Add(1) - go func(pkg []string) { - if err := l.lintPackage(pkg, ruleSet, config, failures); err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - defer wg.Done() - }(pkg) - } - - go func() { - wg.Wait() - close(failures) - }() - - return failures, nil -} - -func (l *Linter) lintPackage(filenames []string, ruleSet []Rule, config Config, failures chan Failure) error { - pkg := &Package{ - fset: token.NewFileSet(), - files: map[string]*File{}, - mu: sync.Mutex{}, - } - for _, filename := range filenames { - content, err := l.reader(filename) - if err != nil { - return err - } - if isGenerated(content) && !config.IgnoreGeneratedHeader { - continue - } - - file, err := NewFile(filename, content, pkg) - if err != nil { - return err - } - pkg.files[filename] = file - } - - if len(pkg.files) == 0 { - return nil - } - - pkg.lint(ruleSet, config, failures) - - return nil -} - -// isGenerated reports whether the source file is generated code -// according the rules from https://golang.org/s/generatedcode. -// This is inherited from the original go lint. -func isGenerated(src []byte) bool { - sc := bufio.NewScanner(bytes.NewReader(src)) - for sc.Scan() { - b := sc.Bytes() - if bytes.HasPrefix(b, genHdr) && bytes.HasSuffix(b, genFtr) && len(b) >= len(genHdr)+len(genFtr) { - return true - } - } - return false -} diff --git a/vendor/github.com/mgechev/revive/lint/package.go b/vendor/github.com/mgechev/revive/lint/package.go deleted file mode 100644 index 7b6046fd7..000000000 --- a/vendor/github.com/mgechev/revive/lint/package.go +++ /dev/null @@ -1,178 +0,0 @@ -package lint - -import ( - "go/ast" - "go/token" - "go/types" - "sync" - - "golang.org/x/tools/go/gcexportdata" -) - -// Package represents a package in the project. -type Package struct { - fset *token.FileSet - files map[string]*File - - TypesPkg *types.Package - TypesInfo *types.Info - - // sortable is the set of types in the package that implement sort.Interface. - Sortable map[string]bool - // main is whether this is a "main" package. - main int - mu sync.Mutex -} - -var newImporter = func(fset *token.FileSet) types.ImporterFrom { - return gcexportdata.NewImporter(fset, make(map[string]*types.Package)) -} - -var ( - trueValue = 1 - falseValue = 2 - notSet = 3 -) - -// IsMain returns if that's the main package. -func (p *Package) IsMain() bool { - if p.main == trueValue { - return true - } else if p.main == falseValue { - return false - } - for _, f := range p.files { - if f.isMain() { - p.main = trueValue - return true - } - } - p.main = falseValue - return false -} - -// TypeCheck performs type checking for given package. -func (p *Package) TypeCheck() error { - p.mu.Lock() - // If type checking has already been performed - // skip it. - if p.TypesInfo != nil || p.TypesPkg != nil { - p.mu.Unlock() - return nil - } - config := &types.Config{ - // By setting a no-op error reporter, the type checker does as much work as possible. - Error: func(error) {}, - Importer: newImporter(p.fset), - } - info := &types.Info{ - Types: make(map[ast.Expr]types.TypeAndValue), - Defs: make(map[*ast.Ident]types.Object), - Uses: make(map[*ast.Ident]types.Object), - Scopes: make(map[ast.Node]*types.Scope), - } - var anyFile *File - var astFiles []*ast.File - for _, f := range p.files { - anyFile = f - astFiles = append(astFiles, f.AST) - } - - typesPkg, err := check(config, anyFile.AST.Name.Name, p.fset, astFiles, info) - - // Remember the typechecking info, even if config.Check failed, - // since we will get partial information. - p.TypesPkg = typesPkg - p.TypesInfo = info - p.mu.Unlock() - return err -} - -// check function encapsulates the call to go/types.Config.Check method and -// recovers if the called method panics (see issue #59) -func check(config *types.Config, n string, fset *token.FileSet, astFiles []*ast.File, info *types.Info) (p *types.Package, err error) { - defer func() { - if r := recover(); r != nil { - err, _ = r.(error) - p = nil - return - } - }() - - return config.Check(n, fset, astFiles, info) -} - -// TypeOf returns the type of an expression. -func (p *Package) TypeOf(expr ast.Expr) types.Type { - if p.TypesInfo == nil { - return nil - } - return p.TypesInfo.TypeOf(expr) -} - -type walker struct { - nmap map[string]int - has map[string]int -} - -func (w *walker) Visit(n ast.Node) ast.Visitor { - fn, ok := n.(*ast.FuncDecl) - if !ok || fn.Recv == nil || len(fn.Recv.List) == 0 { - return w - } - // TODO(dsymonds): We could check the signature to be more precise. - recv := receiverType(fn) - if i, ok := w.nmap[fn.Name.Name]; ok { - w.has[recv] |= i - } - return w -} - -func (p *Package) scanSortable() { - p.Sortable = make(map[string]bool) - - // bitfield for which methods exist on each type. - const ( - Len = 1 << iota - Less - Swap - ) - nmap := map[string]int{"Len": Len, "Less": Less, "Swap": Swap} - has := make(map[string]int) - for _, f := range p.files { - ast.Walk(&walker{nmap, has}, f.AST) - } - for typ, ms := range has { - if ms == Len|Less|Swap { - p.Sortable[typ] = true - } - } -} - -// receiverType returns the named type of the method receiver, sans "*", -// or "invalid-type" if fn.Recv is ill formed. -func receiverType(fn *ast.FuncDecl) string { - switch e := fn.Recv.List[0].Type.(type) { - case *ast.Ident: - return e.Name - case *ast.StarExpr: - if id, ok := e.X.(*ast.Ident); ok { - return id.Name - } - } - // The parser accepts much more than just the legal forms. - return "invalid-type" -} - -func (p *Package) lint(rules []Rule, config Config, failures chan Failure) { - p.scanSortable() - var wg sync.WaitGroup - for _, file := range p.files { - wg.Add(1) - go (func(file *File) { - file.lint(rules, config, failures) - defer wg.Done() - })(file) - } - wg.Wait() -} diff --git a/vendor/github.com/mgechev/revive/lint/rule.go b/vendor/github.com/mgechev/revive/lint/rule.go deleted file mode 100644 index 815abfdd8..000000000 --- a/vendor/github.com/mgechev/revive/lint/rule.go +++ /dev/null @@ -1,31 +0,0 @@ -package lint - -import ( - "go/token" -) - -// DisabledInterval contains a single disabled interval and the associated rule name. -type DisabledInterval struct { - From token.Position - To token.Position - RuleName string -} - -// Rule defines an abstract rule interaface -type Rule interface { - Name() string - Apply(*File, Arguments) []Failure -} - -// AbstractRule defines an abstract rule. -type AbstractRule struct { - Failures []Failure -} - -// ToFailurePosition returns the failure position. -func ToFailurePosition(start token.Pos, end token.Pos, file *File) FailurePosition { - return FailurePosition{ - Start: file.ToPosition(start), - End: file.ToPosition(end), - } -} diff --git a/vendor/github.com/mgechev/revive/lint/utils.go b/vendor/github.com/mgechev/revive/lint/utils.go deleted file mode 100644 index 28657c6df..000000000 --- a/vendor/github.com/mgechev/revive/lint/utils.go +++ /dev/null @@ -1,128 +0,0 @@ -package lint - -import ( - "strings" - "unicode" -) - -// Name returns a different name if it should be different. -func Name(name string, whitelist, blacklist []string) (should string) { - // Fast path for simple cases: "_" and all lowercase. - if name == "_" { - return name - } - allLower := true - for _, r := range name { - if !unicode.IsLower(r) { - allLower = false - break - } - } - if allLower { - return name - } - - // Split camelCase at any lower->upper transition, and split on underscores. - // Check each word for common initialisms. - runes := []rune(name) - w, i := 0, 0 // index of start of word, scan - for i+1 <= len(runes) { - eow := false // whether we hit the end of a word - if i+1 == len(runes) { - eow = true - } else if runes[i+1] == '_' { - // underscore; shift the remainder forward over any run of underscores - eow = true - n := 1 - for i+n+1 < len(runes) && runes[i+n+1] == '_' { - n++ - } - - // Leave at most one underscore if the underscore is between two digits - if i+n+1 < len(runes) && unicode.IsDigit(runes[i]) && unicode.IsDigit(runes[i+n+1]) { - n-- - } - - copy(runes[i+1:], runes[i+n+1:]) - runes = runes[:len(runes)-n] - } else if unicode.IsLower(runes[i]) && !unicode.IsLower(runes[i+1]) { - // lower->non-lower - eow = true - } - i++ - if !eow { - continue - } - - // [w,i) is a word. - word := string(runes[w:i]) - ignoreInitWarnings := map[string]bool{} - for _, i := range whitelist { - ignoreInitWarnings[i] = true - } - - extraInits := map[string]bool{} - for _, i := range blacklist { - extraInits[i] = true - } - - if u := strings.ToUpper(word); (commonInitialisms[u] || extraInits[u]) && !ignoreInitWarnings[u] { - // Keep consistent case, which is lowercase only at the start. - if w == 0 && unicode.IsLower(runes[w]) { - u = strings.ToLower(u) - } - // All the common initialisms are ASCII, - // so we can replace the bytes exactly. - copy(runes[w:], []rune(u)) - } else if w > 0 && strings.ToLower(word) == word { - // already all lowercase, and not the first word, so uppercase the first character. - runes[w] = unicode.ToUpper(runes[w]) - } - w = i - } - return string(runes) -} - -// commonInitialisms is a set of common initialisms. -// Only add entries that are highly unlikely to be non-initialisms. -// For instance, "ID" is fine (Freudian code is rare), but "AND" is not. -var commonInitialisms = map[string]bool{ - "ACL": true, - "API": true, - "ASCII": true, - "CPU": true, - "CSS": true, - "DNS": true, - "EOF": true, - "GUID": true, - "HTML": true, - "HTTP": true, - "HTTPS": true, - "ID": true, - "IP": true, - "JSON": true, - "LHS": true, - "QPS": true, - "RAM": true, - "RHS": true, - "RPC": true, - "SLA": true, - "SMTP": true, - "SQL": true, - "SSH": true, - "TCP": true, - "TLS": true, - "TTL": true, - "UDP": true, - "UI": true, - "UID": true, - "UUID": true, - "URI": true, - "URL": true, - "UTF8": true, - "VM": true, - "XML": true, - "XMPP": true, - "XSRF": true, - "XSS": true, -} diff --git a/vendor/github.com/mgechev/revive/rule/add-constant.go b/vendor/github.com/mgechev/revive/rule/add-constant.go deleted file mode 100644 index 881bbd073..000000000 --- a/vendor/github.com/mgechev/revive/rule/add-constant.go +++ /dev/null @@ -1,151 +0,0 @@ -package rule - -import ( - "fmt" - "github.com/mgechev/revive/lint" - "go/ast" - "strconv" - "strings" -) - -const ( - defaultStrLitLimit = 2 - kindFLOAT = "FLOAT" - kindINT = "INT" - kindSTRING = "STRING" -) - -type whiteList map[string]map[string]bool - -func newWhiteList() whiteList { - return map[string]map[string]bool{kindINT: map[string]bool{}, kindFLOAT: map[string]bool{}, kindSTRING: map[string]bool{}} -} - -func (wl whiteList) add(kind string, list string) { - elems := strings.Split(list, ",") - for _, e := range elems { - wl[kind][e] = true - } -} - -// AddConstantRule lints unused params in functions. -type AddConstantRule struct{} - -// Apply applies the rule to given file. -func (r *AddConstantRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { - strLitLimit := defaultStrLitLimit - var whiteList = newWhiteList() - if len(arguments) > 0 { - args, ok := arguments[0].(map[string]interface{}) - if !ok { - panic(fmt.Sprintf("Invalid argument to the add-constant rule. Expecting a k,v map, got %T", arguments[0])) - } - for k, v := range args { - kind := "" - switch k { - case "allowFloats": - kind = kindFLOAT - fallthrough - case "allowInts": - if kind == "" { - kind = kindINT - } - fallthrough - case "allowStrs": - if kind == "" { - kind = kindSTRING - } - list, ok := v.(string) - if !ok { - panic(fmt.Sprintf("Invalid argument to the add-constant rule, string expected. Got '%v' (%T)", v, v)) - } - whiteList.add(kind, list) - case "maxLitCount": - sl, ok := v.(string) - if !ok { - panic(fmt.Sprintf("Invalid argument to the add-constant rule, expecting string representation of an integer. Got '%v' (%T)", v, v)) - } - - limit, err := strconv.Atoi(sl) - if err != nil { - panic(fmt.Sprintf("Invalid argument to the add-constant rule, expecting string representation of an integer. Got '%v'", v)) - } - strLitLimit = limit - } - } - } - - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - w := lintAddConstantRule{onFailure: onFailure, strLits: make(map[string]int, 0), strLitLimit: strLitLimit, whiteLst: whiteList} - - ast.Walk(w, file.AST) - - return failures -} - -// Name returns the rule name. -func (r *AddConstantRule) Name() string { - return "add-constant" -} - -type lintAddConstantRule struct { - onFailure func(lint.Failure) - strLits map[string]int - strLitLimit int - whiteLst whiteList -} - -func (w lintAddConstantRule) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.GenDecl: - return nil // skip declarations - case *ast.BasicLit: - switch kind := n.Kind.String(); kind { - case kindFLOAT, kindINT: - w.checkNumLit(kind, n) - case kindSTRING: - w.checkStrLit(n) - } - } - - return w - -} - -func (w lintAddConstantRule) checkStrLit(n *ast.BasicLit) { - if w.whiteLst[kindSTRING][n.Value] { - return - } - - count := w.strLits[n.Value] - if count >= 0 { - w.strLits[n.Value] = count + 1 - if w.strLits[n.Value] > w.strLitLimit { - w.onFailure(lint.Failure{ - Confidence: 1, - Node: n, - Category: "style", - Failure: fmt.Sprintf("string literal %s appears, at least, %d times, create a named constant for it", n.Value, w.strLits[n.Value]), - }) - w.strLits[n.Value] = -1 // mark it to avoid failing again on the same literal - } - } -} - -func (w lintAddConstantRule) checkNumLit(kind string, n *ast.BasicLit) { - if w.whiteLst[kind][n.Value] { - return - } - - w.onFailure(lint.Failure{ - Confidence: 1, - Node: n, - Category: "style", - Failure: fmt.Sprintf("avoid magic numbers like '%s', create a named constant for it", n.Value), - }) -} diff --git a/vendor/github.com/mgechev/revive/rule/argument-limit.go b/vendor/github.com/mgechev/revive/rule/argument-limit.go deleted file mode 100644 index 2b11d4982..000000000 --- a/vendor/github.com/mgechev/revive/rule/argument-limit.go +++ /dev/null @@ -1,67 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// ArgumentsLimitRule lints given else constructs. -type ArgumentsLimitRule struct{} - -// Apply applies the rule to given file. -func (r *ArgumentsLimitRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { - if len(arguments) != 1 { - panic(`invalid configuration for "argument-limit"`) - } - - total, ok := arguments[0].(int64) // Alt. non panicking version - if !ok { - panic(`invalid value passed as argument number to the "argument-list" rule`) - } - - var failures []lint.Failure - - walker := lintArgsNum{ - total: int(total), - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - ast.Walk(walker, file.AST) - - return failures -} - -// Name returns the rule name. -func (r *ArgumentsLimitRule) Name() string { - return "argument-limit" -} - -type lintArgsNum struct { - total int - onFailure func(lint.Failure) -} - -func (w lintArgsNum) Visit(n ast.Node) ast.Visitor { - node, ok := n.(*ast.FuncDecl) - if ok { - num := 0 - for _, l := range node.Type.Params.List { - for range l.Names { - num++ - } - } - if num > w.total { - w.onFailure(lint.Failure{ - Confidence: 1, - Failure: fmt.Sprintf("maximum number of arguments per function exceeded; max %d but got %d", w.total, num), - Node: node.Type, - }) - return w - } - } - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/atomic.go b/vendor/github.com/mgechev/revive/rule/atomic.go deleted file mode 100644 index 572e141da..000000000 --- a/vendor/github.com/mgechev/revive/rule/atomic.go +++ /dev/null @@ -1,94 +0,0 @@ -package rule - -import ( - "go/ast" - "go/token" - "go/types" - - "github.com/mgechev/revive/lint" -) - -// AtomicRule lints given else constructs. -type AtomicRule struct{} - -// Apply applies the rule to given file. -func (r *AtomicRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - walker := atomic{ - pkgTypesInfo: file.Pkg.TypesInfo, - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - ast.Walk(walker, file.AST) - - return failures -} - -// Name returns the rule name. -func (r *AtomicRule) Name() string { - return "atomic" -} - -type atomic struct { - pkgTypesInfo *types.Info - onFailure func(lint.Failure) -} - -func (w atomic) Visit(node ast.Node) ast.Visitor { - n, ok := node.(*ast.AssignStmt) - if !ok { - return w - } - - if len(n.Lhs) != len(n.Rhs) { - return nil // skip assignment sub-tree - } - if len(n.Lhs) == 1 && n.Tok == token.DEFINE { - return nil // skip assignment sub-tree - } - - for i, right := range n.Rhs { - call, ok := right.(*ast.CallExpr) - if !ok { - continue - } - sel, ok := call.Fun.(*ast.SelectorExpr) - if !ok { - continue - } - pkgIdent, _ := sel.X.(*ast.Ident) - if w.pkgTypesInfo != nil { - pkgName, ok := w.pkgTypesInfo.Uses[pkgIdent].(*types.PkgName) - if !ok || pkgName.Imported().Path() != "sync/atomic" { - continue - } - } - - switch sel.Sel.Name { - case "AddInt32", "AddInt64", "AddUint32", "AddUint64", "AddUintptr": - left := n.Lhs[i] - if len(call.Args) != 2 { - continue - } - arg := call.Args[0] - broken := false - - if uarg, ok := arg.(*ast.UnaryExpr); ok && uarg.Op == token.AND { - broken = gofmt(left) == gofmt(uarg.X) - } else if star, ok := left.(*ast.StarExpr); ok { - broken = gofmt(star.X) == gofmt(arg) - } - - if broken { - w.onFailure(lint.Failure{ - Confidence: 1, - Failure: "direct assignment to atomic value", - Node: n, - }) - } - } - } - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/bare-return.go b/vendor/github.com/mgechev/revive/rule/bare-return.go deleted file mode 100644 index 3ee4c4adc..000000000 --- a/vendor/github.com/mgechev/revive/rule/bare-return.go +++ /dev/null @@ -1,84 +0,0 @@ -package rule - -import ( - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// BareReturnRule lints given else constructs. -type BareReturnRule struct{} - -// Apply applies the rule to given file. -func (r *BareReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - w := lintBareReturnRule{onFailure: onFailure} - ast.Walk(w, file.AST) - return failures -} - -// Name returns the rule name. -func (r *BareReturnRule) Name() string { - return "bare-return" -} - -type lintBareReturnRule struct { - onFailure func(lint.Failure) -} - -func (w lintBareReturnRule) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.FuncDecl: - w.checkFunc(n.Type.Results, n.Body) - case *ast.FuncLit: // to cope with deferred functions and go-routines - w.checkFunc(n.Type.Results, n.Body) - } - - return w -} - -// checkFunc will verify if the given function has named result and bare returns -func (w lintBareReturnRule) checkFunc(results *ast.FieldList, body *ast.BlockStmt) { - hasNamedResults := results != nil && len(results.List) > 0 && results.List[0].Names != nil - if !hasNamedResults || body == nil { - return // nothing to do - } - - brf := bareReturnFinder{w.onFailure} - ast.Walk(brf, body) -} - -type bareReturnFinder struct { - onFailure func(lint.Failure) -} - -func (w bareReturnFinder) Visit(node ast.Node) ast.Visitor { - _, ok := node.(*ast.FuncLit) - if ok { - // skip analysing function literals - // they will analyzed by the lintBareReturnRule.Visit method - return nil - } - - rs, ok := node.(*ast.ReturnStmt) - if !ok { - return w - } - - if len(rs.Results) > 0 { - return w - } - - w.onFailure(lint.Failure{ - Confidence: 1, - Node: rs, - Failure: "avoid using bare returns, please add return expressions", - }) - - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/blank-imports.go b/vendor/github.com/mgechev/revive/rule/blank-imports.go deleted file mode 100644 index 9e8b8fc00..000000000 --- a/vendor/github.com/mgechev/revive/rule/blank-imports.go +++ /dev/null @@ -1,75 +0,0 @@ -package rule - -import ( - "go/ast" - "strings" - - "github.com/mgechev/revive/lint" -) - -// BlankImportsRule lints given else constructs. -type BlankImportsRule struct{} - -// Name returns the rule name. -func (r *BlankImportsRule) Name() string { - return "blank-imports" -} - -// Apply applies the rule to given file. -func (r *BlankImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - if file.Pkg.IsMain() || file.IsTest() { - return nil - } - - const ( - message = "a blank import should be only in a main or test package, or have a comment justifying it" - category = "imports" - - embedImportPath = `"embed"` - ) - - var failures []lint.Failure - - // The first element of each contiguous group of blank imports should have - // an explanatory comment of some kind. - for i, imp := range file.AST.Imports { - pos := file.ToPosition(imp.Pos()) - - if !isBlank(imp.Name) { - continue // Ignore non-blank imports. - } - - if i > 0 { - prev := file.AST.Imports[i-1] - prevPos := file.ToPosition(prev.Pos()) - - isSubsequentBlancInAGroup := isBlank(prev.Name) && prevPos.Line+1 == pos.Line && prev.Path.Value != embedImportPath - if isSubsequentBlancInAGroup { - continue - } - } - - if imp.Path.Value == embedImportPath && r.fileHasValidEmbedComment(file.AST) { - continue - } - - // This is the first blank import of a group. - if imp.Doc == nil && imp.Comment == nil { - failures = append(failures, lint.Failure{Failure: message, Category: category, Node: imp, Confidence: 1}) - } - } - - return failures -} - -func (r *BlankImportsRule) fileHasValidEmbedComment(fileAst *ast.File) bool { - for _, commentGroup := range fileAst.Comments { - for _, comment := range commentGroup.List { - if strings.HasPrefix(comment.Text, "//go:embed ") { - return true - } - } - } - - return false -} diff --git a/vendor/github.com/mgechev/revive/rule/bool-literal-in-expr.go b/vendor/github.com/mgechev/revive/rule/bool-literal-in-expr.go deleted file mode 100644 index 0a4e696c6..000000000 --- a/vendor/github.com/mgechev/revive/rule/bool-literal-in-expr.go +++ /dev/null @@ -1,73 +0,0 @@ -package rule - -import ( - "go/ast" - "go/token" - - "github.com/mgechev/revive/lint" -) - -// BoolLiteralRule warns when logic expressions contains Boolean literals. -type BoolLiteralRule struct{} - -// Apply applies the rule to given file. -func (r *BoolLiteralRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - astFile := file.AST - w := &lintBoolLiteral{astFile, onFailure} - ast.Walk(w, astFile) - - return failures -} - -// Name returns the rule name. -func (r *BoolLiteralRule) Name() string { - return "bool-literal-in-expr" -} - -type lintBoolLiteral struct { - file *ast.File - onFailure func(lint.Failure) -} - -func (w *lintBoolLiteral) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.BinaryExpr: - if !isBoolOp(n.Op) { - return w - } - - lexeme, ok := isExprABooleanLit(n.X) - if !ok { - lexeme, ok = isExprABooleanLit(n.Y) - - if !ok { - return w - } - } - - isConstant := (n.Op == token.LAND && lexeme == "false") || (n.Op == token.LOR && lexeme == "true") - - if isConstant { - w.addFailure(n, "Boolean expression seems to always evaluate to "+lexeme, "logic") - } else { - w.addFailure(n, "omit Boolean literal in expression", "style") - } - } - - return w -} - -func (w lintBoolLiteral) addFailure(node ast.Node, msg string, cat string) { - w.onFailure(lint.Failure{ - Confidence: 1, - Node: node, - Category: cat, - Failure: msg, - }) -} diff --git a/vendor/github.com/mgechev/revive/rule/call-to-gc.go b/vendor/github.com/mgechev/revive/rule/call-to-gc.go deleted file mode 100644 index 06126611b..000000000 --- a/vendor/github.com/mgechev/revive/rule/call-to-gc.go +++ /dev/null @@ -1,70 +0,0 @@ -package rule - -import ( - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// CallToGCRule lints calls to the garbage collector. -type CallToGCRule struct{} - -// Apply applies the rule to given file. -func (r *CallToGCRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - var gcTriggeringFunctions = map[string]map[string]bool{ - "runtime": map[string]bool{"GC": true}, - } - - w := lintCallToGC{onFailure, gcTriggeringFunctions} - ast.Walk(w, file.AST) - - return failures -} - -// Name returns the rule name. -func (r *CallToGCRule) Name() string { - return "call-to-gc" -} - -type lintCallToGC struct { - onFailure func(lint.Failure) - gcTriggeringFunctions map[string]map[string]bool -} - -func (w lintCallToGC) Visit(node ast.Node) ast.Visitor { - ce, ok := node.(*ast.CallExpr) - if !ok { - return w // nothing to do, the node is not a call - } - - fc, ok := ce.Fun.(*ast.SelectorExpr) - if !ok { - return nil // nothing to do, the call is not of the form pkg.func(...) - } - - id, ok := fc.X.(*ast.Ident) - - if !ok { - return nil // in case X is not an id (it should be!) - } - - fn := fc.Sel.Name - pkg := id.Name - if !w.gcTriggeringFunctions[pkg][fn] { - return nil // it isn't a call to a GC triggering function - } - - w.onFailure(lint.Failure{ - Confidence: 1, - Node: node, - Category: "bad practice", - Failure: "explicit call to the garbage collector", - }) - - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/cognitive-complexity.go b/vendor/github.com/mgechev/revive/rule/cognitive-complexity.go deleted file mode 100644 index ccd36bd09..000000000 --- a/vendor/github.com/mgechev/revive/rule/cognitive-complexity.go +++ /dev/null @@ -1,195 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "go/token" - - "github.com/mgechev/revive/lint" - "golang.org/x/tools/go/ast/astutil" -) - -// CognitiveComplexityRule lints given else constructs. -type CognitiveComplexityRule struct{} - -// Apply applies the rule to given file. -func (r *CognitiveComplexityRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { - var failures []lint.Failure - - const expectedArgumentsCount = 1 - if len(arguments) < expectedArgumentsCount { - panic(fmt.Sprintf("not enough arguments for cognitive-complexity, expected %d, got %d", expectedArgumentsCount, len(arguments))) - } - complexity, ok := arguments[0].(int64) - if !ok { - panic(fmt.Sprintf("invalid argument type for cognitive-complexity, expected int64, got %T", arguments[0])) - } - - linter := cognitiveComplexityLinter{ - file: file, - maxComplexity: int(complexity), - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - linter.lint() - - return failures -} - -// Name returns the rule name. -func (r *CognitiveComplexityRule) Name() string { - return "cognitive-complexity" -} - -type cognitiveComplexityLinter struct { - file *lint.File - maxComplexity int - onFailure func(lint.Failure) -} - -func (w cognitiveComplexityLinter) lint() { - f := w.file - for _, decl := range f.AST.Decls { - if fn, ok := decl.(*ast.FuncDecl); ok && fn.Body != nil { - v := cognitiveComplexityVisitor{} - c := v.subTreeComplexity(fn.Body) - if c > w.maxComplexity { - w.onFailure(lint.Failure{ - Confidence: 1, - Category: "maintenance", - Failure: fmt.Sprintf("function %s has cognitive complexity %d (> max enabled %d)", funcName(fn), c, w.maxComplexity), - Node: fn, - }) - } - } - } -} - -type cognitiveComplexityVisitor struct { - complexity int - nestingLevel int -} - -// subTreeComplexity calculates the cognitive complexity of an AST-subtree. -func (v cognitiveComplexityVisitor) subTreeComplexity(n ast.Node) int { - ast.Walk(&v, n) - return v.complexity -} - -// Visit implements the ast.Visitor interface. -func (v *cognitiveComplexityVisitor) Visit(n ast.Node) ast.Visitor { - switch n := n.(type) { - case *ast.IfStmt: - targets := []ast.Node{n.Cond, n.Body, n.Else} - v.walk(1, targets...) - return nil - case *ast.ForStmt: - targets := []ast.Node{n.Cond, n.Body} - v.walk(1, targets...) - return nil - case *ast.RangeStmt: - v.walk(1, n.Body) - return nil - case *ast.SelectStmt: - v.walk(1, n.Body) - return nil - case *ast.SwitchStmt: - v.walk(1, n.Body) - return nil - case *ast.TypeSwitchStmt: - v.walk(1, n.Body) - return nil - case *ast.FuncLit: - v.walk(0, n.Body) // do not increment the complexity, just do the nesting - return nil - case *ast.BinaryExpr: - v.complexity += v.binExpComplexity(n) - return nil // skip visiting binexp sub-tree (already visited by binExpComplexity) - case *ast.BranchStmt: - if n.Label != nil { - v.complexity++ - } - } - // TODO handle (at least) direct recursion - - return v -} - -func (v *cognitiveComplexityVisitor) walk(complexityIncrement int, targets ...ast.Node) { - v.complexity += complexityIncrement + v.nestingLevel - nesting := v.nestingLevel - v.nestingLevel++ - - for _, t := range targets { - if t == nil { - continue - } - - ast.Walk(v, t) - } - - v.nestingLevel = nesting -} - -func (cognitiveComplexityVisitor) binExpComplexity(n *ast.BinaryExpr) int { - calculator := binExprComplexityCalculator{opsStack: []token.Token{}} - - astutil.Apply(n, calculator.pre, calculator.post) - - return calculator.complexity -} - -type binExprComplexityCalculator struct { - complexity int - opsStack []token.Token // stack of bool operators - subexpStarted bool -} - -func (becc *binExprComplexityCalculator) pre(c *astutil.Cursor) bool { - switch n := c.Node().(type) { - case *ast.BinaryExpr: - isBoolOp := n.Op == token.LAND || n.Op == token.LOR - if !isBoolOp { - break - } - - ops := len(becc.opsStack) - // if - // is the first boolop in the expression OR - // is the first boolop inside a subexpression (...) OR - // is not the same to the previous one - // then - // increment complexity - if ops == 0 || becc.subexpStarted || n.Op != becc.opsStack[ops-1] { - becc.complexity++ - becc.subexpStarted = false - } - - becc.opsStack = append(becc.opsStack, n.Op) - case *ast.ParenExpr: - becc.subexpStarted = true - } - - return true -} - -func (becc *binExprComplexityCalculator) post(c *astutil.Cursor) bool { - switch n := c.Node().(type) { - case *ast.BinaryExpr: - isBoolOp := n.Op == token.LAND || n.Op == token.LOR - if !isBoolOp { - break - } - - ops := len(becc.opsStack) - if ops > 0 { - becc.opsStack = becc.opsStack[:ops-1] - } - case *ast.ParenExpr: - becc.subexpStarted = false - } - - return true -} diff --git a/vendor/github.com/mgechev/revive/rule/confusing-naming.go b/vendor/github.com/mgechev/revive/rule/confusing-naming.go deleted file mode 100644 index 143bb18c3..000000000 --- a/vendor/github.com/mgechev/revive/rule/confusing-naming.go +++ /dev/null @@ -1,190 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - - "strings" - "sync" - - "github.com/mgechev/revive/lint" -) - -type referenceMethod struct { - fileName string - id *ast.Ident -} - -type pkgMethods struct { - pkg *lint.Package - methods map[string]map[string]*referenceMethod - mu *sync.Mutex -} - -type packages struct { - pkgs []pkgMethods - mu sync.Mutex -} - -func (ps *packages) methodNames(lp *lint.Package) pkgMethods { - ps.mu.Lock() - - for _, pkg := range ps.pkgs { - if pkg.pkg == lp { - ps.mu.Unlock() - return pkg - } - } - - pkgm := pkgMethods{pkg: lp, methods: make(map[string]map[string]*referenceMethod), mu: &sync.Mutex{}} - ps.pkgs = append(ps.pkgs, pkgm) - - ps.mu.Unlock() - return pkgm -} - -var allPkgs = packages{pkgs: make([]pkgMethods, 1)} - -// ConfusingNamingRule lints method names that differ only by capitalization -type ConfusingNamingRule struct{} - -// Apply applies the rule to given file. -func (r *ConfusingNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - fileAst := file.AST - pkgm := allPkgs.methodNames(file.Pkg) - walker := lintConfusingNames{ - fileName: file.Name, - pkgm: pkgm, - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - ast.Walk(&walker, fileAst) - - return failures -} - -// Name returns the rule name. -func (r *ConfusingNamingRule) Name() string { - return "confusing-naming" -} - -//checkMethodName checks if a given method/function name is similar (just case differences) to other method/function of the same struct/file. -func checkMethodName(holder string, id *ast.Ident, w *lintConfusingNames) { - if id.Name == "init" && holder == defaultStructName { - // ignore init functions - return - } - - pkgm := w.pkgm - name := strings.ToUpper(id.Name) - - pkgm.mu.Lock() - defer pkgm.mu.Unlock() - - if pkgm.methods[holder] != nil { - if pkgm.methods[holder][name] != nil { - refMethod := pkgm.methods[holder][name] - // confusing names - var kind string - if holder == defaultStructName { - kind = "function" - } else { - kind = "method" - } - var fileName string - if w.fileName == refMethod.fileName { - fileName = "the same source file" - } else { - fileName = refMethod.fileName - } - w.onFailure(lint.Failure{ - Failure: fmt.Sprintf("Method '%s' differs only by capitalization to %s '%s' in %s", id.Name, kind, refMethod.id.Name, fileName), - Confidence: 1, - Node: id, - Category: "naming", - }) - - return - } - } else { - pkgm.methods[holder] = make(map[string]*referenceMethod, 1) - } - - // update the black list - if pkgm.methods[holder] == nil { - println("no entry for '", holder, "'") - } - pkgm.methods[holder][name] = &referenceMethod{fileName: w.fileName, id: id} -} - -type lintConfusingNames struct { - fileName string - pkgm pkgMethods - onFailure func(lint.Failure) -} - -const defaultStructName = "_" // used to map functions - -//getStructName of a function receiver. Defaults to defaultStructName -func getStructName(r *ast.FieldList) string { - result := defaultStructName - - if r == nil || len(r.List) < 1 { - return result - } - - t := r.List[0].Type - - if p, _ := t.(*ast.StarExpr); p != nil { // if a pointer receiver => dereference pointer receiver types - t = p.X - } - - if p, _ := t.(*ast.Ident); p != nil { - result = p.Name - } - - return result -} - -func checkStructFields(fields *ast.FieldList, structName string, w *lintConfusingNames) { - bl := make(map[string]bool, len(fields.List)) - for _, f := range fields.List { - for _, id := range f.Names { - normName := strings.ToUpper(id.Name) - if bl[normName] { - w.onFailure(lint.Failure{ - Failure: fmt.Sprintf("Field '%s' differs only by capitalization to other field in the struct type %s", id.Name, structName), - Confidence: 1, - Node: id, - Category: "naming", - }) - } else { - bl[normName] = true - } - } - } -} - -func (w *lintConfusingNames) Visit(n ast.Node) ast.Visitor { - switch v := n.(type) { - case *ast.FuncDecl: - // Exclude naming warnings for functions that are exported to C but - // not exported in the Go API. - // See https://github.com/golang/lint/issues/144. - if ast.IsExported(v.Name.Name) || !isCgoExported(v) { - checkMethodName(getStructName(v.Recv), v.Name, w) - } - case *ast.TypeSpec: - if s, ok := v.Type.(*ast.StructType); ok { - checkStructFields(s.Fields, v.Name.Name, w) - } - - default: - // will add other checks like field names, struct names, etc. - } - - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/confusing-results.go b/vendor/github.com/mgechev/revive/rule/confusing-results.go deleted file mode 100644 index 1d386b3db..000000000 --- a/vendor/github.com/mgechev/revive/rule/confusing-results.go +++ /dev/null @@ -1,67 +0,0 @@ -package rule - -import ( - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// ConfusingResultsRule lints given function declarations -type ConfusingResultsRule struct{} - -// Apply applies the rule to given file. -func (r *ConfusingResultsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - fileAst := file.AST - walker := lintConfusingResults{ - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - ast.Walk(walker, fileAst) - - return failures -} - -// Name returns the rule name. -func (r *ConfusingResultsRule) Name() string { - return "confusing-results" -} - -type lintConfusingResults struct { - onFailure func(lint.Failure) -} - -func (w lintConfusingResults) Visit(n ast.Node) ast.Visitor { - fn, ok := n.(*ast.FuncDecl) - if !ok || fn.Type.Results == nil || len(fn.Type.Results.List) < 2 { - return w - } - lastType := "" - for _, result := range fn.Type.Results.List { - if len(result.Names) > 0 { - return w - } - - t, ok := result.Type.(*ast.Ident) - if !ok { - return w - } - - if t.Name == lastType { - w.onFailure(lint.Failure{ - Node: n, - Confidence: 1, - Category: "naming", - Failure: "unnamed results of the same type may be confusing, consider using named results", - }) - break - } - lastType = t.Name - - } - - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/constant-logical-expr.go b/vendor/github.com/mgechev/revive/rule/constant-logical-expr.go deleted file mode 100644 index 6a9156111..000000000 --- a/vendor/github.com/mgechev/revive/rule/constant-logical-expr.go +++ /dev/null @@ -1,88 +0,0 @@ -package rule - -import ( - "github.com/mgechev/revive/lint" - "go/ast" - "go/token" -) - -// ConstantLogicalExprRule warns on constant logical expressions. -type ConstantLogicalExprRule struct{} - -// Apply applies the rule to given file. -func (r *ConstantLogicalExprRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - astFile := file.AST - w := &lintConstantLogicalExpr{astFile, onFailure} - ast.Walk(w, astFile) - return failures -} - -// Name returns the rule name. -func (r *ConstantLogicalExprRule) Name() string { - return "constant-logical-expr" -} - -type lintConstantLogicalExpr struct { - file *ast.File - onFailure func(lint.Failure) -} - -func (w *lintConstantLogicalExpr) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.BinaryExpr: - if !w.isOperatorWithLogicalResult(n.Op) { - return w - } - - if gofmt(n.X) != gofmt(n.Y) { // check if subexpressions are the same - return w - } - - if n.Op == token.EQL { - w.newFailure(n, "expression always evaluates to true") - return w - } - - if w.isInequalityOperator(n.Op) { - w.newFailure(n, "expression always evaluates to false") - return w - } - - w.newFailure(n, "left and right hand-side sub-expressions are the same") - } - - return w -} - -func (w *lintConstantLogicalExpr) isOperatorWithLogicalResult(t token.Token) bool { - switch t { - case token.LAND, token.LOR, token.EQL, token.LSS, token.GTR, token.NEQ, token.LEQ, token.GEQ: - return true - } - - return false -} - -func (w *lintConstantLogicalExpr) isInequalityOperator(t token.Token) bool { - switch t { - case token.LSS, token.GTR, token.NEQ, token.LEQ, token.GEQ: - return true - } - - return false -} - -func (w lintConstantLogicalExpr) newFailure(node ast.Node, msg string) { - w.onFailure(lint.Failure{ - Confidence: 1, - Node: node, - Category: "logic", - Failure: msg, - }) -} diff --git a/vendor/github.com/mgechev/revive/rule/context-as-argument.go b/vendor/github.com/mgechev/revive/rule/context-as-argument.go deleted file mode 100644 index 0ed28a82a..000000000 --- a/vendor/github.com/mgechev/revive/rule/context-as-argument.go +++ /dev/null @@ -1,60 +0,0 @@ -package rule - -import ( - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// ContextAsArgumentRule lints given else constructs. -type ContextAsArgumentRule struct{} - -// Apply applies the rule to given file. -func (r *ContextAsArgumentRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - fileAst := file.AST - walker := lintContextArguments{ - file: file, - fileAst: fileAst, - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - ast.Walk(walker, fileAst) - - return failures -} - -// Name returns the rule name. -func (r *ContextAsArgumentRule) Name() string { - return "context-as-argument" -} - -type lintContextArguments struct { - file *lint.File - fileAst *ast.File - onFailure func(lint.Failure) -} - -func (w lintContextArguments) Visit(n ast.Node) ast.Visitor { - fn, ok := n.(*ast.FuncDecl) - if !ok || len(fn.Type.Params.List) <= 1 { - return w - } - // A context.Context should be the first parameter of a function. - // Flag any that show up after the first. - for _, arg := range fn.Type.Params.List[1:] { - if isPkgDot(arg.Type, "context", "Context") { - w.onFailure(lint.Failure{ - Node: fn, - Category: "arg-order", - Failure: "context.Context should be the first parameter of a function", - Confidence: 0.9, - }) - break // only flag one - } - } - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/context-keys-type.go b/vendor/github.com/mgechev/revive/rule/context-keys-type.go deleted file mode 100644 index 9c2f0bbd7..000000000 --- a/vendor/github.com/mgechev/revive/rule/context-keys-type.go +++ /dev/null @@ -1,81 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "go/types" - - "github.com/mgechev/revive/lint" -) - -// ContextKeysType lints given else constructs. -type ContextKeysType struct{} - -// Apply applies the rule to given file. -func (r *ContextKeysType) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - fileAst := file.AST - walker := lintContextKeyTypes{ - file: file, - fileAst: fileAst, - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - file.Pkg.TypeCheck() - ast.Walk(walker, fileAst) - - return failures -} - -// Name returns the rule name. -func (r *ContextKeysType) Name() string { - return "context-keys-type" -} - -type lintContextKeyTypes struct { - file *lint.File - fileAst *ast.File - onFailure func(lint.Failure) -} - -func (w lintContextKeyTypes) Visit(n ast.Node) ast.Visitor { - switch n := n.(type) { - case *ast.CallExpr: - checkContextKeyType(w, n) - } - - return w -} - -func checkContextKeyType(w lintContextKeyTypes, x *ast.CallExpr) { - f := w.file - sel, ok := x.Fun.(*ast.SelectorExpr) - if !ok { - return - } - pkg, ok := sel.X.(*ast.Ident) - if !ok || pkg.Name != "context" { - return - } - if sel.Sel.Name != "WithValue" { - return - } - - // key is second argument to context.WithValue - if len(x.Args) != 3 { - return - } - key := f.Pkg.TypesInfo.Types[x.Args[1]] - - if ktyp, ok := key.Type.(*types.Basic); ok && ktyp.Kind() != types.Invalid { - w.onFailure(lint.Failure{ - Confidence: 1, - Node: x, - Category: "content", - Failure: fmt.Sprintf("should not use basic type %s as key in context.WithValue", key.Type), - }) - } -} diff --git a/vendor/github.com/mgechev/revive/rule/cyclomatic.go b/vendor/github.com/mgechev/revive/rule/cyclomatic.go deleted file mode 100644 index 48ea80a6a..000000000 --- a/vendor/github.com/mgechev/revive/rule/cyclomatic.go +++ /dev/null @@ -1,115 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "go/token" - - "github.com/mgechev/revive/lint" -) - -// Based on https://github.com/fzipp/gocyclo - -// CyclomaticRule lints given else constructs. -type CyclomaticRule struct{} - -// Apply applies the rule to given file. -func (r *CyclomaticRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { - var failures []lint.Failure - - complexity, ok := arguments[0].(int64) // Alt. non panicking version - if !ok { - panic("invalid argument for cyclomatic complexity") - } - - fileAst := file.AST - walker := lintCyclomatic{ - file: file, - complexity: int(complexity), - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - ast.Walk(walker, fileAst) - - return failures -} - -// Name returns the rule name. -func (r *CyclomaticRule) Name() string { - return "cyclomatic" -} - -type lintCyclomatic struct { - file *lint.File - complexity int - onFailure func(lint.Failure) -} - -func (w lintCyclomatic) Visit(_ ast.Node) ast.Visitor { - f := w.file - for _, decl := range f.AST.Decls { - if fn, ok := decl.(*ast.FuncDecl); ok { - c := complexity(fn) - if c > w.complexity { - w.onFailure(lint.Failure{ - Confidence: 1, - Category: "maintenance", - Failure: fmt.Sprintf("function %s has cyclomatic complexity %d", funcName(fn), c), - Node: fn, - }) - } - } - } - return nil -} - -// funcName returns the name representation of a function or method: -// "(Type).Name" for methods or simply "Name" for functions. -func funcName(fn *ast.FuncDecl) string { - if fn.Recv != nil { - if fn.Recv.NumFields() > 0 { - typ := fn.Recv.List[0].Type - return fmt.Sprintf("(%s).%s", recvString(typ), fn.Name) - } - } - return fn.Name.Name -} - -// recvString returns a string representation of recv of the -// form "T", "*T", or "BADRECV" (if not a proper receiver type). -func recvString(recv ast.Expr) string { - switch t := recv.(type) { - case *ast.Ident: - return t.Name - case *ast.StarExpr: - return "*" + recvString(t.X) - } - return "BADRECV" -} - -// complexity calculates the cyclomatic complexity of a function. -func complexity(fn *ast.FuncDecl) int { - v := complexityVisitor{} - ast.Walk(&v, fn) - return v.Complexity -} - -type complexityVisitor struct { - // Complexity is the cyclomatic complexity - Complexity int -} - -// Visit implements the ast.Visitor interface. -func (v *complexityVisitor) Visit(n ast.Node) ast.Visitor { - switch n := n.(type) { - case *ast.FuncDecl, *ast.IfStmt, *ast.ForStmt, *ast.RangeStmt, *ast.CaseClause, *ast.CommClause: - v.Complexity++ - case *ast.BinaryExpr: - if n.Op == token.LAND || n.Op == token.LOR { - v.Complexity++ - } - } - return v -} diff --git a/vendor/github.com/mgechev/revive/rule/deep-exit.go b/vendor/github.com/mgechev/revive/rule/deep-exit.go deleted file mode 100644 index f49e93dd4..000000000 --- a/vendor/github.com/mgechev/revive/rule/deep-exit.go +++ /dev/null @@ -1,94 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// DeepExitRule lints program exit at functions other than main or init. -type DeepExitRule struct{} - -// Apply applies the rule to given file. -func (r *DeepExitRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - var exitFunctions = map[string]map[string]bool{ - "os": map[string]bool{"Exit": true}, - "syscall": map[string]bool{"Exit": true}, - "log": map[string]bool{ - "Fatal": true, - "Fatalf": true, - "Fatalln": true, - "Panic": true, - "Panicf": true, - "Panicln": true, - }, - } - - w := lintDeepExit{onFailure, exitFunctions, file.IsTest()} - ast.Walk(w, file.AST) - return failures -} - -// Name returns the rule name. -func (r *DeepExitRule) Name() string { - return "deep-exit" -} - -type lintDeepExit struct { - onFailure func(lint.Failure) - exitFunctions map[string]map[string]bool - isTestFile bool -} - -func (w lintDeepExit) Visit(node ast.Node) ast.Visitor { - if fd, ok := node.(*ast.FuncDecl); ok { - if w.mustIgnore(fd) { - return nil // skip analysis of this function - } - - return w - } - - se, ok := node.(*ast.ExprStmt) - if !ok { - return w - } - ce, ok := se.X.(*ast.CallExpr) - if !ok { - return w - } - - fc, ok := ce.Fun.(*ast.SelectorExpr) - if !ok { - return w - } - id, ok := fc.X.(*ast.Ident) - if !ok { - return w - } - - fn := fc.Sel.Name - pkg := id.Name - if w.exitFunctions[pkg] != nil && w.exitFunctions[pkg][fn] { // it's a call to an exit function - w.onFailure(lint.Failure{ - Confidence: 1, - Node: ce, - Category: "bad practice", - Failure: fmt.Sprintf("calls to %s.%s only in main() or init() functions", pkg, fn), - }) - } - - return w -} - -func (w *lintDeepExit) mustIgnore(fd *ast.FuncDecl) bool { - fn := fd.Name.Name - - return fn == "init" || fn == "main" || (w.isTestFile && fn == "TestMain") -} diff --git a/vendor/github.com/mgechev/revive/rule/defer.go b/vendor/github.com/mgechev/revive/rule/defer.go deleted file mode 100644 index 2ec7ef47c..000000000 --- a/vendor/github.com/mgechev/revive/rule/defer.go +++ /dev/null @@ -1,137 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// DeferRule lints unused params in functions. -type DeferRule struct{} - -// Apply applies the rule to given file. -func (r *DeferRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { - allow := r.allowFromArgs(arguments) - - var failures []lint.Failure - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - w := lintDeferRule{onFailure: onFailure, allow: allow} - - ast.Walk(w, file.AST) - - return failures -} - -// Name returns the rule name. -func (r *DeferRule) Name() string { - return "defer" -} - -func (r *DeferRule) allowFromArgs(args lint.Arguments) map[string]bool { - if len(args) < 1 { - allow := map[string]bool{ - "loop": true, - "call-chain": true, - "method-call": true, - "return": true, - "recover": true, - } - - return allow - } - - aa, ok := args[0].([]interface{}) - if !ok { - panic(fmt.Sprintf("Invalid argument '%v' for 'defer' rule. Expecting []string, got %T", args[0], args[0])) - } - - allow := make(map[string]bool, len(aa)) - for _, subcase := range aa { - sc, ok := subcase.(string) - if !ok { - panic(fmt.Sprintf("Invalid argument '%v' for 'defer' rule. Expecting string, got %T", subcase, subcase)) - } - allow[sc] = true - } - - return allow -} - -type lintDeferRule struct { - onFailure func(lint.Failure) - inALoop bool - inADefer bool - inAFuncLit bool - allow map[string]bool -} - -func (w lintDeferRule) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.ForStmt: - w.visitSubtree(n.Body, w.inADefer, true, w.inAFuncLit) - return nil - case *ast.RangeStmt: - w.visitSubtree(n.Body, w.inADefer, true, w.inAFuncLit) - return nil - case *ast.FuncLit: - w.visitSubtree(n.Body, w.inADefer, false, true) - return nil - case *ast.ReturnStmt: - if len(n.Results) != 0 && w.inADefer && w.inAFuncLit { - w.newFailure("return in a defer function has no effect", n, 1.0, "logic", "return") - } - case *ast.CallExpr: - if isIdent(n.Fun, "recover") && !w.inADefer { - // confidence is not 1 because recover can be in a function that is deferred elsewhere - w.newFailure("recover must be called inside a deferred function", n, 0.8, "logic", "recover") - } - case *ast.DeferStmt: - w.visitSubtree(n.Call.Fun, true, false, false) - - if w.inALoop { - w.newFailure("prefer not to defer inside loops", n, 1.0, "bad practice", "loop") - } - - switch fn := n.Call.Fun.(type) { - case *ast.CallExpr: - w.newFailure("prefer not to defer chains of function calls", fn, 1.0, "bad practice", "call-chain") - case *ast.SelectorExpr: - if id, ok := fn.X.(*ast.Ident); ok { - isMethodCall := id != nil && id.Obj != nil && id.Obj.Kind == ast.Typ - if isMethodCall { - w.newFailure("be careful when deferring calls to methods without pointer receiver", fn, 0.8, "bad practice", "method-call") - } - } - } - return nil - } - - return w -} - -func (w lintDeferRule) visitSubtree(n ast.Node, inADefer, inALoop, inAFuncLit bool) { - nw := &lintDeferRule{ - onFailure: w.onFailure, - inADefer: inADefer, - inALoop: inALoop, - inAFuncLit: inAFuncLit, - allow: w.allow} - ast.Walk(nw, n) -} - -func (w lintDeferRule) newFailure(msg string, node ast.Node, confidence float64, cat string, subcase string) { - if !w.allow[subcase] { - return - } - - w.onFailure(lint.Failure{ - Confidence: confidence, - Node: node, - Category: cat, - Failure: msg, - }) -} diff --git a/vendor/github.com/mgechev/revive/rule/dot-imports.go b/vendor/github.com/mgechev/revive/rule/dot-imports.go deleted file mode 100644 index 78419d7d6..000000000 --- a/vendor/github.com/mgechev/revive/rule/dot-imports.go +++ /dev/null @@ -1,54 +0,0 @@ -package rule - -import ( - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// DotImportsRule lints given else constructs. -type DotImportsRule struct{} - -// Apply applies the rule to given file. -func (r *DotImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - fileAst := file.AST - walker := lintImports{ - file: file, - fileAst: fileAst, - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - ast.Walk(walker, fileAst) - - return failures -} - -// Name returns the rule name. -func (r *DotImportsRule) Name() string { - return "dot-imports" -} - -type lintImports struct { - file *lint.File - fileAst *ast.File - onFailure func(lint.Failure) -} - -func (w lintImports) Visit(_ ast.Node) ast.Visitor { - for i, is := range w.fileAst.Imports { - _ = i - if is.Name != nil && is.Name.Name == "." && !w.file.IsTest() { - w.onFailure(lint.Failure{ - Confidence: 1, - Failure: "should not use dot imports", - Node: is, - Category: "imports", - }) - } - } - return nil -} diff --git a/vendor/github.com/mgechev/revive/rule/duplicated-imports.go b/vendor/github.com/mgechev/revive/rule/duplicated-imports.go deleted file mode 100644 index 485b6a2ea..000000000 --- a/vendor/github.com/mgechev/revive/rule/duplicated-imports.go +++ /dev/null @@ -1,39 +0,0 @@ -package rule - -import ( - "fmt" - - "github.com/mgechev/revive/lint" -) - -// DuplicatedImportsRule lints given else constructs. -type DuplicatedImportsRule struct{} - -// Apply applies the rule to given file. -func (r *DuplicatedImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - impPaths := map[string]struct{}{} - for _, imp := range file.AST.Imports { - path := imp.Path.Value - _, ok := impPaths[path] - if ok { - failures = append(failures, lint.Failure{ - Confidence: 1, - Failure: fmt.Sprintf("Package %s already imported", path), - Node: imp, - Category: "imports", - }) - continue - } - - impPaths[path] = struct{}{} - } - - return failures -} - -// Name returns the rule name. -func (r *DuplicatedImportsRule) Name() string { - return "duplicated-imports" -} diff --git a/vendor/github.com/mgechev/revive/rule/early-return.go b/vendor/github.com/mgechev/revive/rule/early-return.go deleted file mode 100644 index ffb568a86..000000000 --- a/vendor/github.com/mgechev/revive/rule/early-return.go +++ /dev/null @@ -1,78 +0,0 @@ -package rule - -import ( - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// EarlyReturnRule lints given else constructs. -type EarlyReturnRule struct{} - -// Apply applies the rule to given file. -func (r *EarlyReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - w := lintEarlyReturnRule{onFailure: onFailure} - ast.Walk(w, file.AST) - return failures -} - -// Name returns the rule name. -func (r *EarlyReturnRule) Name() string { - return "early-return" -} - -type lintEarlyReturnRule struct { - onFailure func(lint.Failure) -} - -func (w lintEarlyReturnRule) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.IfStmt: - if n.Else == nil { - // no else branch - return w - } - - elseBlock, ok := n.Else.(*ast.BlockStmt) - if !ok { - // is if-else-if - return w - } - - lenElseBlock := len(elseBlock.List) - if lenElseBlock < 1 { - // empty else block, continue (there is another rule that warns on empty blocks) - return w - } - - lenThenBlock := len(n.Body.List) - if lenThenBlock < 1 { - // then block is empty thus the stmt can be simplified - w.onFailure(lint.Failure{ - Confidence: 1, - Node: n, - Failure: "if c { } else {... return} can be simplified to if !c { ... return }", - }) - - return w - } - - _, lastThenStmtIsReturn := n.Body.List[lenThenBlock-1].(*ast.ReturnStmt) - _, lastElseStmtIsReturn := elseBlock.List[lenElseBlock-1].(*ast.ReturnStmt) - if lastElseStmtIsReturn && !lastThenStmtIsReturn { - w.onFailure(lint.Failure{ - Confidence: 1, - Node: n, - Failure: "if c {...} else {... return } can be simplified to if !c { ... return } ...", - }) - } - } - - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/empty-block.go b/vendor/github.com/mgechev/revive/rule/empty-block.go deleted file mode 100644 index fbec4d93c..000000000 --- a/vendor/github.com/mgechev/revive/rule/empty-block.go +++ /dev/null @@ -1,65 +0,0 @@ -package rule - -import ( - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// EmptyBlockRule lints given else constructs. -type EmptyBlockRule struct{} - -// Apply applies the rule to given file. -func (r *EmptyBlockRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - w := lintEmptyBlock{make(map[*ast.BlockStmt]bool, 0), onFailure} - ast.Walk(w, file.AST) - return failures -} - -// Name returns the rule name. -func (r *EmptyBlockRule) Name() string { - return "empty-block" -} - -type lintEmptyBlock struct { - ignore map[*ast.BlockStmt]bool - onFailure func(lint.Failure) -} - -func (w lintEmptyBlock) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.FuncDecl: - w.ignore[n.Body] = true - return w - case *ast.FuncLit: - w.ignore[n.Body] = true - return w - case *ast.RangeStmt: - if len(n.Body.List) == 0 { - w.onFailure(lint.Failure{ - Confidence: 0.9, - Node: n, - Category: "logic", - Failure: "this block is empty, you can remove it", - }) - return nil // skip visiting the range subtree (it will produce a duplicated failure) - } - case *ast.BlockStmt: - if !w.ignore[n] && len(n.List) == 0 { - w.onFailure(lint.Failure{ - Confidence: 1, - Node: n, - Category: "logic", - Failure: "this block is empty, you can remove it", - }) - } - } - - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/empty-lines.go b/vendor/github.com/mgechev/revive/rule/empty-lines.go deleted file mode 100644 index 61d9281bf..000000000 --- a/vendor/github.com/mgechev/revive/rule/empty-lines.go +++ /dev/null @@ -1,113 +0,0 @@ -package rule - -import ( - "go/ast" - "go/token" - - "github.com/mgechev/revive/lint" -) - -// EmptyLinesRule lints empty lines in blocks. -type EmptyLinesRule struct{} - -// Apply applies the rule to given file. -func (r *EmptyLinesRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - w := lintEmptyLines{file, file.CommentMap(), onFailure} - ast.Walk(w, file.AST) - return failures -} - -// Name returns the rule name. -func (r *EmptyLinesRule) Name() string { - return "empty-lines" -} - -type lintEmptyLines struct { - file *lint.File - cmap ast.CommentMap - onFailure func(lint.Failure) -} - -func (w lintEmptyLines) Visit(node ast.Node) ast.Visitor { - block, ok := node.(*ast.BlockStmt) - if !ok { - return w - } - - w.checkStart(block) - w.checkEnd(block) - - return w -} - -func (w lintEmptyLines) checkStart(block *ast.BlockStmt) { - if len(block.List) == 0 { - return - } - - start := w.position(block.Lbrace) - firstNode := block.List[0] - - if w.commentBetween(start, firstNode) { - return - } - - first := w.position(firstNode.Pos()) - if first.Line-start.Line > 1 { - w.onFailure(lint.Failure{ - Confidence: 1, - Node: block, - Category: "style", - Failure: "extra empty line at the start of a block", - }) - } -} - -func (w lintEmptyLines) checkEnd(block *ast.BlockStmt) { - if len(block.List) < 1 { - return - } - - end := w.position(block.Rbrace) - lastNode := block.List[len(block.List)-1] - - if w.commentBetween(end, lastNode) { - return - } - - last := w.position(lastNode.End()) - if end.Line-last.Line > 1 { - w.onFailure(lint.Failure{ - Confidence: 1, - Node: lastNode, - Category: "style", - Failure: "extra empty line at the end of a block", - }) - } -} - -func (w lintEmptyLines) commentBetween(position token.Position, node ast.Node) bool { - comments := w.cmap.Filter(node).Comments() - if len(comments) == 0 { - return false - } - - for _, comment := range comments { - start, end := w.position(comment.Pos()), w.position(comment.End()) - if start.Line-position.Line == 1 || position.Line-end.Line == 1 { - return true - } - } - - return false -} - -func (w lintEmptyLines) position(pos token.Pos) token.Position { - return w.file.ToPosition(pos) -} diff --git a/vendor/github.com/mgechev/revive/rule/error-naming.go b/vendor/github.com/mgechev/revive/rule/error-naming.go deleted file mode 100644 index 3a1080625..000000000 --- a/vendor/github.com/mgechev/revive/rule/error-naming.go +++ /dev/null @@ -1,79 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "go/token" - "strings" - - "github.com/mgechev/revive/lint" -) - -// ErrorNamingRule lints given else constructs. -type ErrorNamingRule struct{} - -// Apply applies the rule to given file. -func (r *ErrorNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - fileAst := file.AST - walker := lintErrors{ - file: file, - fileAst: fileAst, - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - ast.Walk(walker, fileAst) - - return failures -} - -// Name returns the rule name. -func (r *ErrorNamingRule) Name() string { - return "error-naming" -} - -type lintErrors struct { - file *lint.File - fileAst *ast.File - onFailure func(lint.Failure) -} - -func (w lintErrors) Visit(_ ast.Node) ast.Visitor { - for _, decl := range w.fileAst.Decls { - gd, ok := decl.(*ast.GenDecl) - if !ok || gd.Tok != token.VAR { - continue - } - for _, spec := range gd.Specs { - spec := spec.(*ast.ValueSpec) - if len(spec.Names) != 1 || len(spec.Values) != 1 { - continue - } - ce, ok := spec.Values[0].(*ast.CallExpr) - if !ok { - continue - } - if !isPkgDot(ce.Fun, "errors", "New") && !isPkgDot(ce.Fun, "fmt", "Errorf") { - continue - } - - id := spec.Names[0] - prefix := "err" - if id.IsExported() { - prefix = "Err" - } - if !strings.HasPrefix(id.Name, prefix) { - w.onFailure(lint.Failure{ - Node: id, - Confidence: 0.9, - Category: "naming", - Failure: fmt.Sprintf("error var %s should have name of the form %sFoo", id.Name, prefix), - }) - } - } - } - return nil -} diff --git a/vendor/github.com/mgechev/revive/rule/error-return.go b/vendor/github.com/mgechev/revive/rule/error-return.go deleted file mode 100644 index 737d8c66f..000000000 --- a/vendor/github.com/mgechev/revive/rule/error-return.go +++ /dev/null @@ -1,67 +0,0 @@ -package rule - -import ( - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// ErrorReturnRule lints given else constructs. -type ErrorReturnRule struct{} - -// Apply applies the rule to given file. -func (r *ErrorReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - fileAst := file.AST - walker := lintErrorReturn{ - file: file, - fileAst: fileAst, - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - ast.Walk(walker, fileAst) - - return failures -} - -// Name returns the rule name. -func (r *ErrorReturnRule) Name() string { - return "error-return" -} - -type lintErrorReturn struct { - file *lint.File - fileAst *ast.File - onFailure func(lint.Failure) -} - -func (w lintErrorReturn) Visit(n ast.Node) ast.Visitor { - fn, ok := n.(*ast.FuncDecl) - if !ok || fn.Type.Results == nil { - return w - } - ret := fn.Type.Results.List - if len(ret) <= 1 { - return w - } - if isIdent(ret[len(ret)-1].Type, "error") { - return nil - } - // An error return parameter should be the last parameter. - // Flag any error parameters found before the last. - for _, r := range ret[:len(ret)-1] { - if isIdent(r.Type, "error") { - w.onFailure(lint.Failure{ - Category: "arg-order", - Confidence: 0.9, - Node: fn, - Failure: "error should be the last type when returning multiple items", - }) - break // only flag one - } - } - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/error-strings.go b/vendor/github.com/mgechev/revive/rule/error-strings.go deleted file mode 100644 index b8a5b7ed7..000000000 --- a/vendor/github.com/mgechev/revive/rule/error-strings.go +++ /dev/null @@ -1,98 +0,0 @@ -package rule - -import ( - "go/ast" - "go/token" - "strconv" - "unicode" - "unicode/utf8" - - "github.com/mgechev/revive/lint" -) - -// ErrorStringsRule lints given else constructs. -type ErrorStringsRule struct{} - -// Apply applies the rule to given file. -func (r *ErrorStringsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - fileAst := file.AST - walker := lintErrorStrings{ - file: file, - fileAst: fileAst, - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - ast.Walk(walker, fileAst) - - return failures -} - -// Name returns the rule name. -func (r *ErrorStringsRule) Name() string { - return "error-strings" -} - -type lintErrorStrings struct { - file *lint.File - fileAst *ast.File - onFailure func(lint.Failure) -} - -func (w lintErrorStrings) Visit(n ast.Node) ast.Visitor { - ce, ok := n.(*ast.CallExpr) - if !ok { - return w - } - if !isPkgDot(ce.Fun, "errors", "New") && !isPkgDot(ce.Fun, "fmt", "Errorf") { - return w - } - if len(ce.Args) < 1 { - return w - } - str, ok := ce.Args[0].(*ast.BasicLit) - if !ok || str.Kind != token.STRING { - return w - } - s, _ := strconv.Unquote(str.Value) // can assume well-formed Go - if s == "" { - return w - } - clean, conf := lintErrorString(s) - if clean { - return w - } - - w.onFailure(lint.Failure{ - Node: str, - Confidence: conf, - Category: "errors", - Failure: "error strings should not be capitalized or end with punctuation or a newline", - }) - return w -} - -func lintErrorString(s string) (isClean bool, conf float64) { - const basicConfidence = 0.8 - const capConfidence = basicConfidence - 0.2 - first, firstN := utf8.DecodeRuneInString(s) - last, _ := utf8.DecodeLastRuneInString(s) - if last == '.' || last == ':' || last == '!' || last == '\n' { - return false, basicConfidence - } - if unicode.IsUpper(first) { - // People use proper nouns and exported Go identifiers in error strings, - // so decrease the confidence of warnings for capitalization. - if len(s) <= firstN { - return false, capConfidence - } - // Flag strings starting with something that doesn't look like an initialism. - if second, _ := utf8.DecodeRuneInString(s[firstN:]); !unicode.IsUpper(second) { - return false, capConfidence - } - } - return true, 0 -} diff --git a/vendor/github.com/mgechev/revive/rule/errorf.go b/vendor/github.com/mgechev/revive/rule/errorf.go deleted file mode 100644 index 1bffbab5b..000000000 --- a/vendor/github.com/mgechev/revive/rule/errorf.go +++ /dev/null @@ -1,93 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "regexp" - "strings" - - "github.com/mgechev/revive/lint" -) - -// ErrorfRule lints given else constructs. -type ErrorfRule struct{} - -// Apply applies the rule to given file. -func (r *ErrorfRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - fileAst := file.AST - walker := lintErrorf{ - file: file, - fileAst: fileAst, - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - file.Pkg.TypeCheck() - ast.Walk(walker, fileAst) - - return failures -} - -// Name returns the rule name. -func (r *ErrorfRule) Name() string { - return "errorf" -} - -type lintErrorf struct { - file *lint.File - fileAst *ast.File - onFailure func(lint.Failure) -} - -func (w lintErrorf) Visit(n ast.Node) ast.Visitor { - ce, ok := n.(*ast.CallExpr) - if !ok || len(ce.Args) != 1 { - return w - } - isErrorsNew := isPkgDot(ce.Fun, "errors", "New") - var isTestingError bool - se, ok := ce.Fun.(*ast.SelectorExpr) - if ok && se.Sel.Name == "Error" { - if typ := w.file.Pkg.TypeOf(se.X); typ != nil { - isTestingError = typ.String() == "*testing.T" - } - } - if !isErrorsNew && !isTestingError { - return w - } - arg := ce.Args[0] - ce, ok = arg.(*ast.CallExpr) - if !ok || !isPkgDot(ce.Fun, "fmt", "Sprintf") { - return w - } - errorfPrefix := "fmt" - if isTestingError { - errorfPrefix = w.file.Render(se.X) - } - - failure := lint.Failure{ - Category: "errors", - Node: n, - Confidence: 1, - Failure: fmt.Sprintf("should replace %s(fmt.Sprintf(...)) with %s.Errorf(...)", w.file.Render(se), errorfPrefix), - } - - m := srcLineWithMatch(w.file, ce, `^(.*)`+w.file.Render(se)+`\(fmt\.Sprintf\((.*)\)\)(.*)$`) - if m != nil { - failure.ReplacementLine = m[1] + errorfPrefix + ".Errorf(" + m[2] + ")" + m[3] - } - - w.onFailure(failure) - - return w -} - -func srcLineWithMatch(file *lint.File, node ast.Node, pattern string) (m []string) { - line := srcLine(file.Content(), file.ToPosition(node.Pos())) - line = strings.TrimSuffix(line, "\n") - rx := regexp.MustCompile(pattern) - return rx.FindStringSubmatch(line) -} diff --git a/vendor/github.com/mgechev/revive/rule/exported.go b/vendor/github.com/mgechev/revive/rule/exported.go deleted file mode 100644 index b68f2bacc..000000000 --- a/vendor/github.com/mgechev/revive/rule/exported.go +++ /dev/null @@ -1,272 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "go/token" - "strings" - "unicode" - "unicode/utf8" - - "github.com/mgechev/revive/lint" -) - -// ExportedRule lints given else constructs. -type ExportedRule struct{} - -// Apply applies the rule to given file. -func (r *ExportedRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - if isTest(file) { - return failures - } - - fileAst := file.AST - walker := lintExported{ - file: file, - fileAst: fileAst, - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - genDeclMissingComments: make(map[*ast.GenDecl]bool), - } - - ast.Walk(&walker, fileAst) - - return failures -} - -// Name returns the rule name. -func (r *ExportedRule) Name() string { - return "exported" -} - -type lintExported struct { - file *lint.File - fileAst *ast.File - lastGen *ast.GenDecl - genDeclMissingComments map[*ast.GenDecl]bool - onFailure func(lint.Failure) -} - -func (w *lintExported) lintFuncDoc(fn *ast.FuncDecl) { - if !ast.IsExported(fn.Name.Name) { - // func is unexported - return - } - kind := "function" - name := fn.Name.Name - if fn.Recv != nil && len(fn.Recv.List) > 0 { - // method - kind = "method" - recv := receiverType(fn) - if !ast.IsExported(recv) { - // receiver is unexported - return - } - if commonMethods[name] { - return - } - switch name { - case "Len", "Less", "Swap": - if w.file.Pkg.Sortable[recv] { - return - } - } - name = recv + "." + name - } - if fn.Doc == nil { - w.onFailure(lint.Failure{ - Node: fn, - Confidence: 1, - Category: "comments", - Failure: fmt.Sprintf("exported %s %s should have comment or be unexported", kind, name), - }) - return - } - s := normalizeText(fn.Doc.Text()) - prefix := fn.Name.Name + " " - if !strings.HasPrefix(s, prefix) { - w.onFailure(lint.Failure{ - Node: fn.Doc, - Confidence: 0.8, - Category: "comments", - Failure: fmt.Sprintf(`comment on exported %s %s should be of the form "%s..."`, kind, name, prefix), - }) - } -} - -func (w *lintExported) checkStutter(id *ast.Ident, thing string) { - pkg, name := w.fileAst.Name.Name, id.Name - if !ast.IsExported(name) { - // unexported name - return - } - // A name stutters if the package name is a strict prefix - // and the next character of the name starts a new word. - if len(name) <= len(pkg) { - // name is too short to stutter. - // This permits the name to be the same as the package name. - return - } - if !strings.EqualFold(pkg, name[:len(pkg)]) { - return - } - // We can assume the name is well-formed UTF-8. - // If the next rune after the package name is uppercase or an underscore - // the it's starting a new word and thus this name stutters. - rem := name[len(pkg):] - if next, _ := utf8.DecodeRuneInString(rem); next == '_' || unicode.IsUpper(next) { - w.onFailure(lint.Failure{ - Node: id, - Confidence: 0.8, - Category: "naming", - Failure: fmt.Sprintf("%s name will be used as %s.%s by other packages, and that stutters; consider calling this %s", thing, pkg, name, rem), - }) - } -} - -func (w *lintExported) lintTypeDoc(t *ast.TypeSpec, doc *ast.CommentGroup) { - if !ast.IsExported(t.Name.Name) { - return - } - if doc == nil { - w.onFailure(lint.Failure{ - Node: t, - Confidence: 1, - Category: "comments", - Failure: fmt.Sprintf("exported type %v should have comment or be unexported", t.Name), - }) - return - } - - s := normalizeText(doc.Text()) - articles := [...]string{"A", "An", "The", "This"} - for _, a := range articles { - if t.Name.Name == a { - continue - } - if strings.HasPrefix(s, a+" ") { - s = s[len(a)+1:] - break - } - } - if !strings.HasPrefix(s, t.Name.Name+" ") { - w.onFailure(lint.Failure{ - Node: doc, - Confidence: 1, - Category: "comments", - Failure: fmt.Sprintf(`comment on exported type %v should be of the form "%v ..." (with optional leading article)`, t.Name, t.Name), - }) - } -} - -func (w *lintExported) lintValueSpecDoc(vs *ast.ValueSpec, gd *ast.GenDecl, genDeclMissingComments map[*ast.GenDecl]bool) { - kind := "var" - if gd.Tok == token.CONST { - kind = "const" - } - - if len(vs.Names) > 1 { - // Check that none are exported except for the first. - for _, n := range vs.Names[1:] { - if ast.IsExported(n.Name) { - w.onFailure(lint.Failure{ - Category: "comments", - Confidence: 1, - Failure: fmt.Sprintf("exported %s %s should have its own declaration", kind, n.Name), - Node: vs, - }) - return - } - } - } - - // Only one name. - name := vs.Names[0].Name - if !ast.IsExported(name) { - return - } - - if vs.Doc == nil && gd.Doc == nil { - if genDeclMissingComments[gd] { - return - } - block := "" - if kind == "const" && gd.Lparen.IsValid() { - block = " (or a comment on this block)" - } - w.onFailure(lint.Failure{ - Confidence: 1, - Node: vs, - Category: "comments", - Failure: fmt.Sprintf("exported %s %s should have comment%s or be unexported", kind, name, block), - }) - genDeclMissingComments[gd] = true - return - } - // If this GenDecl has parens and a comment, we don't check its comment form. - if gd.Lparen.IsValid() && gd.Doc != nil { - return - } - // The relevant text to check will be on either vs.Doc or gd.Doc. - // Use vs.Doc preferentially. - doc := vs.Doc - if doc == nil { - doc = gd.Doc - } - prefix := name + " " - s := normalizeText(doc.Text()) - if !strings.HasPrefix(s, prefix) { - w.onFailure(lint.Failure{ - Confidence: 1, - Node: doc, - Category: "comments", - Failure: fmt.Sprintf(`comment on exported %s %s should be of the form "%s..."`, kind, name, prefix), - }) - } -} - -// normalizeText is a helper function that normalizes comment strings by: -// * removing one leading space -// -// This function is needed because ast.CommentGroup.Text() does not handle //-style and /*-style comments uniformly -func normalizeText(t string) string { - return strings.TrimPrefix(t, " ") -} - -func (w *lintExported) Visit(n ast.Node) ast.Visitor { - switch v := n.(type) { - case *ast.GenDecl: - if v.Tok == token.IMPORT { - return nil - } - // token.CONST, token.TYPE or token.VAR - w.lastGen = v - return w - case *ast.FuncDecl: - w.lintFuncDoc(v) - if v.Recv == nil { - // Only check for stutter on functions, not methods. - // Method names are not used package-qualified. - w.checkStutter(v.Name, "func") - } - // Don't proceed inside funcs. - return nil - case *ast.TypeSpec: - // inside a GenDecl, which usually has the doc - doc := v.Doc - if doc == nil { - doc = w.lastGen.Doc - } - w.lintTypeDoc(v, doc) - w.checkStutter(v.Name, "type") - // Don't proceed inside types. - return nil - case *ast.ValueSpec: - w.lintValueSpecDoc(v, w.lastGen, w.genDeclMissingComments) - return nil - } - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/file-header.go b/vendor/github.com/mgechev/revive/rule/file-header.go deleted file mode 100644 index 6df974e91..000000000 --- a/vendor/github.com/mgechev/revive/rule/file-header.go +++ /dev/null @@ -1,69 +0,0 @@ -package rule - -import ( - "regexp" - - "github.com/mgechev/revive/lint" -) - -// FileHeaderRule lints given else constructs. -type FileHeaderRule struct{} - -var ( - multiRegexp = regexp.MustCompile("^/\\*") - singleRegexp = regexp.MustCompile("^//") -) - -// Apply applies the rule to given file. -func (r *FileHeaderRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { - if len(arguments) != 1 { - panic(`invalid configuration for "file-header" rule`) - } - - header, ok := arguments[0].(string) - if !ok { - panic(`invalid argument for "file-header" rule: first argument should be a string`) - } - - failure := []lint.Failure{ - { - Node: file.AST, - Confidence: 1, - Failure: "the file doesn't have an appropriate header", - }, - } - - if len(file.AST.Comments) == 0 { - return failure - } - - g := file.AST.Comments[0] - if g == nil { - return failure - } - comment := "" - for _, c := range g.List { - text := c.Text - if multiRegexp.Match([]byte(text)) { - text = text[2 : len(text)-2] - } else if singleRegexp.Match([]byte(text)) { - text = text[2:] - } - comment += text - } - - regex, err := regexp.Compile(header) - if err != nil { - panic(err.Error()) - } - - if !regex.Match([]byte(comment)) { - return failure - } - return nil -} - -// Name returns the rule name. -func (r *FileHeaderRule) Name() string { - return "file-header" -} diff --git a/vendor/github.com/mgechev/revive/rule/flag-param.go b/vendor/github.com/mgechev/revive/rule/flag-param.go deleted file mode 100644 index 6cb6daea9..000000000 --- a/vendor/github.com/mgechev/revive/rule/flag-param.go +++ /dev/null @@ -1,104 +0,0 @@ -package rule - -import ( - "fmt" - "github.com/mgechev/revive/lint" - "go/ast" -) - -// FlagParamRule lints given else constructs. -type FlagParamRule struct{} - -// Apply applies the rule to given file. -func (r *FlagParamRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - w := lintFlagParamRule{onFailure: onFailure} - ast.Walk(w, file.AST) - return failures -} - -// Name returns the rule name. -func (r *FlagParamRule) Name() string { - return "flag-parameter" -} - -type lintFlagParamRule struct { - onFailure func(lint.Failure) -} - -func (w lintFlagParamRule) Visit(node ast.Node) ast.Visitor { - fd, ok := node.(*ast.FuncDecl) - if !ok { - return w - } - - if fd.Body == nil { - return nil // skip whole function declaration - } - - for _, p := range fd.Type.Params.List { - t := p.Type - - id, ok := t.(*ast.Ident) - if !ok { - continue - } - - if id.Name != "bool" { - continue - } - - cv := conditionVisitor{p.Names, fd, w} - ast.Walk(cv, fd.Body) - } - - return w -} - -type conditionVisitor struct { - ids []*ast.Ident - fd *ast.FuncDecl - linter lintFlagParamRule -} - -func (w conditionVisitor) Visit(node ast.Node) ast.Visitor { - ifStmt, ok := node.(*ast.IfStmt) - if !ok { - return w - } - - fselect := func(n ast.Node) bool { - ident, ok := n.(*ast.Ident) - if !ok { - return false - } - - for _, id := range w.ids { - if ident.Name == id.Name { - return true - } - } - - return false - } - - uses := pick(ifStmt.Cond, fselect, nil) - - if len(uses) < 1 { - return w - } - - w.linter.onFailure(lint.Failure{ - Confidence: 1, - Node: w.fd.Type.Params, - Category: "bad practice", - Failure: fmt.Sprintf("parameter '%s' seems to be a control flag, avoid control coupling", uses[0]), - }) - - return nil -} diff --git a/vendor/github.com/mgechev/revive/rule/function-length.go b/vendor/github.com/mgechev/revive/rule/function-length.go deleted file mode 100644 index e1cee21cf..000000000 --- a/vendor/github.com/mgechev/revive/rule/function-length.go +++ /dev/null @@ -1,153 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "reflect" - - "github.com/mgechev/revive/lint" -) - -// FunctionLength lint. -type FunctionLength struct{} - -// Apply applies the rule to given file. -func (r *FunctionLength) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { - maxStmt, maxLines := r.parseArguments(arguments) - - var failures []lint.Failure - - walker := lintFuncLength{ - file: file, - maxStmt: int(maxStmt), - maxLines: int(maxLines), - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - ast.Walk(walker, file.AST) - - return failures -} - -// Name returns the rule name. -func (r *FunctionLength) Name() string { - return "function-length" -} - -func (r *FunctionLength) parseArguments(arguments lint.Arguments) (maxStmt int64, maxLines int64) { - if len(arguments) != 2 { - panic(fmt.Sprintf(`invalid configuration for "function-length" rule, expected 2 arguments but got %d`, len(arguments))) - } - - maxStmt, maxStmtOk := arguments[0].(int64) - if !maxStmtOk { - panic(fmt.Sprintf(`invalid configuration value for max statements in "function-length" rule; need int64 but got %T`, arguments[0])) - } - if maxStmt < 0 { - panic(fmt.Sprintf(`the configuration value for max statements in "function-length" rule cannot be negative, got %d`, maxStmt)) - } - - maxLines, maxLinesOk := arguments[1].(int64) - if !maxLinesOk { - panic(fmt.Sprintf(`invalid configuration value for max lines in "function-length" rule; need int64 but got %T`, arguments[1])) - } - if maxLines < 0 { - panic(fmt.Sprintf(`the configuration value for max statements in "function-length" rule cannot be negative, got %d`, maxLines)) - } - - return -} - -type lintFuncLength struct { - file *lint.File - maxStmt int - maxLines int - onFailure func(lint.Failure) -} - -func (w lintFuncLength) Visit(n ast.Node) ast.Visitor { - node, ok := n.(*ast.FuncDecl) - if !ok { - return w - } - - body := node.Body - if body == nil || len(node.Body.List) == 0 { - return nil - } - - if w.maxStmt > 0 { - stmtCount := w.countStmts(node.Body.List) - if stmtCount > w.maxStmt { - w.onFailure(lint.Failure{ - Confidence: 1, - Failure: fmt.Sprintf("maximum number of statements per function exceeded; max %d but got %d", w.maxStmt, stmtCount), - Node: node, - }) - } - } - - if w.maxLines > 0 { - lineCount := w.countLines(node.Body) - if lineCount > w.maxLines { - w.onFailure(lint.Failure{ - Confidence: 1, - Failure: fmt.Sprintf("maximum number of lines per function exceeded; max %d but got %d", w.maxLines, lineCount), - Node: node, - }) - } - } - - return nil -} - -func (w lintFuncLength) countLines(b *ast.BlockStmt) int { - return w.file.ToPosition(b.End()).Line - w.file.ToPosition(b.Pos()).Line - 1 -} - -func (w lintFuncLength) countStmts(b []ast.Stmt) int { - count := 0 - for _, s := range b { - switch stmt := s.(type) { - case *ast.BlockStmt: - count += w.countStmts(stmt.List) - case *ast.IfStmt: - count += 1 + w.countBodyListStmts(stmt) - if stmt.Else != nil { - elseBody, ok := stmt.Else.(*ast.BlockStmt) - if ok { - count += w.countStmts(elseBody.List) - } - } - case *ast.ForStmt, *ast.RangeStmt, - *ast.SwitchStmt, *ast.TypeSwitchStmt, *ast.SelectStmt: - count += 1 + w.countBodyListStmts(stmt) - case *ast.CaseClause: - count += w.countStmts(stmt.Body) - case *ast.AssignStmt: - count += 1 + w.countFuncLitStmts(stmt.Rhs[0]) - case *ast.GoStmt: - count += 1 + w.countFuncLitStmts(stmt.Call.Fun) - case *ast.DeferStmt: - count += 1 + w.countFuncLitStmts(stmt.Call.Fun) - default: - count++ - } - } - - return count -} - -func (w lintFuncLength) countFuncLitStmts(stmt ast.Expr) int { - if block, ok := stmt.(*ast.FuncLit); ok { - return w.countStmts(block.Body.List) - } - return 0 -} - -func (w lintFuncLength) countBodyListStmts(t interface{}) int { - i := reflect.ValueOf(t).Elem().FieldByName(`Body`).Elem().FieldByName(`List`).Interface() - return w.countStmts(i.([]ast.Stmt)) -} diff --git a/vendor/github.com/mgechev/revive/rule/function-result-limit.go b/vendor/github.com/mgechev/revive/rule/function-result-limit.go deleted file mode 100644 index 1850fc419..000000000 --- a/vendor/github.com/mgechev/revive/rule/function-result-limit.go +++ /dev/null @@ -1,68 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// FunctionResultsLimitRule lints given else constructs. -type FunctionResultsLimitRule struct{} - -// Apply applies the rule to given file. -func (r *FunctionResultsLimitRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { - if len(arguments) != 1 { - panic(`invalid configuration for "function-result-limit"`) - } - - max, ok := arguments[0].(int64) // Alt. non panicking version - if !ok { - panic(fmt.Sprintf(`invalid value passed as return results number to the "function-result-limit" rule; need int64 but got %T`, arguments[0])) - } - if max < 0 { - panic(`the value passed as return results number to the "function-result-limit" rule cannot be negative`) - } - - var failures []lint.Failure - - walker := lintFunctionResultsNum{ - max: int(max), - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - ast.Walk(walker, file.AST) - - return failures -} - -// Name returns the rule name. -func (r *FunctionResultsLimitRule) Name() string { - return "function-result-limit" -} - -type lintFunctionResultsNum struct { - max int - onFailure func(lint.Failure) -} - -func (w lintFunctionResultsNum) Visit(n ast.Node) ast.Visitor { - node, ok := n.(*ast.FuncDecl) - if ok { - num := 0 - if node.Type.Results != nil { - num = node.Type.Results.NumFields() - } - if num > w.max { - w.onFailure(lint.Failure{ - Confidence: 1, - Failure: fmt.Sprintf("maximum number of return results per function exceeded; max %d but got %d", w.max, num), - Node: node.Type, - }) - return w - } - } - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/get-return.go b/vendor/github.com/mgechev/revive/rule/get-return.go deleted file mode 100644 index 494ab6669..000000000 --- a/vendor/github.com/mgechev/revive/rule/get-return.go +++ /dev/null @@ -1,70 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "strings" - - "github.com/mgechev/revive/lint" -) - -// GetReturnRule lints given else constructs. -type GetReturnRule struct{} - -// Apply applies the rule to given file. -func (r *GetReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - w := lintReturnRule{onFailure} - ast.Walk(w, file.AST) - return failures -} - -// Name returns the rule name. -func (r *GetReturnRule) Name() string { - return "get-return" -} - -type lintReturnRule struct { - onFailure func(lint.Failure) -} - -func isGetter(name string) bool { - if strings.HasPrefix(strings.ToUpper(name), "GET") { - if len(name) > 3 { - c := name[3] - return !(c >= 'a' && c <= 'z') - } - } - - return false -} - -func hasResults(rs *ast.FieldList) bool { - return rs != nil && len(rs.List) > 0 -} - -func (w lintReturnRule) Visit(node ast.Node) ast.Visitor { - fd, ok := node.(*ast.FuncDecl) - if !ok { - return w - } - - if !isGetter(fd.Name.Name) { - return w - } - if !hasResults(fd.Type.Results) { - w.onFailure(lint.Failure{ - Confidence: 0.8, - Node: fd, - Category: "logic", - Failure: fmt.Sprintf("function '%s' seems to be a getter but it does not return any result", fd.Name.Name), - }) - } - - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/identical-branches.go b/vendor/github.com/mgechev/revive/rule/identical-branches.go deleted file mode 100644 index 094a79147..000000000 --- a/vendor/github.com/mgechev/revive/rule/identical-branches.go +++ /dev/null @@ -1,82 +0,0 @@ -package rule - -import ( - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// IdenticalBranchesRule warns on constant logical expressions. -type IdenticalBranchesRule struct{} - -// Apply applies the rule to given file. -func (r *IdenticalBranchesRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - astFile := file.AST - w := &lintIdenticalBranches{astFile, onFailure} - ast.Walk(w, astFile) - return failures -} - -// Name returns the rule name. -func (r *IdenticalBranchesRule) Name() string { - return "identical-branches" -} - -type lintIdenticalBranches struct { - file *ast.File - onFailure func(lint.Failure) -} - -func (w *lintIdenticalBranches) Visit(node ast.Node) ast.Visitor { - n, ok := node.(*ast.IfStmt) - if !ok { - return w - } - - if n.Else == nil { - return w - } - branches := []*ast.BlockStmt{n.Body} - - elseBranch, ok := n.Else.(*ast.BlockStmt) - if !ok { // if-else-if construction - return w - } - branches = append(branches, elseBranch) - - if w.identicalBranches(branches) { - w.newFailure(n, "both branches of the if are identical") - } - - return w -} - -func (w *lintIdenticalBranches) identicalBranches(branches []*ast.BlockStmt) bool { - if len(branches) < 2 { - return false - } - - ref := gofmt(branches[0]) - for i := 1; i < len(branches); i++ { - if gofmt(branches[i]) != ref { - return false - } - } - - return true -} - -func (w lintIdenticalBranches) newFailure(node ast.Node, msg string) { - w.onFailure(lint.Failure{ - Confidence: 1, - Node: node, - Category: "logic", - Failure: msg, - }) -} diff --git a/vendor/github.com/mgechev/revive/rule/if-return.go b/vendor/github.com/mgechev/revive/rule/if-return.go deleted file mode 100644 index c275d2766..000000000 --- a/vendor/github.com/mgechev/revive/rule/if-return.go +++ /dev/null @@ -1,115 +0,0 @@ -package rule - -import ( - "go/ast" - "go/token" - "strings" - - "github.com/mgechev/revive/lint" -) - -// IfReturnRule lints given else constructs. -type IfReturnRule struct{} - -// Apply applies the rule to given file. -func (r *IfReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - astFile := file.AST - w := &lintElseError{astFile, onFailure} - ast.Walk(w, astFile) - return failures -} - -// Name returns the rule name. -func (r *IfReturnRule) Name() string { - return "if-return" -} - -type lintElseError struct { - file *ast.File - onFailure func(lint.Failure) -} - -func (w *lintElseError) Visit(node ast.Node) ast.Visitor { - switch v := node.(type) { - case *ast.BlockStmt: - for i := 0; i < len(v.List)-1; i++ { - // if var := whatever; var != nil { return var } - s, ok := v.List[i].(*ast.IfStmt) - if !ok || s.Body == nil || len(s.Body.List) != 1 || s.Else != nil { - continue - } - assign, ok := s.Init.(*ast.AssignStmt) - if !ok || len(assign.Lhs) != 1 || !(assign.Tok == token.DEFINE || assign.Tok == token.ASSIGN) { - continue - } - id, ok := assign.Lhs[0].(*ast.Ident) - if !ok { - continue - } - expr, ok := s.Cond.(*ast.BinaryExpr) - if !ok || expr.Op != token.NEQ { - continue - } - if lhs, ok := expr.X.(*ast.Ident); !ok || lhs.Name != id.Name { - continue - } - if rhs, ok := expr.Y.(*ast.Ident); !ok || rhs.Name != "nil" { - continue - } - r, ok := s.Body.List[0].(*ast.ReturnStmt) - if !ok || len(r.Results) != 1 { - continue - } - if r, ok := r.Results[0].(*ast.Ident); !ok || r.Name != id.Name { - continue - } - - // return nil - r, ok = v.List[i+1].(*ast.ReturnStmt) - if !ok || len(r.Results) != 1 { - continue - } - if r, ok := r.Results[0].(*ast.Ident); !ok || r.Name != "nil" { - continue - } - - // check if there are any comments explaining the construct, don't emit an error if there are some. - if containsComments(s.Pos(), r.Pos(), w.file) { - continue - } - - w.onFailure(lint.Failure{ - Confidence: .9, - Node: v.List[i], - Failure: "redundant if ...; err != nil check, just return error instead.", - }) - } - } - return w -} - -func containsComments(start, end token.Pos, f *ast.File) bool { - for _, cgroup := range f.Comments { - comments := cgroup.List - if comments[0].Slash >= end { - // All comments starting with this group are after end pos. - return false - } - if comments[len(comments)-1].Slash < start { - // Comments group ends before start pos. - continue - } - for _, c := range comments { - if start <= c.Slash && c.Slash < end && !strings.HasPrefix(c.Text, "// MATCH ") { - return true - } - } - } - return false -} diff --git a/vendor/github.com/mgechev/revive/rule/import-shadowing.go b/vendor/github.com/mgechev/revive/rule/import-shadowing.go deleted file mode 100644 index b78234c59..000000000 --- a/vendor/github.com/mgechev/revive/rule/import-shadowing.go +++ /dev/null @@ -1,102 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "go/token" - "strings" - - "github.com/mgechev/revive/lint" -) - -// ImportShadowingRule lints given else constructs. -type ImportShadowingRule struct{} - -// Apply applies the rule to given file. -func (r *ImportShadowingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - importNames := map[string]struct{}{} - for _, imp := range file.AST.Imports { - importNames[getName(imp)] = struct{}{} - } - - fileAst := file.AST - walker := importShadowing{ - importNames: importNames, - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - alreadySeen: map[*ast.Object]struct{}{}, - } - - ast.Walk(walker, fileAst) - - return failures -} - -// Name returns the rule name. -func (r *ImportShadowingRule) Name() string { - return "import-shadowing" -} - -func getName(imp *ast.ImportSpec) string { - const pathSep = "/" - const strDelim = `"` - if imp.Name != nil { - return imp.Name.Name - } - - path := imp.Path.Value - i := strings.LastIndex(path, pathSep) - if i == -1 { - return strings.Trim(path, strDelim) - } - - return strings.Trim(path[i+1:], strDelim) -} - -type importShadowing struct { - importNames map[string]struct{} - onFailure func(lint.Failure) - alreadySeen map[*ast.Object]struct{} -} - -// Visit visits AST nodes and checks if id nodes (ast.Ident) shadow an import name -func (w importShadowing) Visit(n ast.Node) ast.Visitor { - switch n := n.(type) { - case *ast.AssignStmt: - if n.Tok == token.DEFINE { - return w // analyze variable declarations of the form id := expr - } - - return nil // skip assigns of the form id = expr (not an id declaration) - case *ast.CallExpr, // skip call expressions (not an id declaration) - *ast.ImportSpec, // skip import section subtree because we already have the list of imports - *ast.KeyValueExpr, // skip analysis of key-val expressions ({key:value}): ids of such expressions, even the same of an import name, do not shadow the import name - *ast.ReturnStmt, // skip skipping analysis of returns, ids in expression were already analyzed - *ast.SelectorExpr, // skip analysis of selector expressions (anId.otherId): because if anId shadows an import name, it was already detected, and otherId does not shadows the import name - *ast.StructType: // skip analysis of struct type because struct fields can not shadow an import name - return nil - case *ast.Ident: - id := n.Name - if id == "_" { - return w // skip _ id - } - - _, isImportName := w.importNames[id] - _, alreadySeen := w.alreadySeen[n.Obj] - if isImportName && !alreadySeen { - w.onFailure(lint.Failure{ - Confidence: 1, - Node: n, - Category: "namming", - Failure: fmt.Sprintf("The name '%s' shadows an import name", id), - }) - - w.alreadySeen[n.Obj] = struct{}{} - } - } - - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/imports-blacklist.go b/vendor/github.com/mgechev/revive/rule/imports-blacklist.go deleted file mode 100644 index 31ef901e5..000000000 --- a/vendor/github.com/mgechev/revive/rule/imports-blacklist.go +++ /dev/null @@ -1,52 +0,0 @@ -package rule - -import ( - "fmt" - - "github.com/mgechev/revive/lint" -) - -// ImportsBlacklistRule lints given else constructs. -type ImportsBlacklistRule struct{} - -// Apply applies the rule to given file. -func (r *ImportsBlacklistRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { - var failures []lint.Failure - - if file.IsTest() { - return failures // skip, test file - } - - blacklist := make(map[string]bool, len(arguments)) - - for _, arg := range arguments { - argStr, ok := arg.(string) - if !ok { - panic(fmt.Sprintf("Invalid argument to the imports-blacklist rule. Expecting a string, got %T", arg)) - } - // we add quotes if not present, because when parsed, the value of the AST node, will be quoted - if len(argStr) > 2 && argStr[0] != '"' && argStr[len(argStr)-1] != '"' { - argStr = fmt.Sprintf(`"%s"`, argStr) - } - blacklist[argStr] = true - } - - for _, is := range file.AST.Imports { - path := is.Path - if path != nil && blacklist[path.Value] { - failures = append(failures, lint.Failure{ - Confidence: 1, - Failure: "should not use the following blacklisted import: " + path.Value, - Node: is, - Category: "imports", - }) - } - } - - return failures -} - -// Name returns the rule name. -func (r *ImportsBlacklistRule) Name() string { - return "imports-blacklist" -} diff --git a/vendor/github.com/mgechev/revive/rule/increment-decrement.go b/vendor/github.com/mgechev/revive/rule/increment-decrement.go deleted file mode 100644 index 5d6b17671..000000000 --- a/vendor/github.com/mgechev/revive/rule/increment-decrement.go +++ /dev/null @@ -1,74 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "go/token" - - "github.com/mgechev/revive/lint" -) - -// IncrementDecrementRule lints given else constructs. -type IncrementDecrementRule struct{} - -// Apply applies the rule to given file. -func (r *IncrementDecrementRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - fileAst := file.AST - walker := lintIncrementDecrement{ - file: file, - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - ast.Walk(walker, fileAst) - - return failures -} - -// Name returns the rule name. -func (r *IncrementDecrementRule) Name() string { - return "increment-decrement" -} - -type lintIncrementDecrement struct { - file *lint.File - fileAst *ast.File - onFailure func(lint.Failure) -} - -func (w lintIncrementDecrement) Visit(n ast.Node) ast.Visitor { - as, ok := n.(*ast.AssignStmt) - if !ok { - return w - } - if len(as.Lhs) != 1 { - return w - } - if !isOne(as.Rhs[0]) { - return w - } - var suffix string - switch as.Tok { - case token.ADD_ASSIGN: - suffix = "++" - case token.SUB_ASSIGN: - suffix = "--" - default: - return w - } - w.onFailure(lint.Failure{ - Confidence: 0.8, - Node: as, - Category: "unary-op", - Failure: fmt.Sprintf("should replace %s with %s%s", w.file.Render(as), w.file.Render(as.Lhs[0]), suffix), - }) - return w -} - -func isOne(expr ast.Expr) bool { - lit, ok := expr.(*ast.BasicLit) - return ok && lit.Kind == token.INT && lit.Value == "1" -} diff --git a/vendor/github.com/mgechev/revive/rule/indent-error-flow.go b/vendor/github.com/mgechev/revive/rule/indent-error-flow.go deleted file mode 100644 index 4c9799b2a..000000000 --- a/vendor/github.com/mgechev/revive/rule/indent-error-flow.go +++ /dev/null @@ -1,78 +0,0 @@ -package rule - -import ( - "go/ast" - "go/token" - - "github.com/mgechev/revive/lint" -) - -// IndentErrorFlowRule lints given else constructs. -type IndentErrorFlowRule struct{} - -// Apply applies the rule to given file. -func (r *IndentErrorFlowRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - w := lintElse{make(map[*ast.IfStmt]bool), onFailure} - ast.Walk(w, file.AST) - return failures -} - -// Name returns the rule name. -func (r *IndentErrorFlowRule) Name() string { - return "indent-error-flow" -} - -type lintElse struct { - ignore map[*ast.IfStmt]bool - onFailure func(lint.Failure) -} - -func (w lintElse) Visit(node ast.Node) ast.Visitor { - ifStmt, ok := node.(*ast.IfStmt) - if !ok || ifStmt.Else == nil { - return w - } - if w.ignore[ifStmt] { - if elseif, ok := ifStmt.Else.(*ast.IfStmt); ok { - w.ignore[elseif] = true - } - return w - } - if elseif, ok := ifStmt.Else.(*ast.IfStmt); ok { - w.ignore[elseif] = true - return w - } - if _, ok := ifStmt.Else.(*ast.BlockStmt); !ok { - // only care about elses without conditions - return w - } - if len(ifStmt.Body.List) == 0 { - return w - } - shortDecl := false // does the if statement have a ":=" initialization statement? - if ifStmt.Init != nil { - if as, ok := ifStmt.Init.(*ast.AssignStmt); ok && as.Tok == token.DEFINE { - shortDecl = true - } - } - lastStmt := ifStmt.Body.List[len(ifStmt.Body.List)-1] - if _, ok := lastStmt.(*ast.ReturnStmt); ok { - extra := "" - if shortDecl { - extra = " (move short variable declaration to its own line if necessary)" - } - w.onFailure(lint.Failure{ - Confidence: 1, - Node: ifStmt.Else, - Category: "indent", - Failure: "if block ends with a return statement, so drop this else and outdent its block" + extra, - }) - } - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/line-length-limit.go b/vendor/github.com/mgechev/revive/rule/line-length-limit.go deleted file mode 100644 index 5ee057079..000000000 --- a/vendor/github.com/mgechev/revive/rule/line-length-limit.go +++ /dev/null @@ -1,84 +0,0 @@ -package rule - -import ( - "bufio" - "bytes" - "fmt" - "go/token" - "strings" - "unicode/utf8" - - "github.com/mgechev/revive/lint" -) - -// LineLengthLimitRule lints given else constructs. -type LineLengthLimitRule struct{} - -// Apply applies the rule to given file. -func (r *LineLengthLimitRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { - if len(arguments) != 1 { - panic(`invalid configuration for "line-length-limit"`) - } - - max, ok := arguments[0].(int64) // Alt. non panicking version - if !ok || max < 0 { - panic(`invalid value passed as argument number to the "line-length-limit" rule`) - } - - var failures []lint.Failure - checker := lintLineLengthNum{ - max: int(max), - file: file, - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - checker.check() - - return failures -} - -// Name returns the rule name. -func (r *LineLengthLimitRule) Name() string { - return "line-length-limit" -} - -type lintLineLengthNum struct { - max int - file *lint.File - onFailure func(lint.Failure) -} - -func (r lintLineLengthNum) check() { - f := bytes.NewReader(r.file.Content()) - spaces := strings.Repeat(" ", 4) // tab width = 4 - l := 1 - s := bufio.NewScanner(f) - for s.Scan() { - t := s.Text() - t = strings.Replace(t, "\t", spaces, -1) - c := utf8.RuneCountInString(t) - if c > r.max { - r.onFailure(lint.Failure{ - Category: "code-style", - Position: lint.FailurePosition{ - // Offset not set; it is non-trivial, and doesn't appear to be needed. - Start: token.Position{ - Filename: r.file.Name, - Line: l, - Column: 0, - }, - End: token.Position{ - Filename: r.file.Name, - Line: l, - Column: c, - }, - }, - Confidence: 1, - Failure: fmt.Sprintf("line is %d characters, out of limit %d", c, r.max), - }) - } - l++ - } -} diff --git a/vendor/github.com/mgechev/revive/rule/max-public-structs.go b/vendor/github.com/mgechev/revive/rule/max-public-structs.go deleted file mode 100644 index 9a2d07cbc..000000000 --- a/vendor/github.com/mgechev/revive/rule/max-public-structs.go +++ /dev/null @@ -1,67 +0,0 @@ -package rule - -import ( - "go/ast" - - "strings" - - "github.com/mgechev/revive/lint" -) - -// MaxPublicStructsRule lints given else constructs. -type MaxPublicStructsRule struct{} - -// Apply applies the rule to given file. -func (r *MaxPublicStructsRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { - var failures []lint.Failure - - fileAst := file.AST - walker := &lintMaxPublicStructs{ - fileAst: fileAst, - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - ast.Walk(walker, fileAst) - - max, ok := arguments[0].(int64) // Alt. non panicking version - if !ok { - panic(`invalid value passed as argument number to the "max-public-structs" rule`) - } - - if walker.current > max { - walker.onFailure(lint.Failure{ - Failure: "you have exceeded the maximum number of public struct declarations", - Confidence: 1, - Node: fileAst, - Category: "style", - }) - } - - return failures -} - -// Name returns the rule name. -func (r *MaxPublicStructsRule) Name() string { - return "max-public-structs" -} - -type lintMaxPublicStructs struct { - current int64 - fileAst *ast.File - onFailure func(lint.Failure) -} - -func (w *lintMaxPublicStructs) Visit(n ast.Node) ast.Visitor { - switch v := n.(type) { - case *ast.TypeSpec: - name := v.Name.Name - first := string(name[0]) - if strings.ToUpper(first) == first { - w.current++ - } - break - } - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/modifies-param.go b/vendor/github.com/mgechev/revive/rule/modifies-param.go deleted file mode 100644 index 55136e6c8..000000000 --- a/vendor/github.com/mgechev/revive/rule/modifies-param.go +++ /dev/null @@ -1,80 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// ModifiesParamRule lints given else constructs. -type ModifiesParamRule struct{} - -// Apply applies the rule to given file. -func (r *ModifiesParamRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - w := lintModifiesParamRule{onFailure: onFailure} - ast.Walk(w, file.AST) - return failures -} - -// Name returns the rule name. -func (r *ModifiesParamRule) Name() string { - return "modifies-parameter" -} - -type lintModifiesParamRule struct { - params map[string]bool - onFailure func(lint.Failure) -} - -func retrieveParamNames(pl []*ast.Field) map[string]bool { - result := make(map[string]bool, len(pl)) - for _, p := range pl { - for _, n := range p.Names { - if n.Name == "_" { - continue - } - - result[n.Name] = true - } - } - return result -} - -func (w lintModifiesParamRule) Visit(node ast.Node) ast.Visitor { - switch v := node.(type) { - case *ast.FuncDecl: - w.params = retrieveParamNames(v.Type.Params.List) - case *ast.IncDecStmt: - if id, ok := v.X.(*ast.Ident); ok { - checkParam(id, &w) - } - case *ast.AssignStmt: - lhs := v.Lhs - for _, e := range lhs { - id, ok := e.(*ast.Ident) - if ok { - checkParam(id, &w) - } - } - } - - return w -} - -func checkParam(id *ast.Ident, w *lintModifiesParamRule) { - if w.params[id.Name] { - w.onFailure(lint.Failure{ - Confidence: 0.5, // confidence is low because of shadow variables - Node: id, - Category: "bad practice", - Failure: fmt.Sprintf("parameter '%s' seems to be modified", id), - }) - } -} diff --git a/vendor/github.com/mgechev/revive/rule/modifies-value-receiver.go b/vendor/github.com/mgechev/revive/rule/modifies-value-receiver.go deleted file mode 100644 index 4fe22ddf3..000000000 --- a/vendor/github.com/mgechev/revive/rule/modifies-value-receiver.go +++ /dev/null @@ -1,134 +0,0 @@ -package rule - -import ( - "go/ast" - "strings" - - "github.com/mgechev/revive/lint" -) - -// ModifiesValRecRule lints assignments to value method-receivers. -type ModifiesValRecRule struct{} - -// Apply applies the rule to given file. -func (r *ModifiesValRecRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - w := lintModifiesValRecRule{file: file, onFailure: onFailure} - file.Pkg.TypeCheck() - ast.Walk(w, file.AST) - - return failures -} - -// Name returns the rule name. -func (r *ModifiesValRecRule) Name() string { - return "modifies-value-receiver" -} - -type lintModifiesValRecRule struct { - file *lint.File - onFailure func(lint.Failure) -} - -func (w lintModifiesValRecRule) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.FuncDecl: - if n.Recv == nil { - return nil // skip, not a method - } - - receiver := n.Recv.List[0] - if _, ok := receiver.Type.(*ast.StarExpr); ok { - return nil // skip, method with pointer receiver - } - - if w.skipType(receiver.Type) { - return nil // skip, receiver is a map or array - } - - if len(receiver.Names) < 1 { - return nil // skip, anonymous receiver - } - - receiverName := receiver.Names[0].Name - if receiverName == "_" { - return nil // skip, anonymous receiver - } - - fselect := func(n ast.Node) bool { - // look for assignments with the receiver in the right hand - asgmt, ok := n.(*ast.AssignStmt) - if !ok { - return false - } - - for _, exp := range asgmt.Lhs { - switch e := exp.(type) { - case *ast.IndexExpr: // receiver...[] = ... - continue - case *ast.StarExpr: // *receiver = ... - continue - case *ast.SelectorExpr: // receiver.field = ... - name := w.getNameFromExpr(e.X) - if name == "" || name != receiverName { - continue - } - - if w.skipType(ast.Expr(e.Sel)) { - continue - } - - case *ast.Ident: // receiver := ... - if e.Name != receiverName { - continue - } - default: - continue - } - - return true - } - - return false - } - - assignmentsToReceiver := pick(n.Body, fselect, nil) - - for _, assignment := range assignmentsToReceiver { - w.onFailure(lint.Failure{ - Node: assignment, - Confidence: 1, - Failure: "suspicious assignment to a by-value method receiver", - }) - } - } - - return w -} - -func (w lintModifiesValRecRule) skipType(t ast.Expr) bool { - rt := w.file.Pkg.TypeOf(t) - if rt == nil { - return false - } - - rt = rt.Underlying() - rtName := rt.String() - - // skip when receiver is a map or array - return strings.HasPrefix(rtName, "[]") || strings.HasPrefix(rtName, "map[") -} - -func (lintModifiesValRecRule) getNameFromExpr(ie ast.Expr) string { - ident, ok := ie.(*ast.Ident) - if !ok { - return "" - } - - return ident.Name -} diff --git a/vendor/github.com/mgechev/revive/rule/package-comments.go b/vendor/github.com/mgechev/revive/rule/package-comments.go deleted file mode 100644 index 00fc5bb91..000000000 --- a/vendor/github.com/mgechev/revive/rule/package-comments.go +++ /dev/null @@ -1,121 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "go/token" - "strings" - - "github.com/mgechev/revive/lint" -) - -// PackageCommentsRule lints the package comments. It complains if -// there is no package comment, or if it is not of the right form. -// This has a notable false positive in that a package comment -// could rightfully appear in a different file of the same package, -// but that's not easy to fix since this linter is file-oriented. -type PackageCommentsRule struct{} - -// Apply applies the rule to given file. -func (r *PackageCommentsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - if isTest(file) { - return failures - } - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - fileAst := file.AST - w := &lintPackageComments{fileAst, file, onFailure} - ast.Walk(w, fileAst) - return failures -} - -// Name returns the rule name. -func (r *PackageCommentsRule) Name() string { - return "package-comments" -} - -type lintPackageComments struct { - fileAst *ast.File - file *lint.File - onFailure func(lint.Failure) -} - -func (l *lintPackageComments) Visit(_ ast.Node) ast.Visitor { - if l.file.IsTest() { - return nil - } - - const ref = styleGuideBase + "#package-comments" - prefix := "Package " + l.fileAst.Name.Name + " " - - // Look for a detached package comment. - // First, scan for the last comment that occurs before the "package" keyword. - var lastCG *ast.CommentGroup - for _, cg := range l.fileAst.Comments { - if cg.Pos() > l.fileAst.Package { - // Gone past "package" keyword. - break - } - lastCG = cg - } - if lastCG != nil && strings.HasPrefix(lastCG.Text(), prefix) { - endPos := l.file.ToPosition(lastCG.End()) - pkgPos := l.file.ToPosition(l.fileAst.Package) - if endPos.Line+1 < pkgPos.Line { - // There isn't a great place to anchor this error; - // the start of the blank lines between the doc and the package statement - // is at least pointing at the location of the problem. - pos := token.Position{ - Filename: endPos.Filename, - // Offset not set; it is non-trivial, and doesn't appear to be needed. - Line: endPos.Line + 1, - Column: 1, - } - l.onFailure(lint.Failure{ - Category: "comments", - Position: lint.FailurePosition{ - Start: pos, - End: pos, - }, - Confidence: 0.9, - Failure: "package comment is detached; there should be no blank lines between it and the package statement", - }) - return nil - } - } - - if l.fileAst.Doc == nil { - l.onFailure(lint.Failure{ - Category: "comments", - Node: l.fileAst, - Confidence: 0.2, - Failure: "should have a package comment, unless it's in another file for this package", - }) - return nil - } - s := l.fileAst.Doc.Text() - if ts := strings.TrimLeft(s, " \t"); ts != s { - l.onFailure(lint.Failure{ - Category: "comments", - Node: l.fileAst.Doc, - Confidence: 1, - Failure: "package comment should not have leading space", - }) - s = ts - } - // Only non-main packages need to keep to this form. - if !l.file.Pkg.IsMain() && !strings.HasPrefix(s, prefix) { - l.onFailure(lint.Failure{ - Category: "comments", - Node: l.fileAst.Doc, - Confidence: 1, - Failure: fmt.Sprintf(`package comment should be of the form "%s..."`, prefix), - }) - } - return nil -} diff --git a/vendor/github.com/mgechev/revive/rule/range-val-address.go b/vendor/github.com/mgechev/revive/rule/range-val-address.go deleted file mode 100644 index 18554825a..000000000 --- a/vendor/github.com/mgechev/revive/rule/range-val-address.go +++ /dev/null @@ -1,113 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "go/token" - - "github.com/mgechev/revive/lint" -) - -// RangeValAddress lints -type RangeValAddress struct{} - -// Apply applies the rule to given file. -func (r *RangeValAddress) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - walker := rangeValAddress{ - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - ast.Walk(walker, file.AST) - - return failures -} - -// Name returns the rule name. -func (r *RangeValAddress) Name() string { - return "range-val-address" -} - -type rangeValAddress struct { - onFailure func(lint.Failure) -} - -func (w rangeValAddress) Visit(node ast.Node) ast.Visitor { - n, ok := node.(*ast.RangeStmt) - if !ok { - return w - } - - value, ok := n.Value.(*ast.Ident) - if !ok { - return w - } - - ast.Walk(rangeBodyVisitor{ - valueID: value.Obj, - onFailure: w.onFailure, - }, n.Body) - - return w -} - -type rangeBodyVisitor struct { - valueID *ast.Object - onFailure func(lint.Failure) -} - -func (bw rangeBodyVisitor) Visit(node ast.Node) ast.Visitor { - asgmt, ok := node.(*ast.AssignStmt) - if !ok { - return bw - } - - for _, exp := range asgmt.Lhs { - e, ok := exp.(*ast.IndexExpr) - if !ok { - continue - } - if bw.isAccessingRangeValueAddress(e.Index) { // e.g. a[&value]... - bw.onFailure(bw.newFailure(e.Index)) - } - } - - for _, exp := range asgmt.Rhs { - switch e := exp.(type) { - case *ast.UnaryExpr: // e.g. ...&value - if bw.isAccessingRangeValueAddress(e) { - bw.onFailure(bw.newFailure(e)) - } - case *ast.CallExpr: - if fun, ok := e.Fun.(*ast.Ident); ok && fun.Name == "append" { // e.g. ...append(arr, &value) - for _, v := range e.Args { - if bw.isAccessingRangeValueAddress(v) { - bw.onFailure(bw.newFailure(e)) - } - } - } - } - } - return bw -} - -func (bw rangeBodyVisitor) isAccessingRangeValueAddress(exp ast.Expr) bool { - u, ok := exp.(*ast.UnaryExpr) - if !ok { - return false - } - - v, ok := u.X.(*ast.Ident) - return ok && u.Op == token.AND && v.Obj == bw.valueID -} - -func (bw rangeBodyVisitor) newFailure(node ast.Node) lint.Failure { - return lint.Failure{ - Node: node, - Confidence: 1, - Failure: fmt.Sprintf("suspicious assignment of '%s'. range-loop variables always have the same address", bw.valueID.Name), - } -} diff --git a/vendor/github.com/mgechev/revive/rule/range-val-in-closure.go b/vendor/github.com/mgechev/revive/rule/range-val-in-closure.go deleted file mode 100644 index 857787be3..000000000 --- a/vendor/github.com/mgechev/revive/rule/range-val-in-closure.go +++ /dev/null @@ -1,111 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// RangeValInClosureRule lints given else constructs. -type RangeValInClosureRule struct{} - -// Apply applies the rule to given file. -func (r *RangeValInClosureRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - walker := rangeValInClosure{ - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - ast.Walk(walker, file.AST) - - return failures -} - -// Name returns the rule name. -func (r *RangeValInClosureRule) Name() string { - return "range-val-in-closure" -} - -type rangeValInClosure struct { - onFailure func(lint.Failure) -} - -func (w rangeValInClosure) Visit(node ast.Node) ast.Visitor { - - // Find the variables updated by the loop statement. - var vars []*ast.Ident - addVar := func(expr ast.Expr) { - if id, ok := expr.(*ast.Ident); ok { - vars = append(vars, id) - } - } - var body *ast.BlockStmt - switch n := node.(type) { - case *ast.RangeStmt: - body = n.Body - addVar(n.Key) - addVar(n.Value) - case *ast.ForStmt: - body = n.Body - switch post := n.Post.(type) { - case *ast.AssignStmt: - // e.g. for p = head; p != nil; p = p.next - for _, lhs := range post.Lhs { - addVar(lhs) - } - case *ast.IncDecStmt: - // e.g. for i := 0; i < n; i++ - addVar(post.X) - } - } - if vars == nil { - return w - } - - // Inspect a go or defer statement - // if it's the last one in the loop body. - // (We give up if there are following statements, - // because it's hard to prove go isn't followed by wait, - // or defer by return.) - if len(body.List) == 0 { - return w - } - var last *ast.CallExpr - switch s := body.List[len(body.List)-1].(type) { - case *ast.GoStmt: - last = s.Call - case *ast.DeferStmt: - last = s.Call - default: - return w - } - lit, ok := last.Fun.(*ast.FuncLit) - if !ok { - return w - } - if lit.Type == nil { - // Not referring to a variable (e.g. struct field name) - return w - } - ast.Inspect(lit.Body, func(n ast.Node) bool { - id, ok := n.(*ast.Ident) - if !ok || id.Obj == nil { - return true - } - for _, v := range vars { - if v.Obj == id.Obj { - w.onFailure(lint.Failure{ - Confidence: 1, - Failure: fmt.Sprintf("loop variable %v captured by func literal", id.Name), - Node: n, - }) - } - } - return true - }) - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/range.go b/vendor/github.com/mgechev/revive/rule/range.go deleted file mode 100644 index d18492c71..000000000 --- a/vendor/github.com/mgechev/revive/rule/range.go +++ /dev/null @@ -1,82 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "strings" - - "github.com/mgechev/revive/lint" -) - -// RangeRule lints given else constructs. -type RangeRule struct{} - -// Apply applies the rule to given file. -func (r *RangeRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - w := &lintRanges{file, onFailure} - ast.Walk(w, file.AST) - return failures -} - -// Name returns the rule name. -func (r *RangeRule) Name() string { - return "range" -} - -type lintRanges struct { - file *lint.File - onFailure func(lint.Failure) -} - -func (w *lintRanges) Visit(node ast.Node) ast.Visitor { - rs, ok := node.(*ast.RangeStmt) - if !ok { - return w - } - if rs.Value == nil { - // for x = range m { ... } - return w // single var form - } - if !isIdent(rs.Value, "_") { - // for ?, y = range m { ... } - return w - } - - newRS := *rs // shallow copy - newRS.Value = nil - - w.onFailure(lint.Failure{ - Failure: fmt.Sprintf("should omit 2nd value from range; this loop is equivalent to `for %s %s range ...`", w.file.Render(rs.Key), rs.Tok), - Confidence: 1, - Node: rs.Value, - ReplacementLine: firstLineOf(w.file, &newRS, rs), - }) - - return w -} - -func firstLineOf(f *lint.File, node, match ast.Node) string { - line := f.Render(node) - if i := strings.Index(line, "\n"); i >= 0 { - line = line[:i] - } - return indentOf(f, match) + line -} - -func indentOf(f *lint.File, node ast.Node) string { - line := srcLine(f.Content(), f.ToPosition(node.Pos())) - for i, r := range line { - switch r { - case ' ', '\t': - default: - return line[:i] - } - } - return line // unusual or empty line -} diff --git a/vendor/github.com/mgechev/revive/rule/receiver-naming.go b/vendor/github.com/mgechev/revive/rule/receiver-naming.go deleted file mode 100644 index 589d5f0ef..000000000 --- a/vendor/github.com/mgechev/revive/rule/receiver-naming.go +++ /dev/null @@ -1,81 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// ReceiverNamingRule lints given else constructs. -type ReceiverNamingRule struct{} - -// Apply applies the rule to given file. -func (r *ReceiverNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - fileAst := file.AST - walker := lintReceiverName{ - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - typeReceiver: map[string]string{}, - } - - ast.Walk(walker, fileAst) - - return failures -} - -// Name returns the rule name. -func (r *ReceiverNamingRule) Name() string { - return "receiver-naming" -} - -type lintReceiverName struct { - onFailure func(lint.Failure) - typeReceiver map[string]string -} - -func (w lintReceiverName) Visit(n ast.Node) ast.Visitor { - fn, ok := n.(*ast.FuncDecl) - if !ok || fn.Recv == nil || len(fn.Recv.List) == 0 { - return w - } - names := fn.Recv.List[0].Names - if len(names) < 1 { - return w - } - name := names[0].Name - const ref = styleGuideBase + "#receiver-names" - if name == "_" { - w.onFailure(lint.Failure{ - Node: n, - Confidence: 1, - Category: "naming", - Failure: "receiver name should not be an underscore, omit the name if it is unused", - }) - return w - } - if name == "this" || name == "self" { - w.onFailure(lint.Failure{ - Node: n, - Confidence: 1, - Category: "naming", - Failure: `receiver name should be a reflection of its identity; don't use generic names such as "this" or "self"`, - }) - return w - } - recv := receiverType(fn) - if prev, ok := w.typeReceiver[recv]; ok && prev != name { - w.onFailure(lint.Failure{ - Node: n, - Confidence: 1, - Category: "naming", - Failure: fmt.Sprintf("receiver name %s should be consistent with previous receiver name %s for %s", name, prev, recv), - }) - return w - } - w.typeReceiver[recv] = name - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/redefines-builtin-id.go b/vendor/github.com/mgechev/revive/rule/redefines-builtin-id.go deleted file mode 100644 index 947b8aac7..000000000 --- a/vendor/github.com/mgechev/revive/rule/redefines-builtin-id.go +++ /dev/null @@ -1,145 +0,0 @@ -package rule - -import ( - "fmt" - "github.com/mgechev/revive/lint" - "go/ast" - "go/token" -) - -// RedefinesBuiltinIDRule warns when a builtin identifier is shadowed. -type RedefinesBuiltinIDRule struct{} - -// Apply applies the rule to given file. -func (r *RedefinesBuiltinIDRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - var builtInConstAndVars = map[string]bool{ - "true": true, - "false": true, - "iota": true, - "nil": true, - } - - var builtFunctions = map[string]bool{ - "append": true, - "cap": true, - "close": true, - "complex": true, - "copy": true, - "delete": true, - "imag": true, - "len": true, - "make": true, - "new": true, - "panic": true, - "print": true, - "println": true, - "real": true, - "recover": true, - } - - var builtInTypes = map[string]bool{ - "ComplexType": true, - "FloatType": true, - "IntegerType": true, - "Type": true, - "Type1": true, - "bool": true, - "byte": true, - "complex128": true, - "complex64": true, - "error": true, - "float32": true, - "float64": true, - "int": true, - "int16": true, - "int32": true, - "int64": true, - "int8": true, - "rune": true, - "string": true, - "uint": true, - "uint16": true, - "uint32": true, - "uint64": true, - "uint8": true, - "uintptr": true, - } - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - astFile := file.AST - w := &lintRedefinesBuiltinID{builtInConstAndVars, builtFunctions, builtInTypes, onFailure} - ast.Walk(w, astFile) - - return failures -} - -// Name returns the rule name. -func (r *RedefinesBuiltinIDRule) Name() string { - return "redefines-builtin-id" -} - -type lintRedefinesBuiltinID struct { - constsAndVars map[string]bool - funcs map[string]bool - types map[string]bool - onFailure func(lint.Failure) -} - -func (w *lintRedefinesBuiltinID) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.GenDecl: - if n.Tok != token.TYPE { - return nil // skip if not type declaration - } - typeSpec, ok := n.Specs[0].(*ast.TypeSpec) - if !ok { - return nil - } - id := typeSpec.Name.Name - if w.types[id] { - w.addFailure(n, fmt.Sprintf("redefinition of the built-in type %s", id)) - } - case *ast.FuncDecl: - if n.Recv != nil { - return w // skip methods - } - - id := n.Name.Name - if w.funcs[id] { - w.addFailure(n, fmt.Sprintf("redefinition of the built-in function %s", id)) - } - case *ast.AssignStmt: - for _, e := range n.Lhs { - id, ok := e.(*ast.Ident) - if !ok { - continue - } - - if w.constsAndVars[id.Name] { - var msg string - if n.Tok == token.DEFINE { - msg = fmt.Sprintf("assignment creates a shadow of built-in identifier %s", id.Name) - } else { - msg = fmt.Sprintf("assignment modifies built-in identifier %s", id.Name) - } - w.addFailure(n, msg) - } - } - } - - return w -} - -func (w lintRedefinesBuiltinID) addFailure(node ast.Node, msg string) { - w.onFailure(lint.Failure{ - Confidence: 1, - Node: node, - Category: "logic", - Failure: msg, - }) -} diff --git a/vendor/github.com/mgechev/revive/rule/string-of-int.go b/vendor/github.com/mgechev/revive/rule/string-of-int.go deleted file mode 100644 index 38f453a4a..000000000 --- a/vendor/github.com/mgechev/revive/rule/string-of-int.go +++ /dev/null @@ -1,95 +0,0 @@ -package rule - -import ( - "go/ast" - "go/types" - - "github.com/mgechev/revive/lint" -) - -// StringOfIntRule warns when logic expressions contains Boolean literals. -type StringOfIntRule struct{} - -// Apply applies the rule to given file. -func (r *StringOfIntRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - astFile := file.AST - file.Pkg.TypeCheck() - - w := &lintStringInt{file, onFailure} - ast.Walk(w, astFile) - - return failures -} - -// Name returns the rule name. -func (r *StringOfIntRule) Name() string { - return "string-of-int" -} - -type lintStringInt struct { - file *lint.File - onFailure func(lint.Failure) -} - -func (w *lintStringInt) Visit(node ast.Node) ast.Visitor { - ce, ok := node.(*ast.CallExpr) - if !ok { - return w - } - - if !w.isCallStringCast(ce.Fun) { - return w - } - - if !w.isIntExpression(ce.Args) { - return w - } - - w.onFailure(lint.Failure{ - Confidence: 1, - Node: ce, - Failure: "dubious convertion of an integer into a string, use strconv.Itoa", - }) - - return w -} - -func (w *lintStringInt) isCallStringCast(e ast.Expr) bool { - t := w.file.Pkg.TypeOf(e) - if t == nil { - return false - } - - tb, _ := t.Underlying().(*types.Basic) - - return tb != nil && tb.Kind() == types.String -} - -func (w *lintStringInt) isIntExpression(es []ast.Expr) bool { - if len(es) != 1 { - return false - } - - t := w.file.Pkg.TypeOf(es[0]) - if t == nil { - return false - } - - ut, _ := t.Underlying().(*types.Basic) - if ut == nil || ut.Info()&types.IsInteger == 0 { - return false - } - - switch ut.Kind() { - case types.Byte, types.Rune, types.UntypedRune: - return false - } - - return true -} diff --git a/vendor/github.com/mgechev/revive/rule/struct-tag.go b/vendor/github.com/mgechev/revive/rule/struct-tag.go deleted file mode 100644 index cb3818e92..000000000 --- a/vendor/github.com/mgechev/revive/rule/struct-tag.go +++ /dev/null @@ -1,236 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "strconv" - "strings" - - "github.com/fatih/structtag" - "github.com/mgechev/revive/lint" -) - -// StructTagRule lints struct tags. -type StructTagRule struct{} - -// Apply applies the rule to given file. -func (r *StructTagRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - w := lintStructTagRule{onFailure: onFailure} - - ast.Walk(w, file.AST) - - return failures -} - -// Name returns the rule name. -func (r *StructTagRule) Name() string { - return "struct-tag" -} - -type lintStructTagRule struct { - onFailure func(lint.Failure) - usedTagNbr map[string]bool // list of used tag numbers -} - -func (w lintStructTagRule) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.StructType: - if n.Fields == nil || n.Fields.NumFields() < 1 { - return nil // skip empty structs - } - w.usedTagNbr = map[string]bool{} // init - for _, f := range n.Fields.List { - if f.Tag != nil { - w.checkTaggedField(f) - } - } - } - - return w - -} - -// checkTaggedField checks the tag of the given field. -// precondition: the field has a tag -func (w lintStructTagRule) checkTaggedField(f *ast.Field) { - if len(f.Names) > 0 && !f.Names[0].IsExported() { - w.addFailure(f, "tag on not-exported field "+f.Names[0].Name) - } - - tags, err := structtag.Parse(strings.Trim(f.Tag.Value, "`")) - if err != nil || tags == nil { - w.addFailure(f.Tag, "malformed tag") - return - } - - for _, tag := range tags.Tags() { - switch key := tag.Key; key { - case "asn1": - msg, ok := w.checkASN1Tag(f.Type, tag) - if !ok { - w.addFailure(f.Tag, msg) - } - case "bson": - msg, ok := w.checkBSONTag(tag.Options) - if !ok { - w.addFailure(f.Tag, msg) - } - case "default": - if !w.typeValueMatch(f.Type, tag.Name) { - w.addFailure(f.Tag, "field's type and default value's type mismatch") - } - case "json": - msg, ok := w.checkJSONTag(tag.Name, tag.Options) - if !ok { - w.addFailure(f.Tag, msg) - } - case "protobuf": - // Not implemented yet - case "required": - if tag.Name != "true" && tag.Name != "false" { - w.addFailure(f.Tag, "required should be 'true' or 'false'") - } - case "xml": - msg, ok := w.checkXMLTag(tag.Options) - if !ok { - w.addFailure(f.Tag, msg) - } - case "yaml": - msg, ok := w.checkYAMLTag(tag.Options) - if !ok { - w.addFailure(f.Tag, msg) - } - default: - // unknown key - } - } -} - -func (w lintStructTagRule) checkASN1Tag(t ast.Expr, tag *structtag.Tag) (string, bool) { - checkList := append(tag.Options, tag.Name) - for _, opt := range checkList { - switch opt { - case "application", "explicit", "generalized", "ia5", "omitempty", "optional", "set", "utf8": - - default: - if strings.HasPrefix(opt, "tag:") { - parts := strings.Split(opt, ":") - tagNumber := parts[1] - if w.usedTagNbr[tagNumber] { - return fmt.Sprintf("duplicated tag number %s", tagNumber), false - } - w.usedTagNbr[tagNumber] = true - - continue - } - - if strings.HasPrefix(opt, "default:") { - parts := strings.Split(opt, ":") - if len(parts) < 2 { - return "malformed default for ASN1 tag", false - } - if !w.typeValueMatch(t, parts[1]) { - return "field's type and default value's type mismatch", false - } - - continue - } - - return fmt.Sprintf("unknown option '%s' in ASN1 tag", opt), false - } - } - - return "", true -} - -func (w lintStructTagRule) checkBSONTag(options []string) (string, bool) { - for _, opt := range options { - switch opt { - case "inline", "minsize", "omitempty": - default: - return fmt.Sprintf("unknown option '%s' in BSON tag", opt), false - } - } - - return "", true -} - -func (w lintStructTagRule) checkJSONTag(name string, options []string) (string, bool) { - for _, opt := range options { - switch opt { - case "omitempty", "string": - case "": - // special case for JSON key "-" - if name != "-" { - return "option can not be empty in JSON tag", false - } - default: - return fmt.Sprintf("unknown option '%s' in JSON tag", opt), false - } - } - - return "", true -} - -func (w lintStructTagRule) checkXMLTag(options []string) (string, bool) { - for _, opt := range options { - switch opt { - case "any", "attr", "cdata", "chardata", "comment", "innerxml", "omitempty", "typeattr": - default: - return fmt.Sprintf("unknown option '%s' in XML tag", opt), false - } - } - - return "", true -} - -func (w lintStructTagRule) checkYAMLTag(options []string) (string, bool) { - for _, opt := range options { - switch opt { - case "flow", "inline", "omitempty": - default: - return fmt.Sprintf("unknown option '%s' in YAML tag", opt), false - } - } - - return "", true -} - -func (w lintStructTagRule) typeValueMatch(t ast.Expr, val string) bool { - tID, ok := t.(*ast.Ident) - if !ok { - return true - } - - typeMatches := true - switch tID.Name { - case "bool": - typeMatches = val == "true" || val == "false" - case "float64": - _, err := strconv.ParseFloat(val, 64) - typeMatches = err == nil - case "int": - _, err := strconv.ParseInt(val, 10, 64) - typeMatches = err == nil - case "string": - case "nil": - default: - // unchecked type - } - - return typeMatches -} - -func (w lintStructTagRule) addFailure(n ast.Node, msg string) { - w.onFailure(lint.Failure{ - Node: n, - Failure: msg, - Confidence: 1, - }) -} diff --git a/vendor/github.com/mgechev/revive/rule/superfluous-else.go b/vendor/github.com/mgechev/revive/rule/superfluous-else.go deleted file mode 100644 index c29be9e0d..000000000 --- a/vendor/github.com/mgechev/revive/rule/superfluous-else.go +++ /dev/null @@ -1,114 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "go/token" - - "github.com/mgechev/revive/lint" -) - -// SuperfluousElseRule lints given else constructs. -type SuperfluousElseRule struct{} - -// Apply applies the rule to given file. -func (r *SuperfluousElseRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - var branchingFunctions = map[string]map[string]bool{ - "os": map[string]bool{"Exit": true}, - "log": map[string]bool{ - "Fatal": true, - "Fatalf": true, - "Fatalln": true, - "Panic": true, - "Panicf": true, - "Panicln": true, - }, - } - - w := lintSuperfluousElse{make(map[*ast.IfStmt]bool), onFailure, branchingFunctions} - ast.Walk(w, file.AST) - return failures -} - -// Name returns the rule name. -func (r *SuperfluousElseRule) Name() string { - return "superfluous-else" -} - -type lintSuperfluousElse struct { - ignore map[*ast.IfStmt]bool - onFailure func(lint.Failure) - branchingFunctions map[string]map[string]bool -} - -func (w lintSuperfluousElse) Visit(node ast.Node) ast.Visitor { - ifStmt, ok := node.(*ast.IfStmt) - if !ok || ifStmt.Else == nil { - return w - } - if w.ignore[ifStmt] { - if elseif, ok := ifStmt.Else.(*ast.IfStmt); ok { - w.ignore[elseif] = true - } - return w - } - if elseif, ok := ifStmt.Else.(*ast.IfStmt); ok { - w.ignore[elseif] = true - return w - } - if _, ok := ifStmt.Else.(*ast.BlockStmt); !ok { - // only care about elses without conditions - return w - } - if len(ifStmt.Body.List) == 0 { - return w - } - shortDecl := false // does the if statement have a ":=" initialization statement? - if ifStmt.Init != nil { - if as, ok := ifStmt.Init.(*ast.AssignStmt); ok && as.Tok == token.DEFINE { - shortDecl = true - } - } - extra := "" - if shortDecl { - extra = " (move short variable declaration to its own line if necessary)" - } - - lastStmt := ifStmt.Body.List[len(ifStmt.Body.List)-1] - switch stmt := lastStmt.(type) { - case *ast.BranchStmt: - token := stmt.Tok.String() - if token != "fallthrough" { - w.onFailure(newFailure(ifStmt.Else, "if block ends with a "+token+" statement, so drop this else and outdent its block"+extra)) - } - case *ast.ExprStmt: - if ce, ok := stmt.X.(*ast.CallExpr); ok { // it's a function call - if fc, ok := ce.Fun.(*ast.SelectorExpr); ok { - if id, ok := fc.X.(*ast.Ident); ok { - fn := fc.Sel.Name - pkg := id.Name - if w.branchingFunctions[pkg][fn] { // it's a call to a branching function - w.onFailure( - newFailure(ifStmt.Else, fmt.Sprintf("if block ends with call to %s.%s function, so drop this else and outdent its block%s", pkg, fn, extra))) - } - } - } - } - } - - return w -} - -func newFailure(node ast.Node, msg string) lint.Failure { - return lint.Failure{ - Confidence: 1, - Node: node, - Category: "indent", - Failure: msg, - } -} diff --git a/vendor/github.com/mgechev/revive/rule/time-naming.go b/vendor/github.com/mgechev/revive/rule/time-naming.go deleted file mode 100644 index a93f4b5ae..000000000 --- a/vendor/github.com/mgechev/revive/rule/time-naming.go +++ /dev/null @@ -1,93 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "go/types" - "strings" - - "github.com/mgechev/revive/lint" -) - -// TimeNamingRule lints given else constructs. -type TimeNamingRule struct{} - -// Apply applies the rule to given file. -func (r *TimeNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - w := &lintTimeNames{file, onFailure} - - file.Pkg.TypeCheck() - ast.Walk(w, file.AST) - return failures -} - -// Name returns the rule name. -func (r *TimeNamingRule) Name() string { - return "time-naming" -} - -type lintTimeNames struct { - file *lint.File - onFailure func(lint.Failure) -} - -func (w *lintTimeNames) Visit(node ast.Node) ast.Visitor { - v, ok := node.(*ast.ValueSpec) - if !ok { - return w - } - for _, name := range v.Names { - origTyp := w.file.Pkg.TypeOf(name) - // Look for time.Duration or *time.Duration; - // the latter is common when using flag.Duration. - typ := origTyp - if pt, ok := typ.(*types.Pointer); ok { - typ = pt.Elem() - } - if !isNamedType(typ, "time", "Duration") { - continue - } - suffix := "" - for _, suf := range timeSuffixes { - if strings.HasSuffix(name.Name, suf) { - suffix = suf - break - } - } - if suffix == "" { - continue - } - w.onFailure(lint.Failure{ - Category: "time", - Confidence: 0.9, - Node: v, - Failure: fmt.Sprintf("var %s is of type %v; don't use unit-specific suffix %q", name.Name, origTyp, suffix), - }) - } - return w -} - -// timeSuffixes is a list of name suffixes that imply a time unit. -// This is not an exhaustive list. -var timeSuffixes = []string{ - "Sec", "Secs", "Seconds", - "Msec", "Msecs", - "Milli", "Millis", "Milliseconds", - "Usec", "Usecs", "Microseconds", - "MS", "Ms", -} - -func isNamedType(typ types.Type, importPath, name string) bool { - n, ok := typ.(*types.Named) - if !ok { - return false - } - tn := n.Obj() - return tn != nil && tn.Pkg() != nil && tn.Pkg().Path() == importPath && tn.Name() == name -} diff --git a/vendor/github.com/mgechev/revive/rule/unconditional-recursion.go b/vendor/github.com/mgechev/revive/rule/unconditional-recursion.go deleted file mode 100644 index c06626b5a..000000000 --- a/vendor/github.com/mgechev/revive/rule/unconditional-recursion.go +++ /dev/null @@ -1,183 +0,0 @@ -package rule - -import ( - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// UnconditionalRecursionRule lints given else constructs. -type UnconditionalRecursionRule struct{} - -// Apply applies the rule to given file. -func (r *UnconditionalRecursionRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - w := lintUnconditionalRecursionRule{onFailure: onFailure} - ast.Walk(w, file.AST) - return failures -} - -// Name returns the rule name. -func (r *UnconditionalRecursionRule) Name() string { - return "unconditional-recursion" -} - -type funcDesc struct { - reciverID *ast.Ident - id *ast.Ident -} - -func (fd *funcDesc) equal(other *funcDesc) bool { - receiversAreEqual := (fd.reciverID == nil && other.reciverID == nil) || fd.reciverID != nil && other.reciverID != nil && fd.reciverID.Name == other.reciverID.Name - idsAreEqual := (fd.id == nil && other.id == nil) || fd.id.Name == other.id.Name - - return receiversAreEqual && idsAreEqual -} - -type funcStatus struct { - funcDesc *funcDesc - seenConditionalExit bool -} - -type lintUnconditionalRecursionRule struct { - onFailure func(lint.Failure) - currentFunc *funcStatus -} - -// Visit will traverse the file AST. -// The rule is based in the following algorithm: inside each function body we search for calls to the function itself. -// We do not search inside conditional control structures (if, for, switch, ...) because any recursive call inside them is conditioned -// We do search inside conditional control structures are statements that will take the control out of the function (return, exit, panic) -// If we find conditional control exits, it means the function is NOT unconditionally-recursive -// If we find a recursive call before finding any conditional exit, a failure is generated -// In resume: if we found a recursive call control-dependant from the entry point of the function then we raise a failure. -func (w lintUnconditionalRecursionRule) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.FuncDecl: - var rec *ast.Ident - switch { - case n.Recv == nil || n.Recv.NumFields() < 1 || len(n.Recv.List[0].Names) < 1: - rec = nil - default: - rec = n.Recv.List[0].Names[0] - } - - w.currentFunc = &funcStatus{&funcDesc{rec, n.Name}, false} - case *ast.CallExpr: - var funcID *ast.Ident - var selector *ast.Ident - switch c := n.Fun.(type) { - case *ast.Ident: - selector = nil - funcID = c - case *ast.SelectorExpr: - var ok bool - selector, ok = c.X.(*ast.Ident) - if !ok { // a.b....Foo() - return nil - } - funcID = c.Sel - default: - return w - } - - if w.currentFunc != nil && // not in a func body - !w.currentFunc.seenConditionalExit && // there is a conditional exit in the function - w.currentFunc.funcDesc.equal(&funcDesc{selector, funcID}) { - w.onFailure(lint.Failure{ - Category: "logic", - Confidence: 1, - Node: n, - Failure: "unconditional recursive call", - }) - } - case *ast.IfStmt: - w.updateFuncStatus(n.Body) - w.updateFuncStatus(n.Else) - return nil - case *ast.SelectStmt: - w.updateFuncStatus(n.Body) - return nil - case *ast.RangeStmt: - w.updateFuncStatus(n.Body) - return nil - case *ast.TypeSwitchStmt: - w.updateFuncStatus(n.Body) - return nil - case *ast.SwitchStmt: - w.updateFuncStatus(n.Body) - return nil - case *ast.GoStmt: - for _, a := range n.Call.Args { - ast.Walk(w, a) // check if arguments have a recursive call - } - return nil // recursive async call is not an issue - case *ast.ForStmt: - if n.Cond != nil { - return nil - } - // unconditional loop - return w - } - - return w -} - -func (w *lintUnconditionalRecursionRule) updateFuncStatus(node ast.Node) { - if node == nil || w.currentFunc == nil || w.currentFunc.seenConditionalExit { - return - } - - w.currentFunc.seenConditionalExit = w.hasControlExit(node) -} - -var exitFunctions = map[string]map[string]bool{ - "os": map[string]bool{"Exit": true}, - "syscall": map[string]bool{"Exit": true}, - "log": map[string]bool{ - "Fatal": true, - "Fatalf": true, - "Fatalln": true, - "Panic": true, - "Panicf": true, - "Panicln": true, - }, -} - -func (w *lintUnconditionalRecursionRule) hasControlExit(node ast.Node) bool { - // isExit returns true if the given node makes control exit the function - isExit := func(node ast.Node) bool { - switch n := node.(type) { - case *ast.ReturnStmt: - return true - case *ast.CallExpr: - if isIdent(n.Fun, "panic") { - return true - } - se, ok := n.Fun.(*ast.SelectorExpr) - if !ok { - return false - } - - id, ok := se.X.(*ast.Ident) - if !ok { - return false - } - - fn := se.Sel.Name - pkg := id.Name - if exitFunctions[pkg] != nil && exitFunctions[pkg][fn] { // it's a call to an exit function - return true - } - } - - return false - } - - return len(pick(node, isExit, nil)) != 0 -} diff --git a/vendor/github.com/mgechev/revive/rule/unexported-naming.go b/vendor/github.com/mgechev/revive/rule/unexported-naming.go deleted file mode 100644 index 96cec3e46..000000000 --- a/vendor/github.com/mgechev/revive/rule/unexported-naming.go +++ /dev/null @@ -1,115 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "go/token" - - "github.com/mgechev/revive/lint" -) - -// UnexportedNamingRule lints wrongly named unexported symbols. -type UnexportedNamingRule struct{} - -// Apply applies the rule to given file. -func (r *UnexportedNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - ba := &unexportablenamingLinter{onFailure} - ast.Walk(ba, file.AST) - - return failures -} - -// Name returns the rule name. -func (r *UnexportedNamingRule) Name() string { - return "unexported-naming" -} - -type unexportablenamingLinter struct { - onFailure func(lint.Failure) -} - -func (unl unexportablenamingLinter) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.FuncDecl: - unl.lintFunction(n.Type, n.Body) - return nil - case *ast.FuncLit: - unl.lintFunction(n.Type, n.Body) - - return nil - case *ast.AssignStmt: - if n.Tok != token.DEFINE { - return nil - } - - ids := []*ast.Ident{} - for _, e := range n.Lhs { - id, ok := e.(*ast.Ident) - if !ok { - continue - } - ids = append(ids, id) - } - - unl.lintIDs(ids) - - case *ast.DeclStmt: - gd, ok := n.Decl.(*ast.GenDecl) - if !ok { - return nil - } - - if len(gd.Specs) < 1 { - return nil - } - - vs, ok := gd.Specs[0].(*ast.ValueSpec) - if !ok { - return nil - } - - unl.lintIDs(vs.Names) - } - - return unl -} - -func (unl unexportablenamingLinter) lintFunction(ft *ast.FuncType, body *ast.BlockStmt) { - unl.lintFields(ft.Params) - unl.lintFields(ft.Results) - - if body != nil { - ast.Walk(unl, body) - } -} - -func (unl unexportablenamingLinter) lintFields(fields *ast.FieldList) { - if fields == nil { - return - } - - ids := []*ast.Ident{} - for _, field := range fields.List { - ids = append(ids, field.Names...) - } - - unl.lintIDs(ids) -} - -func (unl unexportablenamingLinter) lintIDs(ids []*ast.Ident) { - for _, id := range ids { - if id.IsExported() { - unl.onFailure(lint.Failure{ - Node: id, - Confidence: 1, - Category: "naming", - Failure: fmt.Sprintf("the symbol %s is local, its name should start with a lowercase letter", id.String()), - }) - } - } -} diff --git a/vendor/github.com/mgechev/revive/rule/unexported-return.go b/vendor/github.com/mgechev/revive/rule/unexported-return.go deleted file mode 100644 index c9c8a41d3..000000000 --- a/vendor/github.com/mgechev/revive/rule/unexported-return.go +++ /dev/null @@ -1,106 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "go/types" - - "github.com/mgechev/revive/lint" -) - -// UnexportedReturnRule lints given else constructs. -type UnexportedReturnRule struct{} - -// Apply applies the rule to given file. -func (r *UnexportedReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - fileAst := file.AST - walker := lintUnexportedReturn{ - file: file, - fileAst: fileAst, - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - file.Pkg.TypeCheck() - ast.Walk(walker, fileAst) - - return failures -} - -// Name returns the rule name. -func (r *UnexportedReturnRule) Name() string { - return "unexported-return" -} - -type lintUnexportedReturn struct { - file *lint.File - fileAst *ast.File - onFailure func(lint.Failure) -} - -func (w lintUnexportedReturn) Visit(n ast.Node) ast.Visitor { - fn, ok := n.(*ast.FuncDecl) - if !ok { - return w - } - if fn.Type.Results == nil { - return nil - } - if !fn.Name.IsExported() { - return nil - } - thing := "func" - if fn.Recv != nil && len(fn.Recv.List) > 0 { - thing = "method" - if !ast.IsExported(receiverType(fn)) { - // Don't report exported methods of unexported types, - // such as private implementations of sort.Interface. - return nil - } - } - for _, ret := range fn.Type.Results.List { - typ := w.file.Pkg.TypeOf(ret.Type) - if exportedType(typ) { - continue - } - w.onFailure(lint.Failure{ - Category: "unexported-type-in-api", - Node: ret.Type, - Confidence: 0.8, - Failure: fmt.Sprintf("exported %s %s returns unexported type %s, which can be annoying to use", - thing, fn.Name.Name, typ), - }) - break // only flag one - } - return nil -} - -// exportedType reports whether typ is an exported type. -// It is imprecise, and will err on the side of returning true, -// such as for composite types. -func exportedType(typ types.Type) bool { - switch T := typ.(type) { - case *types.Named: - obj := T.Obj() - switch { - // Builtin types have no package. - case obj.Pkg() == nil: - case obj.Exported(): - default: - _, ok := T.Underlying().(*types.Interface) - return ok - } - return true - case *types.Map: - return exportedType(T.Key()) && exportedType(T.Elem()) - case interface { - Elem() types.Type - }: // array, slice, pointer, chan - return exportedType(T.Elem()) - } - // Be conservative about other types, such as struct, interface, etc. - return true -} diff --git a/vendor/github.com/mgechev/revive/rule/unhandled-error.go b/vendor/github.com/mgechev/revive/rule/unhandled-error.go deleted file mode 100644 index 0e2f62875..000000000 --- a/vendor/github.com/mgechev/revive/rule/unhandled-error.go +++ /dev/null @@ -1,120 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "go/types" - - "github.com/mgechev/revive/lint" -) - -// UnhandledErrorRule lints given else constructs. -type UnhandledErrorRule struct{} - -type ignoreListType map[string]struct{} - -// Apply applies the rule to given file. -func (r *UnhandledErrorRule) Apply(file *lint.File, args lint.Arguments) []lint.Failure { - var failures []lint.Failure - - ignoreList := make(ignoreListType, len(args)) - - for _, arg := range args { - argStr, ok := arg.(string) - if !ok { - panic(fmt.Sprintf("Invalid argument to the unhandled-error rule. Expecting a string, got %T", arg)) - } - - ignoreList[argStr] = struct{}{} - } - - walker := &lintUnhandledErrors{ - ignoreList: ignoreList, - pkg: file.Pkg, - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - file.Pkg.TypeCheck() - ast.Walk(walker, file.AST) - - return failures -} - -// Name returns the rule name. -func (r *UnhandledErrorRule) Name() string { - return "unhandled-error" -} - -type lintUnhandledErrors struct { - ignoreList ignoreListType - pkg *lint.Package - onFailure func(lint.Failure) -} - -// Visit looks for statements that are function calls. -// If the called function returns a value of type error a failure will be created. -func (w *lintUnhandledErrors) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.ExprStmt: - fCall, ok := n.X.(*ast.CallExpr) - if !ok { - return nil // not a function call - } - - funcType := w.pkg.TypeOf(fCall) - if funcType == nil { - return nil // skip, type info not available - } - - switch t := funcType.(type) { - case *types.Named: - if !w.isTypeError(t) { - return nil // func call does not return an error - } - - w.addFailure(fCall) - default: - retTypes, ok := funcType.Underlying().(*types.Tuple) - if !ok { - return nil // skip, unable to retrieve return type of the called function - } - - if w.returnsAnError(retTypes) { - w.addFailure(fCall) - } - } - } - return w -} - -func (w *lintUnhandledErrors) addFailure(n *ast.CallExpr) { - funcName := gofmt(n.Fun) - if _, mustIgnore := w.ignoreList[funcName]; mustIgnore { - return - } - - w.onFailure(lint.Failure{ - Category: "bad practice", - Confidence: 1, - Node: n, - Failure: fmt.Sprintf("Unhandled error in call to function %v", funcName), - }) -} - -func (*lintUnhandledErrors) isTypeError(t *types.Named) bool { - const errorTypeName = "_.error" - - return t.Obj().Id() == errorTypeName -} - -func (w *lintUnhandledErrors) returnsAnError(tt *types.Tuple) bool { - for i := 0; i < tt.Len(); i++ { - nt, ok := tt.At(i).Type().(*types.Named) - if ok && w.isTypeError(nt) { - return true - } - } - return false -} diff --git a/vendor/github.com/mgechev/revive/rule/unnecessary-stmt.go b/vendor/github.com/mgechev/revive/rule/unnecessary-stmt.go deleted file mode 100644 index 732d8a8bb..000000000 --- a/vendor/github.com/mgechev/revive/rule/unnecessary-stmt.go +++ /dev/null @@ -1,107 +0,0 @@ -package rule - -import ( - "go/ast" - "go/token" - - "github.com/mgechev/revive/lint" -) - -// UnnecessaryStmtRule warns on unnecessary statements. -type UnnecessaryStmtRule struct{} - -// Apply applies the rule to given file. -func (r *UnnecessaryStmtRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - w := lintUnnecessaryStmtRule{onFailure} - ast.Walk(w, file.AST) - return failures -} - -// Name returns the rule name. -func (r *UnnecessaryStmtRule) Name() string { - return "unnecessary-stmt" -} - -type lintUnnecessaryStmtRule struct { - onFailure func(lint.Failure) -} - -func (w lintUnnecessaryStmtRule) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.FuncDecl: - if n.Body == nil || n.Type.Results != nil { - return w - } - stmts := n.Body.List - if len(stmts) == 0 { - return w - } - - lastStmt := stmts[len(stmts)-1] - rs, ok := lastStmt.(*ast.ReturnStmt) - if !ok { - return w - } - - if len(rs.Results) == 0 { - w.newFailure(lastStmt, "omit unnecessary return statement") - } - - case *ast.SwitchStmt: - w.checkSwitchBody(n.Body) - case *ast.TypeSwitchStmt: - w.checkSwitchBody(n.Body) - case *ast.CaseClause: - if n.Body == nil { - return w - } - stmts := n.Body - if len(stmts) == 0 { - return w - } - - lastStmt := stmts[len(stmts)-1] - rs, ok := lastStmt.(*ast.BranchStmt) - if !ok { - return w - } - - if rs.Tok == token.BREAK && rs.Label == nil { - w.newFailure(lastStmt, "omit unnecessary break at the end of case clause") - } - } - - return w -} - -func (w lintUnnecessaryStmtRule) checkSwitchBody(b *ast.BlockStmt) { - cases := b.List - if len(cases) != 1 { - return - } - - cc, ok := cases[0].(*ast.CaseClause) - if !ok { - return - } - - if len(cc.List) > 1 { // skip cases with multiple expressions - return - } - - w.newFailure(b, "switch with only one case can be replaced by an if-then") -} - -func (w lintUnnecessaryStmtRule) newFailure(node ast.Node, msg string) { - w.onFailure(lint.Failure{ - Confidence: 1, - Node: node, - Category: "style", - Failure: msg, - }) -} diff --git a/vendor/github.com/mgechev/revive/rule/unreachable-code.go b/vendor/github.com/mgechev/revive/rule/unreachable-code.go deleted file mode 100644 index c81e9e733..000000000 --- a/vendor/github.com/mgechev/revive/rule/unreachable-code.go +++ /dev/null @@ -1,114 +0,0 @@ -package rule - -import ( - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// UnreachableCodeRule lints unreachable code. -type UnreachableCodeRule struct{} - -// Apply applies the rule to given file. -func (r *UnreachableCodeRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - var branchingFunctions = map[string]map[string]bool{ - "os": map[string]bool{"Exit": true}, - "log": map[string]bool{ - "Fatal": true, - "Fatalf": true, - "Fatalln": true, - "Panic": true, - "Panicf": true, - "Panicln": true, - }, - } - - w := lintUnreachableCode{onFailure, branchingFunctions} - ast.Walk(w, file.AST) - return failures -} - -// Name returns the rule name. -func (r *UnreachableCodeRule) Name() string { - return "unreachable-code" -} - -type lintUnreachableCode struct { - onFailure func(lint.Failure) - branchingFunctions map[string]map[string]bool -} - -func (w lintUnreachableCode) Visit(node ast.Node) ast.Visitor { - blk, ok := node.(*ast.BlockStmt) - if !ok { - return w - } - - if len(blk.List) < 2 { - return w - } -loop: - for i, stmt := range blk.List[:len(blk.List)-1] { - // println("iterating ", len(blk.List)) - next := blk.List[i+1] - if _, ok := next.(*ast.LabeledStmt); ok { - continue // skip if next statement is labeled - } - - switch s := stmt.(type) { - case *ast.ReturnStmt: - w.onFailure(newUnreachableCodeFailure(s)) - break loop - case *ast.BranchStmt: - token := s.Tok.String() - if token != "fallthrough" { - w.onFailure(newUnreachableCodeFailure(s)) - break loop - } - case *ast.ExprStmt: - ce, ok := s.X.(*ast.CallExpr) - if !ok { - continue - } - // it's a function call - fc, ok := ce.Fun.(*ast.SelectorExpr) - if !ok { - continue - } - - id, ok := fc.X.(*ast.Ident) - - if !ok { - continue - } - fn := fc.Sel.Name - pkg := id.Name - if !w.branchingFunctions[pkg][fn] { // it isn't a call to a branching function - continue - } - - if _, ok := next.(*ast.ReturnStmt); ok { // return statement needed to satisfy function signature - continue - } - - w.onFailure(newUnreachableCodeFailure(s)) - break loop - } - } - - return w -} - -func newUnreachableCodeFailure(node ast.Node) lint.Failure { - return lint.Failure{ - Confidence: 1, - Node: node, - Category: "logic", - Failure: "unreachable code after this statement", - } -} diff --git a/vendor/github.com/mgechev/revive/rule/unused-param.go b/vendor/github.com/mgechev/revive/rule/unused-param.go deleted file mode 100644 index 60df908d3..000000000 --- a/vendor/github.com/mgechev/revive/rule/unused-param.go +++ /dev/null @@ -1,102 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// UnusedParamRule lints unused params in functions. -type UnusedParamRule struct{} - -// Apply applies the rule to given file. -func (r *UnusedParamRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - w := lintUnusedParamRule{onFailure: onFailure} - - ast.Walk(w, file.AST) - - return failures -} - -// Name returns the rule name. -func (r *UnusedParamRule) Name() string { - return "unused-parameter" -} - -type lintUnusedParamRule struct { - onFailure func(lint.Failure) -} - -func (w lintUnusedParamRule) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.FuncDecl: - params := retrieveNamedParams(n.Type.Params) - if len(params) < 1 { - return nil // skip, func without parameters - } - - if n.Body == nil { - return nil // skip, is a function prototype - } - - // inspect the func body looking for references to parameters - fselect := func(n ast.Node) bool { - ident, isAnID := n.(*ast.Ident) - - if !isAnID { - return false - } - - _, isAParam := params[ident.Obj] - if isAParam { - params[ident.Obj] = false // mark as used - } - - return false - } - _ = pick(n.Body, fselect, nil) - - for _, p := range n.Type.Params.List { - for _, n := range p.Names { - if params[n.Obj] { - w.onFailure(lint.Failure{ - Confidence: 1, - Node: n, - Category: "bad practice", - Failure: fmt.Sprintf("parameter '%s' seems to be unused, consider removing or renaming it as _", n.Name), - }) - } - } - } - - return nil // full method body already inspected - } - - return w -} - -func retrieveNamedParams(params *ast.FieldList) map[*ast.Object]bool { - result := map[*ast.Object]bool{} - if params.List == nil { - return result - } - - for _, p := range params.List { - for _, n := range p.Names { - if n.Name == "_" { - continue - } - - result[n.Obj] = true - } - } - - return result -} diff --git a/vendor/github.com/mgechev/revive/rule/unused-receiver.go b/vendor/github.com/mgechev/revive/rule/unused-receiver.go deleted file mode 100644 index 2289a517e..000000000 --- a/vendor/github.com/mgechev/revive/rule/unused-receiver.go +++ /dev/null @@ -1,77 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// UnusedReceiverRule lints unused params in functions. -type UnusedReceiverRule struct{} - -// Apply applies the rule to given file. -func (*UnusedReceiverRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - w := lintUnusedReceiverRule{onFailure: onFailure} - - ast.Walk(w, file.AST) - - return failures -} - -// Name returns the rule name. -func (*UnusedReceiverRule) Name() string { - return "unused-receiver" -} - -type lintUnusedReceiverRule struct { - onFailure func(lint.Failure) -} - -func (w lintUnusedReceiverRule) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.FuncDecl: - if n.Recv == nil { - return nil // skip this func decl, not a method - } - - rec := n.Recv.List[0] // safe to access only the first (unique) element of the list - if len(rec.Names) < 1 { - return nil // the receiver is anonymous: func (aType) Foo(...) ... - } - - recID := rec.Names[0] - if recID.Name == "_" { - return nil // the receiver is already named _ - } - - // inspect the func body looking for references to the receiver id - fselect := func(n ast.Node) bool { - ident, isAnID := n.(*ast.Ident) - - return isAnID && ident.Obj == recID.Obj - } - refs2recID := pick(n.Body, fselect, nil) - - if len(refs2recID) > 0 { - return nil // the receiver is referenced in the func body - } - - w.onFailure(lint.Failure{ - Confidence: 1, - Node: recID, - Category: "bad practice", - Failure: fmt.Sprintf("method receiver '%s' is not referenced in method's body, consider removing or renaming it as _", recID.Name), - }) - - return nil // full method body already inspected - } - - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/utils.go b/vendor/github.com/mgechev/revive/rule/utils.go deleted file mode 100644 index 38677c839..000000000 --- a/vendor/github.com/mgechev/revive/rule/utils.go +++ /dev/null @@ -1,191 +0,0 @@ -package rule - -import ( - "bytes" - "fmt" - "go/ast" - "go/printer" - "go/token" - "go/types" - "regexp" - "strings" - - "github.com/mgechev/revive/lint" -) - -const styleGuideBase = "https://golang.org/wiki/CodeReviewComments" - -// isBlank returns whether id is the blank identifier "_". -// If id == nil, the answer is false. -func isBlank(id *ast.Ident) bool { return id != nil && id.Name == "_" } - -func isTest(f *lint.File) bool { - return strings.HasSuffix(f.Name, "_test.go") -} - -var commonMethods = map[string]bool{ - "Error": true, - "Read": true, - "ServeHTTP": true, - "String": true, - "Write": true, -} - -func receiverType(fn *ast.FuncDecl) string { - switch e := fn.Recv.List[0].Type.(type) { - case *ast.Ident: - return e.Name - case *ast.StarExpr: - if id, ok := e.X.(*ast.Ident); ok { - return id.Name - } - } - // The parser accepts much more than just the legal forms. - return "invalid-type" -} - -var knownNameExceptions = map[string]bool{ - "LastInsertId": true, // must match database/sql - "kWh": true, -} - -func isCgoExported(f *ast.FuncDecl) bool { - if f.Recv != nil || f.Doc == nil { - return false - } - - cgoExport := regexp.MustCompile(fmt.Sprintf("(?m)^//export %s$", regexp.QuoteMeta(f.Name.Name))) - for _, c := range f.Doc.List { - if cgoExport.MatchString(c.Text) { - return true - } - } - return false -} - -var allCapsRE = regexp.MustCompile(`^[A-Z0-9_]+$`) - -func isIdent(expr ast.Expr, ident string) bool { - id, ok := expr.(*ast.Ident) - return ok && id.Name == ident -} - -var zeroLiteral = map[string]bool{ - "false": true, // bool - // runes - `'\x00'`: true, - `'\000'`: true, - // strings - `""`: true, - "``": true, - // numerics - "0": true, - "0.": true, - "0.0": true, - "0i": true, -} - -func validType(T types.Type) bool { - return T != nil && - T != types.Typ[types.Invalid] && - !strings.Contains(T.String(), "invalid type") // good but not foolproof -} - -func isPkgDot(expr ast.Expr, pkg, name string) bool { - sel, ok := expr.(*ast.SelectorExpr) - return ok && isIdent(sel.X, pkg) && isIdent(sel.Sel, name) -} - -func srcLine(src []byte, p token.Position) string { - // Run to end of line in both directions if not at line start/end. - lo, hi := p.Offset, p.Offset+1 - for lo > 0 && src[lo-1] != '\n' { - lo-- - } - for hi < len(src) && src[hi-1] != '\n' { - hi++ - } - return string(src[lo:hi]) -} - -// pick yields a list of nodes by picking them from a sub-ast with root node n. -// Nodes are selected by applying the fselect function -// f function is applied to each selected node before inseting it in the final result. -// If f==nil then it defaults to the identity function (ie it returns the node itself) -func pick(n ast.Node, fselect func(n ast.Node) bool, f func(n ast.Node) []ast.Node) []ast.Node { - var result []ast.Node - - if n == nil { - return result - } - - if f == nil { - f = func(n ast.Node) []ast.Node { return []ast.Node{n} } - } - - onSelect := func(n ast.Node) { - result = append(result, f(n)...) - } - p := picker{fselect: fselect, onSelect: onSelect} - ast.Walk(p, n) - return result -} - -func pickFromExpList(l []ast.Expr, fselect func(n ast.Node) bool, f func(n ast.Node) []ast.Node) []ast.Node { - result := make([]ast.Node, 0) - for _, e := range l { - result = append(result, pick(e, fselect, f)...) - } - return result -} - -type picker struct { - fselect func(n ast.Node) bool - onSelect func(n ast.Node) -} - -func (p picker) Visit(node ast.Node) ast.Visitor { - if p.fselect == nil { - return nil - } - - if p.fselect(node) { - p.onSelect(node) - } - - return p -} - -// isBoolOp returns true if the given token corresponds to -// a bool operator -func isBoolOp(t token.Token) bool { - switch t { - case token.LAND, token.LOR, token.EQL, token.NEQ: - return true - } - - return false -} - -const ( - trueName = "true" - falseName = "false" -) - -func isExprABooleanLit(n ast.Node) (lexeme string, ok bool) { - oper, ok := n.(*ast.Ident) - - if !ok { - return "", false - } - - return oper.Name, (oper.Name == trueName || oper.Name == falseName) -} - -// gofmt returns a string representation of an AST subtree. -func gofmt(x interface{}) string { - buf := bytes.Buffer{} - fs := token.NewFileSet() - printer.Fprint(&buf, fs, x) - return buf.String() -} diff --git a/vendor/github.com/mgechev/revive/rule/var-declarations.go b/vendor/github.com/mgechev/revive/rule/var-declarations.go deleted file mode 100644 index 441132115..000000000 --- a/vendor/github.com/mgechev/revive/rule/var-declarations.go +++ /dev/null @@ -1,120 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "go/token" - "go/types" - - "github.com/mgechev/revive/lint" -) - -// VarDeclarationsRule lints given else constructs. -type VarDeclarationsRule struct{} - -// Apply applies the rule to given file. -func (r *VarDeclarationsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - fileAst := file.AST - walker := &lintVarDeclarations{ - file: file, - fileAst: fileAst, - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - file.Pkg.TypeCheck() - ast.Walk(walker, fileAst) - - return failures -} - -// Name returns the rule name. -func (r *VarDeclarationsRule) Name() string { - return "var-declaration" -} - -type lintVarDeclarations struct { - fileAst *ast.File - file *lint.File - lastGen *ast.GenDecl - onFailure func(lint.Failure) -} - -func (w *lintVarDeclarations) Visit(node ast.Node) ast.Visitor { - switch v := node.(type) { - case *ast.GenDecl: - if v.Tok != token.CONST && v.Tok != token.VAR { - return nil - } - w.lastGen = v - return w - case *ast.ValueSpec: - if w.lastGen.Tok == token.CONST { - return nil - } - if len(v.Names) > 1 || v.Type == nil || len(v.Values) == 0 { - return nil - } - rhs := v.Values[0] - // An underscore var appears in a common idiom for compile-time interface satisfaction, - // as in "var _ Interface = (*Concrete)(nil)". - if isIdent(v.Names[0], "_") { - return nil - } - // If the RHS is a zero value, suggest dropping it. - zero := false - if lit, ok := rhs.(*ast.BasicLit); ok { - zero = zeroLiteral[lit.Value] - } else if isIdent(rhs, "nil") { - zero = true - } - if zero { - w.onFailure(lint.Failure{ - Confidence: 0.9, - Node: rhs, - Category: "zero-value", - Failure: fmt.Sprintf("should drop = %s from declaration of var %s; it is the zero value", w.file.Render(rhs), v.Names[0]), - }) - return nil - } - lhsTyp := w.file.Pkg.TypeOf(v.Type) - rhsTyp := w.file.Pkg.TypeOf(rhs) - - if !validType(lhsTyp) || !validType(rhsTyp) { - // Type checking failed (often due to missing imports). - return nil - } - - if !types.Identical(lhsTyp, rhsTyp) { - // Assignment to a different type is not redundant. - return nil - } - - // The next three conditions are for suppressing the warning in situations - // where we were unable to typecheck. - - // If the LHS type is an interface, don't warn, since it is probably a - // concrete type on the RHS. Note that our feeble lexical check here - // will only pick up interface{} and other literal interface types; - // that covers most of the cases we care to exclude right now. - if _, ok := v.Type.(*ast.InterfaceType); ok { - return nil - } - // If the RHS is an untyped const, only warn if the LHS type is its default type. - if defType, ok := w.file.IsUntypedConst(rhs); ok && !isIdent(v.Type, defType) { - return nil - } - - w.onFailure(lint.Failure{ - Category: "type-inference", - Confidence: 0.8, - Node: v.Type, - Failure: fmt.Sprintf("should omit type %s from declaration of var %s; it will be inferred from the right-hand side", w.file.Render(v.Type), v.Names[0]), - }) - return nil - } - return w -} diff --git a/vendor/github.com/mgechev/revive/rule/var-naming.go b/vendor/github.com/mgechev/revive/rule/var-naming.go deleted file mode 100644 index 768f65b96..000000000 --- a/vendor/github.com/mgechev/revive/rule/var-naming.go +++ /dev/null @@ -1,230 +0,0 @@ -package rule - -import ( - "fmt" - "go/ast" - "go/token" - "strings" - - "github.com/mgechev/revive/lint" -) - -// VarNamingRule lints given else constructs. -type VarNamingRule struct{} - -// Apply applies the rule to given file. -func (r *VarNamingRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { - var failures []lint.Failure - - var whitelist []string - var blacklist []string - - if len(arguments) >= 1 { - whitelist = getList(arguments[0], "whitelist") - } - - if len(arguments) >= 2 { - blacklist = getList(arguments[1], "blacklist") - } - - fileAst := file.AST - walker := lintNames{ - file: file, - fileAst: fileAst, - whitelist: whitelist, - blacklist: blacklist, - onFailure: func(failure lint.Failure) { - failures = append(failures, failure) - }, - } - - // Package names need slightly different handling than other names. - if strings.Contains(walker.fileAst.Name.Name, "_") && !strings.HasSuffix(walker.fileAst.Name.Name, "_test") { - walker.onFailure(lint.Failure{ - Failure: "don't use an underscore in package name", - Confidence: 1, - Node: walker.fileAst, - Category: "naming", - }) - } - - ast.Walk(&walker, fileAst) - - return failures -} - -// Name returns the rule name. -func (r *VarNamingRule) Name() string { - return "var-naming" -} - -func checkList(fl *ast.FieldList, thing string, w *lintNames) { - if fl == nil { - return - } - for _, f := range fl.List { - for _, id := range f.Names { - check(id, thing, w) - } - } -} - -func check(id *ast.Ident, thing string, w *lintNames) { - if id.Name == "_" { - return - } - if knownNameExceptions[id.Name] { - return - } - - // Handle two common styles from other languages that don't belong in Go. - if len(id.Name) >= 5 && allCapsRE.MatchString(id.Name) && strings.Contains(id.Name, "_") { - w.onFailure(lint.Failure{ - Failure: "don't use ALL_CAPS in Go names; use CamelCase", - Confidence: 0.8, - Node: id, - Category: "naming", - }) - return - } - if len(id.Name) > 2 && id.Name[0] == 'k' && id.Name[1] >= 'A' && id.Name[1] <= 'Z' { - should := string(id.Name[1]+'a'-'A') + id.Name[2:] - w.onFailure(lint.Failure{ - Failure: fmt.Sprintf("don't use leading k in Go names; %s %s should be %s", thing, id.Name, should), - Confidence: 0.8, - Node: id, - Category: "naming", - }) - } - - should := lint.Name(id.Name, w.whitelist, w.blacklist) - if id.Name == should { - return - } - - if len(id.Name) > 2 && strings.Contains(id.Name[1:], "_") { - w.onFailure(lint.Failure{ - Failure: fmt.Sprintf("don't use underscores in Go names; %s %s should be %s", thing, id.Name, should), - Confidence: 0.9, - Node: id, - Category: "naming", - }) - return - } - w.onFailure(lint.Failure{ - Failure: fmt.Sprintf("%s %s should be %s", thing, id.Name, should), - Confidence: 0.8, - Node: id, - Category: "naming", - }) -} - -type lintNames struct { - file *lint.File - fileAst *ast.File - lastGen *ast.GenDecl - genDeclMissingComments map[*ast.GenDecl]bool - onFailure func(lint.Failure) - whitelist []string - blacklist []string -} - -func (w *lintNames) Visit(n ast.Node) ast.Visitor { - switch v := n.(type) { - case *ast.AssignStmt: - if v.Tok == token.ASSIGN { - return w - } - for _, exp := range v.Lhs { - if id, ok := exp.(*ast.Ident); ok { - check(id, "var", w) - } - } - case *ast.FuncDecl: - if w.file.IsTest() && (strings.HasPrefix(v.Name.Name, "Example") || strings.HasPrefix(v.Name.Name, "Test") || strings.HasPrefix(v.Name.Name, "Benchmark")) { - return w - } - - thing := "func" - if v.Recv != nil { - thing = "method" - } - - // Exclude naming warnings for functions that are exported to C but - // not exported in the Go API. - // See https://github.com/golang/lint/issues/144. - if ast.IsExported(v.Name.Name) || !isCgoExported(v) { - check(v.Name, thing, w) - } - - checkList(v.Type.Params, thing+" parameter", w) - checkList(v.Type.Results, thing+" result", w) - case *ast.GenDecl: - if v.Tok == token.IMPORT { - return w - } - var thing string - switch v.Tok { - case token.CONST: - thing = "const" - case token.TYPE: - thing = "type" - case token.VAR: - thing = "var" - } - for _, spec := range v.Specs { - switch s := spec.(type) { - case *ast.TypeSpec: - check(s.Name, thing, w) - case *ast.ValueSpec: - for _, id := range s.Names { - check(id, thing, w) - } - } - } - case *ast.InterfaceType: - // Do not check interface method names. - // They are often constrainted by the method names of concrete types. - for _, x := range v.Methods.List { - ft, ok := x.Type.(*ast.FuncType) - if !ok { // might be an embedded interface name - continue - } - checkList(ft.Params, "interface method parameter", w) - checkList(ft.Results, "interface method result", w) - } - case *ast.RangeStmt: - if v.Tok == token.ASSIGN { - return w - } - if id, ok := v.Key.(*ast.Ident); ok { - check(id, "range var", w) - } - if id, ok := v.Value.(*ast.Ident); ok { - check(id, "range var", w) - } - case *ast.StructType: - for _, f := range v.Fields.List { - for _, id := range f.Names { - check(id, "struct field", w) - } - } - } - return w -} - -func getList(arg interface{}, argName string) []string { - temp, ok := arg.([]interface{}) - if !ok { - panic(fmt.Sprintf("Invalid argument to the var-naming rule. Expecting a %s of type slice with initialisms, got %T", argName, arg)) - } - var list []string - for _, v := range temp { - if val, ok := v.(string); ok { - list = append(list, val) - } else { - panic(fmt.Sprintf("Invalid %s values of the var-naming rule. Expecting slice of strings but got element of type %T", val, arg)) - } - } - return list -} diff --git a/vendor/github.com/mgechev/revive/rule/waitgroup-by-value.go b/vendor/github.com/mgechev/revive/rule/waitgroup-by-value.go deleted file mode 100644 index b86929136..000000000 --- a/vendor/github.com/mgechev/revive/rule/waitgroup-by-value.go +++ /dev/null @@ -1,66 +0,0 @@ -package rule - -import ( - "go/ast" - - "github.com/mgechev/revive/lint" -) - -// WaitGroupByValueRule lints sync.WaitGroup passed by copy in functions. -type WaitGroupByValueRule struct{} - -// Apply applies the rule to given file. -func (r *WaitGroupByValueRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { - var failures []lint.Failure - - onFailure := func(failure lint.Failure) { - failures = append(failures, failure) - } - - w := lintWaitGroupByValueRule{onFailure: onFailure} - ast.Walk(w, file.AST) - return failures -} - -// Name returns the rule name. -func (r *WaitGroupByValueRule) Name() string { - return "waitgroup-by-value" -} - -type lintWaitGroupByValueRule struct { - onFailure func(lint.Failure) -} - -func (w lintWaitGroupByValueRule) Visit(node ast.Node) ast.Visitor { - // look for function declarations - fd, ok := node.(*ast.FuncDecl) - if !ok { - return w - } - - // Check all function's parameters - for _, field := range fd.Type.Params.List { - if !w.isWaitGroup(field.Type) { - continue - } - - w.onFailure(lint.Failure{ - Confidence: 1, - Node: field, - Failure: "sync.WaitGroup passed by value, the function will get a copy of the original one", - }) - } - - return nil -} - -func (lintWaitGroupByValueRule) isWaitGroup(ft ast.Expr) bool { - se, ok := ft.(*ast.SelectorExpr) - if !ok { - return false - } - - x, _ := se.X.(*ast.Ident) - sel := se.Sel.Name - return x.Name == "sync" && sel == "WaitGroup" -} diff --git a/vendor/modules.txt b/vendor/modules.txt index cd437b528..656676e88 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -177,9 +177,6 @@ github.com/bradfitz/gomemcache/memcache github.com/caddyserver/certmagic # github.com/cespare/xxhash/v2 v2.1.1 github.com/cespare/xxhash/v2 -# github.com/chavacava/garif v0.0.0-20210405164556-e8a0a408d6af -## explicit -github.com/chavacava/garif # github.com/chi-middleware/proxy v1.1.1 ## explicit github.com/chi-middleware/proxy @@ -239,10 +236,6 @@ github.com/emirpasic/gods/utils # github.com/ethantkoenig/rupture v1.0.0 ## explicit github.com/ethantkoenig/rupture -# github.com/fatih/color v1.10.0 -github.com/fatih/color -# github.com/fatih/structtag v1.2.0 -github.com/fatih/structtag # github.com/felixge/httpsnoop v1.0.1 github.com/felixge/httpsnoop # github.com/fsnotify/fsnotify v1.4.9 @@ -559,8 +552,6 @@ github.com/markbates/goth/providers/nextcloud github.com/markbates/goth/providers/openidConnect github.com/markbates/goth/providers/twitter github.com/markbates/goth/providers/yandex -# github.com/mattn/go-colorable v0.1.8 -github.com/mattn/go-colorable # github.com/mattn/go-isatty v0.0.12 ## explicit github.com/mattn/go-isatty @@ -572,14 +563,6 @@ github.com/mattn/go-runewidth github.com/mattn/go-sqlite3 # github.com/matttproud/golang_protobuf_extensions v1.0.1 github.com/matttproud/golang_protobuf_extensions/pbutil -# github.com/mgechev/dots v0.0.0-20190921121421-c36f7dcfbb81 -## explicit -github.com/mgechev/dots -# github.com/mgechev/revive v1.0.6 -## explicit -github.com/mgechev/revive/formatter -github.com/mgechev/revive/lint -github.com/mgechev/revive/rule # github.com/mholt/acmez v0.1.3 github.com/mholt/acmez github.com/mholt/acmez/acme @@ -612,7 +595,6 @@ github.com/minio/minio-go/v7/pkg/tags ## explicit github.com/minio/sha256-simd # github.com/mitchellh/go-homedir v1.1.0 -## explicit github.com/mitchellh/go-homedir # github.com/mitchellh/mapstructure v1.4.1 github.com/mitchellh/mapstructure @@ -639,6 +621,7 @@ github.com/nwaples/rardecode # github.com/oklog/ulid v1.3.1 github.com/oklog/ulid # github.com/olekukonko/tablewriter v0.0.5 +## explicit github.com/olekukonko/tablewriter # github.com/oliamb/cutter v0.2.2 ## explicit