Skip to content

Commit

Permalink
revert where parameter is not used
Browse files Browse the repository at this point in the history
  • Loading branch information
mfederowicz committed Dec 25, 2023
1 parent baae12d commit 577f932
Show file tree
Hide file tree
Showing 56 changed files with 114 additions and 114 deletions.
2 changes: 1 addition & 1 deletion rule/add-constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (r lintAddConstantRule) checkFunc(expr *ast.CallExpr) {
}
}

func (r lintAddConstantRule) getFuncName(expr *ast.CallExpr) string {
func (lintAddConstantRule) getFuncName(expr *ast.CallExpr) string {
switch f := expr.Fun.(type) {
case *ast.SelectorExpr:
switch prefix := f.X.(type) {
Expand Down
14 changes: 7 additions & 7 deletions rule/atomic.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type AtomicRule struct{}

// Apply applies the rule to given file.
func (r *AtomicRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
func (*AtomicRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure
walker := atomic{
pkgTypesInfo: file.Pkg.TypesInfo(),
Expand All @@ -36,10 +36,10 @@ type atomic struct {
onFailure func(lint.Failure)
}

func (r atomic) Visit(node ast.Node) ast.Visitor {
func (w atomic) Visit(node ast.Node) ast.Visitor {
n, ok := node.(*ast.AssignStmt)
if !ok {
return r
return w
}

if len(n.Lhs) != len(n.Rhs) {
Expand All @@ -59,8 +59,8 @@ func (r atomic) Visit(node ast.Node) ast.Visitor {
continue
}
pkgIdent, _ := sel.X.(*ast.Ident)
if r.pkgTypesInfo != nil {
pkgName, ok := r.pkgTypesInfo.Uses[pkgIdent].(*types.PkgName)
if w.pkgTypesInfo != nil {
pkgName, ok := w.pkgTypesInfo.Uses[pkgIdent].(*types.PkgName)
if !ok || pkgName.Imported().Path() != "sync/atomic" {
continue
}
Expand All @@ -82,13 +82,13 @@ func (r atomic) Visit(node ast.Node) ast.Visitor {
}

if broken {
r.onFailure(lint.Failure{
w.onFailure(lint.Failure{
Confidence: 1,
Failure: "direct assignment to atomic value",
Node: n,
})
}
}
}
return r
return w
}
2 changes: 1 addition & 1 deletion rule/bare-return.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type BareReturnRule struct{}

// Apply applies the rule to given file.
func (r *BareReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
func (*BareReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure

onFailure := func(failure lint.Failure) {
Expand Down
2 changes: 1 addition & 1 deletion rule/blank-imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (r *BlankImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failu
return failures
}

func (r *BlankImportsRule) fileHasValidEmbedComment(fileAst *ast.File) bool {
func (*BlankImportsRule) fileHasValidEmbedComment(fileAst *ast.File) bool {
for _, commentGroup := range fileAst.Comments {
for _, comment := range commentGroup.List {
if strings.HasPrefix(comment.Text, "//go:embed ") {
Expand Down
2 changes: 1 addition & 1 deletion rule/bool-literal-in-expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type BoolLiteralRule struct{}

// Apply applies the rule to given file.
func (r *BoolLiteralRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
func (*BoolLiteralRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure

onFailure := func(failure lint.Failure) {
Expand Down
2 changes: 1 addition & 1 deletion rule/call-to-gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type CallToGCRule struct{}

// Apply applies the rule to given file.
func (r *CallToGCRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
func (*CallToGCRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure
onFailure := func(failure lint.Failure) {
failures = append(failures, failure)
Expand Down
74 changes: 37 additions & 37 deletions rule/cognitive-complexity.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ type cognitiveComplexityLinter struct {
onFailure func(lint.Failure)
}

func (r cognitiveComplexityLinter) lintCognitiveComplexity() {
f := r.file
func (w cognitiveComplexityLinter) lintCognitiveComplexity() {
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 > r.maxComplexity {
r.onFailure(lint.Failure{
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, r.maxComplexity),
Failure: fmt.Sprintf("function %s has cognitive complexity %d (> max enabled %d)", funcName(fn), c, w.maxComplexity),
Node: fn,
})
}
Expand All @@ -90,67 +90,67 @@ type cognitiveComplexityVisitor struct {
}

// subTreeComplexity calculates the cognitive complexity of an AST-subtree.
func (r cognitiveComplexityVisitor) subTreeComplexity(n ast.Node) int {
ast.Walk(&r, n)
return r.complexity
func (v cognitiveComplexityVisitor) subTreeComplexity(n ast.Node) int {
ast.Walk(&v, n)
return v.complexity
}

// Visit implements the ast.Visitor interface.
func (r *cognitiveComplexityVisitor) Visit(n ast.Node) ast.Visitor {
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}
r.walk(1, targets...)
v.walk(1, targets...)
return nil
case *ast.ForStmt:
targets := []ast.Node{n.Cond, n.Body}
r.walk(1, targets...)
v.walk(1, targets...)
return nil
case *ast.RangeStmt:
r.walk(1, n.Body)
v.walk(1, n.Body)
return nil
case *ast.SelectStmt:
r.walk(1, n.Body)
v.walk(1, n.Body)
return nil
case *ast.SwitchStmt:
r.walk(1, n.Body)
v.walk(1, n.Body)
return nil
case *ast.TypeSwitchStmt:
r.walk(1, n.Body)
v.walk(1, n.Body)
return nil
case *ast.FuncLit:
r.walk(0, n.Body) // do not increment the complexity, just do the nesting
v.walk(0, n.Body) // do not increment the complexity, just do the nesting
return nil
case *ast.BinaryExpr:
r.complexity += r.binExpComplexity(n)
v.complexity += v.binExpComplexity(n)
return nil // skip visiting binexp sub-tree (already visited by binExpComplexity)
case *ast.BranchStmt:
if n.Label != nil {
r.complexity++
v.complexity++
}
}
// TODO handle (at least) direct recursion

return r
return v
}

func (r *cognitiveComplexityVisitor) walk(complexityIncrement int, targets ...ast.Node) {
r.complexity += complexityIncrement + r.nestingLevel
nesting := r.nestingLevel
r.nestingLevel++
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(r, t)
ast.Walk(v, t)
}

r.nestingLevel = nesting
v.nestingLevel = nesting
}

func (r cognitiveComplexityVisitor) binExpComplexity(n *ast.BinaryExpr) int {
func (cognitiveComplexityVisitor) binExpComplexity(n *ast.BinaryExpr) int {
calculator := binExprComplexityCalculator{opsStack: []token.Token{}}

astutil.Apply(n, calculator.pre, calculator.post)
Expand All @@ -164,48 +164,48 @@ type binExprComplexityCalculator struct {
subexpStarted bool
}

func (r *binExprComplexityCalculator) pre(c *astutil.Cursor) 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(r.opsStack)
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 || r.subexpStarted || n.Op != r.opsStack[ops-1] {
r.complexity++
r.subexpStarted = false
if ops == 0 || becc.subexpStarted || n.Op != becc.opsStack[ops-1] {
becc.complexity++
becc.subexpStarted = false
}

r.opsStack = append(r.opsStack, n.Op)
becc.opsStack = append(becc.opsStack, n.Op)
case *ast.ParenExpr:
r.subexpStarted = true
becc.subexpStarted = true
}

return true
}

func (r *binExprComplexityCalculator) post(c *astutil.Cursor) bool {
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(r.opsStack)
ops := len(becc.opsStack)
if ops > 0 {
r.opsStack = r.opsStack[:ops-1]
becc.opsStack = becc.opsStack[:ops-1]
}
case *ast.ParenExpr:
r.subexpStarted = false
becc.subexpStarted = false
}

return true
Expand Down
2 changes: 1 addition & 1 deletion rule/confusing-naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var allPkgs = packages{pkgs: make([]pkgMethods, 1)}
type ConfusingNamingRule struct{}

// Apply applies the rule to given file.
func (r *ConfusingNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
func (*ConfusingNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure
fileAst := file.AST
pkgm := allPkgs.methodNames(file.Pkg)
Expand Down
2 changes: 1 addition & 1 deletion rule/confusing-results.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type ConfusingResultsRule struct{}

// Apply applies the rule to given file.
func (r *ConfusingResultsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
func (*ConfusingResultsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure

fileAst := file.AST
Expand Down
8 changes: 4 additions & 4 deletions rule/constant-logical-expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type ConstantLogicalExprRule struct{}

// Apply applies the rule to given file.
func (r *ConstantLogicalExprRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
func (*ConstantLogicalExprRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure

onFailure := func(failure lint.Failure) {
Expand Down Expand Up @@ -63,7 +63,7 @@ func (w *lintConstantLogicalExpr) Visit(node ast.Node) ast.Visitor {
return w
}

func (l *lintConstantLogicalExpr) isOperatorWithLogicalResult(t token.Token) bool {
func (*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
Expand All @@ -72,7 +72,7 @@ func (l *lintConstantLogicalExpr) isOperatorWithLogicalResult(t token.Token) boo
return false
}

func (l *lintConstantLogicalExpr) isEqualityOperator(t token.Token) bool {
func (*lintConstantLogicalExpr) isEqualityOperator(t token.Token) bool {
switch t {
case token.EQL, token.LEQ, token.GEQ:
return true
Expand All @@ -81,7 +81,7 @@ func (l *lintConstantLogicalExpr) isEqualityOperator(t token.Token) bool {
return false
}

func (l *lintConstantLogicalExpr) isInequalityOperator(t token.Token) bool {
func (*lintConstantLogicalExpr) isInequalityOperator(t token.Token) bool {
switch t {
case token.LSS, token.GTR, token.NEQ:
return true
Expand Down
2 changes: 1 addition & 1 deletion rule/context-keys-type.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type ContextKeysType struct{}

// Apply applies the rule to given file.
func (c *ContextKeysType) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
func (*ContextKeysType) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure

fileAst := file.AST
Expand Down
4 changes: 2 additions & 2 deletions rule/datarace.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type DataRaceRule struct{}

// Apply applies the rule to given file.
func (r *DataRaceRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
func (*DataRaceRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure
onFailure := func(failure lint.Failure) {
failures = append(failures, failure)
Expand Down Expand Up @@ -53,7 +53,7 @@ func (w lintDataRaces) Visit(n ast.Node) ast.Visitor {
return nil
}

func (w lintDataRaces) ExtractReturnIDs(fields []*ast.Field) map[*ast.Object]struct{} {
func (lintDataRaces) ExtractReturnIDs(fields []*ast.Field) map[*ast.Object]struct{} {
r := map[*ast.Object]struct{}{}
for _, f := range fields {
for _, id := range f.Names {
Expand Down
2 changes: 1 addition & 1 deletion rule/deep-exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type DeepExitRule struct{}

// Apply applies the rule to given file.
func (r *DeepExitRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
func (*DeepExitRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure
onFailure := func(failure lint.Failure) {
failures = append(failures, failure)
Expand Down
2 changes: 1 addition & 1 deletion rule/defer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (*DeferRule) Name() string {
return "defer"
}

func (r *DeferRule) allowFromArgs(args lint.Arguments) map[string]bool {
func (*DeferRule) allowFromArgs(args lint.Arguments) map[string]bool {
if len(args) < 1 {
allow := map[string]bool{
"loop": true,
Expand Down
2 changes: 1 addition & 1 deletion rule/duplicated-imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type DuplicatedImportsRule struct{}

// Apply applies the rule to given file.
func (r *DuplicatedImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
func (*DuplicatedImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure

impPaths := map[string]struct{}{}
Expand Down
2 changes: 1 addition & 1 deletion rule/early-return.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (*EarlyReturnRule) Name() string {
}

// CheckIfElse evaluates the rule against an ifelse.Chain.
func (e *EarlyReturnRule) CheckIfElse(chain ifelse.Chain, args ifelse.Args) (failMsg string) {
func (*EarlyReturnRule) CheckIfElse(chain ifelse.Chain, args ifelse.Args) (failMsg string) {
if !chain.Else.Deviates() {
// this rule only applies if the else-block deviates control flow
return
Expand Down
2 changes: 1 addition & 1 deletion rule/empty-block.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type EmptyBlockRule struct{}

// Apply applies the rule to given file.
func (r *EmptyBlockRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
func (*EmptyBlockRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure

onFailure := func(failure lint.Failure) {
Expand Down
Loading

0 comments on commit 577f932

Please sign in to comment.