aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/bkielbasa
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2025-01-22 16:07:17 +0100
committerTaras Madan <tarasmadan@google.com>2025-01-23 10:42:36 +0000
commit7b4377ad9d8a7205416df8d6217ef2b010f89481 (patch)
treee6fec4fd12ff807a16d847923f501075bf71d16c /vendor/github.com/bkielbasa
parent475a4c203afb8b7d3af51c4fd32bb170ff32a45e (diff)
vendor: delete
Diffstat (limited to 'vendor/github.com/bkielbasa')
-rw-r--r--vendor/github.com/bkielbasa/cyclop/LICENSE21
-rw-r--r--vendor/github.com/bkielbasa/cyclop/pkg/analyzer/analyzer.go111
2 files changed, 0 insertions, 132 deletions
diff --git a/vendor/github.com/bkielbasa/cyclop/LICENSE b/vendor/github.com/bkielbasa/cyclop/LICENSE
deleted file mode 100644
index b4a776a40..000000000
--- a/vendor/github.com/bkielbasa/cyclop/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2020 Bartłomiej Klimczak
-
-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/bkielbasa/cyclop/pkg/analyzer/analyzer.go b/vendor/github.com/bkielbasa/cyclop/pkg/analyzer/analyzer.go
deleted file mode 100644
index 1972379df..000000000
--- a/vendor/github.com/bkielbasa/cyclop/pkg/analyzer/analyzer.go
+++ /dev/null
@@ -1,111 +0,0 @@
-package analyzer
-
-import (
- "flag"
- "go/ast"
- "go/token"
- "strings"
-
- "golang.org/x/tools/go/analysis"
-)
-
-//nolint:gochecknoglobals
-var flagSet flag.FlagSet
-
-//nolint:gochecknoglobals
-var (
- maxComplexity int
- packageAverage float64
- skipTests bool
-)
-
-const (
- defaultMaxComplexity = 10
-)
-
-//nolint:gochecknoinits
-func init() {
- flagSet.IntVar(&maxComplexity, "maxComplexity", defaultMaxComplexity, "max complexity the function can have")
- flagSet.Float64Var(&packageAverage, "packageAverage", 0, "max average complexity in package")
- flagSet.BoolVar(&skipTests, "skipTests", false, "should the linter execute on test files as well")
-}
-
-func NewAnalyzer() *analysis.Analyzer {
- return &analysis.Analyzer{
- Name: "cyclop",
- Doc: "checks function and package cyclomatic complexity",
- Run: run,
- Flags: flagSet,
- }
-}
-
-func run(pass *analysis.Pass) (interface{}, error) {
- var sum, count float64
- var pkgName string
- var pkgPos token.Pos
-
- for _, file := range pass.Files {
- ast.Inspect(file, func(node ast.Node) bool {
- funcDecl, ok := node.(*ast.FuncDecl)
- if !ok {
- if node == nil {
- return true
- }
- if file, ok := node.(*ast.File); ok {
- pkgName = file.Name.Name
- pkgPos = node.Pos()
- }
- // we check function by function
- return true
- }
-
- if skipTests && testFunc(funcDecl) {
- return true
- }
-
- count++
- comp := complexity(funcDecl)
- sum += float64(comp)
- if comp > maxComplexity {
- pass.Reportf(node.Pos(), "calculated cyclomatic complexity for function %s is %d, max is %d", funcDecl.Name.Name, comp, maxComplexity)
- }
-
- return true
- })
- }
-
- if packageAverage > 0 {
- avg := sum / count
- if avg > packageAverage {
- pass.Reportf(pkgPos, "the average complexity for the package %s is %f, max is %f", pkgName, avg, packageAverage)
- }
- }
-
- return nil, nil
-}
-
-func testFunc(f *ast.FuncDecl) bool {
- return strings.HasPrefix(f.Name.Name, "Test")
-}
-
-func complexity(fn *ast.FuncDecl) int {
- v := complexityVisitor{}
- ast.Walk(&v, fn)
- return v.Complexity
-}
-
-type complexityVisitor struct {
- Complexity int
-}
-
-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
-}