Skip to content

Commit

Permalink
test: add default case when no arguments provided to a rule
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Nov 20, 2024
1 parent 0e8acea commit 2b4cf05
Show file tree
Hide file tree
Showing 24 changed files with 571 additions and 6 deletions.
4 changes: 4 additions & 0 deletions test/argument_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/mgechev/revive/rule"
)

func TestArgumentLimitDefault(t *testing.T) {
testRule(t, "argument_limit_default", &rule.ArgumentsLimitRule{}, &lint.RuleConfig{})
}

func TestArgumentLimit(t *testing.T) {
testRule(t, "argument_limit", &rule.ArgumentsLimitRule{}, &lint.RuleConfig{
Arguments: []any{int64(3)},
Expand Down
4 changes: 4 additions & 0 deletions test/banned_characters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/mgechev/revive/rule"
)

func TestBannedCharactersDefault(t *testing.T) {
testRule(t, "banned_characters_default", &rule.BannedCharsRule{}, &lint.RuleConfig{})
}

// Test banned characters in a const, var and func names.
// One banned character is in the comment and should not be checked.
// One banned character from the list is not present in the fixture file.
Expand Down
4 changes: 4 additions & 0 deletions test/cognitive_complexity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/mgechev/revive/rule"
)

func TestCognitiveComplexityDefault(t *testing.T) {
testRule(t, "cognitive_complexity_default", &rule.CognitiveComplexityRule{}, &lint.RuleConfig{})
}

func TestCognitiveComplexity(t *testing.T) {
testRule(t, "cognitive_complexity", &rule.CognitiveComplexityRule{}, &lint.RuleConfig{
Arguments: []any{int64(0)},
Expand Down
4 changes: 4 additions & 0 deletions test/context_as_argument_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/mgechev/revive/rule"
)

func TestContextAsArgumentDefault(t *testing.T) {
testRule(t, "context_as_argument_default", &rule.ContextAsArgumentRule{}, &lint.RuleConfig{})
}

func TestContextAsArgument(t *testing.T) {
testRule(t, "context_as_argument", &rule.ContextAsArgumentRule{}, &lint.RuleConfig{
Arguments: []any{
Expand Down
5 changes: 5 additions & 0 deletions test/cyclomatic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import (
"github.com/mgechev/revive/rule"
)

func TestCyclomaticDefault(t *testing.T) {
testRule(t, "cyclomatic_default", &rule.CyclomaticRule{}, &lint.RuleConfig{})
}

func TestCyclomatic(t *testing.T) {
testRule(t, "cyclomatic_default", &rule.CyclomaticRule{}, &lint.RuleConfig{})
testRule(t, "cyclomatic", &rule.CyclomaticRule{}, &lint.RuleConfig{
Arguments: []any{int64(1)},
})
Expand Down
14 changes: 8 additions & 6 deletions test/dot_imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (
"github.com/mgechev/revive/rule"
)

func TestDotImports(t *testing.T) {
args := []any{map[string]any{
"allowedPackages": []any{"errors", "context", "github.com/BurntSushi/toml"},
}}
func TestDotImportsDefault(t *testing.T) {
testRule(t, "dot_imports_default", &rule.DotImportsRule{}, &lint.RuleConfig{})
}

testRule(t, "import_dot", &rule.DotImportsRule{}, &lint.RuleConfig{
Arguments: args,
func TestDotImports(t *testing.T) {
testRule(t, "dot_imports", &rule.DotImportsRule{}, &lint.RuleConfig{
Arguments: []any{map[string]any{
"allowedPackages": []any{"errors", "context", "github.com/BurntSushi/toml"},
}},
})
}
4 changes: 4 additions & 0 deletions test/enforce_repeated_arg_type_style_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/mgechev/revive/rule"
)

func TestEnforceRepeatedArgTypeStyleDefault(t *testing.T) {
testRule(t, "enforce_repeated_arg_type_style_default", &rule.EnforceRepeatedArgTypeStyleRule{}, &lint.RuleConfig{})
}

func TestEnforceRepeatedArgTypeStyleShort(t *testing.T) {
testRule(t, "enforce_repeated_arg_type_style_short_args", &rule.EnforceRepeatedArgTypeStyleRule{}, &lint.RuleConfig{
Arguments: []any{"short"},
Expand Down
4 changes: 4 additions & 0 deletions test/file_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/mgechev/revive/rule"
)

func TestLintFileHeaderDefault(t *testing.T) {
testRule(t, "lint_file_header_default", &rule.FileHeaderRule{}, &lint.RuleConfig{})
}

func TestLintFileHeader(t *testing.T) {
testRule(t, "lint_file_header1", &rule.FileHeaderRule{}, &lint.RuleConfig{
Arguments: []any{"foobar"},
Expand Down
4 changes: 4 additions & 0 deletions test/function_length_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/mgechev/revive/rule"
)

func TestFuncLengthDefault(t *testing.T) {
testRule(t, "function_length_default", &rule.FunctionLength{}, &lint.RuleConfig{})
}

func TestFuncLengthLimitsStatements(t *testing.T) {
testRule(t, "function_length1", &rule.FunctionLength{}, &lint.RuleConfig{
Arguments: []any{int64(2), int64(100)},
Expand Down
4 changes: 4 additions & 0 deletions test/line_length_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/mgechev/revive/rule"
)

func TestLineLengthLimitDefault(t *testing.T) {
testRule(t, "line_length_limit_default", &rule.LineLengthLimitRule{}, &lint.RuleConfig{})
}

func TestLineLengthLimit(t *testing.T) {
testRule(t, "line_length_limit", &rule.LineLengthLimitRule{}, &lint.RuleConfig{
Arguments: []any{int64(100)},
Expand Down
4 changes: 4 additions & 0 deletions test/max_control_nesting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/mgechev/revive/rule"
)

func TestMaxControlNestingDefault(t *testing.T) {
testRule(t, "max_control_nesting_default", &rule.MaxControlNestingRule{}, &lint.RuleConfig{})
}

func TestMaxControlNesting(t *testing.T) {
testRule(t, "max_control_nesting", &rule.MaxControlNestingRule{}, &lint.RuleConfig{
Arguments: []any{int64(2)}},
Expand Down
7 changes: 7 additions & 0 deletions testdata/argument_limit_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package fixtures

func foo(a, b, c, d, e, f, g, h int) {
}

func bar(a, b, c, d, e, f, g, h, i int64) { // MATCH /maximum number of arguments per function exceeded; max 8 but got 9/
}
3 changes: 3 additions & 0 deletions testdata/banned_characters_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package fixtures

const Ω = "Omega"
13 changes: 13 additions & 0 deletions testdata/cognitive_complexity_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package pkg

func l() { // MATCH /function l has cognitive complexity 8 (> max enabled 7)/
for i := 1; i <= max; i++ {
for j := 2; j < i; j++ {
if (i%j == 0) || (i%j == 1) {
continue
}
total += i
}
}
return total && max
}
9 changes: 9 additions & 0 deletions testdata/context_as_argument_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package foo

import (
"context"
"testing"
)

func x(_ AllowedBeforePtrStruct, ctx context.Context) { // MATCH /context.Context should be the first parameter of a function/
}
19 changes: 19 additions & 0 deletions testdata/cyclomatic_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package pkg

import "log"

func f(x int) bool { // MATCH /function f has cyclomatic complexity 11 (> max enabled 10)/
if x > 0 && true || false {
return true
} else {
log.Printf("non-positive x: %d", x)
}
switch x {
case 1:
case 2:
case 3:
case 4:
default:
}
return true || true && true
}
File renamed without changes.
5 changes: 5 additions & 0 deletions testdata/dot_imports_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package fixtures

import (
. "context" // MATCH /should not use dot imports/
)
21 changes: 21 additions & 0 deletions testdata/enforce_repeated_arg_type_style_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package fixtures

func compliantFunc(a, b int, c string) {}

func nonCompliantFunc1(a int, b int, c string) {}
func nonCompliantFunc2(a int, b, c int) {}

type myStruct struct{}

func (m myStruct) compliantMethod(a, b int, c string) {}

func (m myStruct) nonCompliantMethod1(a int, b int, c string) {}
func (m myStruct) nonCompliantMethod2(a int, b, c int) {}

func variadicFunction(a int, b ...int) {}

func singleArgFunction(a int) {}

func multiTypeArgs(a int, b string, c float64) {}

func mixedCompliance(a, b int, c int, d string) {}
Loading

0 comments on commit 2b4cf05

Please sign in to comment.