mirror of
https://github.com/mgechev/revive.git
synced 2025-11-23 22:04:49 +02:00
chore: format code with gofumpt (#1583)
This commit is contained in:
@@ -137,6 +137,7 @@ formatters:
|
||||
enable:
|
||||
- gci
|
||||
- gofmt
|
||||
- gofumpt
|
||||
- goimports
|
||||
settings:
|
||||
gci:
|
||||
|
||||
@@ -287,7 +287,6 @@ func TestGetConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
cfg, err := config.GetConfig(cfgPath)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %v", err)
|
||||
}
|
||||
|
||||
@@ -57,8 +57,10 @@ func (f *Friendly) printFriendlyFailure(sb *strings.Builder, failure lint.Failur
|
||||
sb.WriteString("\n\n")
|
||||
}
|
||||
|
||||
var errorEmoji = color.RedString("✘")
|
||||
var warningEmoji = color.YellowString("⚠")
|
||||
var (
|
||||
errorEmoji = color.RedString("✘")
|
||||
warningEmoji = color.YellowString("⚠")
|
||||
)
|
||||
|
||||
func (*Friendly) printHeaderRow(sb *strings.Builder, failure lint.Failure, severity lint.Severity) {
|
||||
emoji := warningEmoji
|
||||
|
||||
@@ -12,7 +12,6 @@ func TestGetLogger(t *testing.T) {
|
||||
t.Setenv("DEBUG", "")
|
||||
|
||||
logger, err := logging.GetLogger()
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("expected no error, got %v", err)
|
||||
}
|
||||
@@ -27,7 +26,6 @@ func TestGetLogger(t *testing.T) {
|
||||
t.Cleanup(func() { os.Remove("revive.log") })
|
||||
|
||||
logger, err := logging.GetLogger()
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("expected no error, got %v", err)
|
||||
}
|
||||
|
||||
@@ -36,8 +36,7 @@ func TestReviveCreateInstance(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type mockRule struct {
|
||||
}
|
||||
type mockRule struct{}
|
||||
|
||||
func (*mockRule) Name() string {
|
||||
return "mock-rule"
|
||||
|
||||
@@ -17,7 +17,6 @@ func TestAddConstantRule_Configure(t *testing.T) {
|
||||
wantStrLitLimit int
|
||||
}{
|
||||
{
|
||||
|
||||
name: "no arguments",
|
||||
arguments: lint.Arguments{},
|
||||
wantErr: nil,
|
||||
|
||||
@@ -18,121 +18,177 @@ func TestStringFormatConfigure(t *testing.T) {
|
||||
{
|
||||
name: "Not a Slice",
|
||||
arguments: lint.Arguments{
|
||||
"this is not a slice"},
|
||||
wantErr: errors.New("invalid configuration for string-format: argument is not a slice [argument 0, option 0]")},
|
||||
"this is not a slice",
|
||||
},
|
||||
wantErr: errors.New("invalid configuration for string-format: argument is not a slice [argument 0, option 0]"),
|
||||
},
|
||||
{
|
||||
name: "Missing Regex",
|
||||
arguments: lint.Arguments{
|
||||
[]any{
|
||||
"method[0]"}},
|
||||
wantErr: errors.New("invalid configuration for string-format: less than two slices found in argument, scope and regex are required [argument 0, option 0]")},
|
||||
"method[0]",
|
||||
},
|
||||
},
|
||||
wantErr: errors.New("invalid configuration for string-format: less than two slices found in argument, scope and regex are required [argument 0, option 0]"),
|
||||
},
|
||||
{
|
||||
name: "Bad Argument Type",
|
||||
arguments: lint.Arguments{
|
||||
[]any{
|
||||
1}},
|
||||
wantErr: errors.New("invalid configuration for string-format: less than two slices found in argument, scope and regex are required [argument 0, option 0]")},
|
||||
1,
|
||||
},
|
||||
},
|
||||
wantErr: errors.New("invalid configuration for string-format: less than two slices found in argument, scope and regex are required [argument 0, option 0]"),
|
||||
},
|
||||
{
|
||||
name: "Empty Scope",
|
||||
arguments: lint.Arguments{
|
||||
[]any{
|
||||
"",
|
||||
"//"}},
|
||||
wantErr: errors.New("invalid configuration for string-format: empty scope provided [argument 0, option 0]")},
|
||||
"//",
|
||||
},
|
||||
},
|
||||
wantErr: errors.New("invalid configuration for string-format: empty scope provided [argument 0, option 0]"),
|
||||
},
|
||||
{
|
||||
name: "Small or Empty Regex",
|
||||
arguments: lint.Arguments{
|
||||
[]any{
|
||||
"method[1].a",
|
||||
"-"}},
|
||||
wantErr: errors.New("invalid configuration for string-format: regex is too small (regexes should begin and end with '/') [argument 0, option 1]")},
|
||||
"-",
|
||||
},
|
||||
},
|
||||
wantErr: errors.New("invalid configuration for string-format: regex is too small (regexes should begin and end with '/') [argument 0, option 1]"),
|
||||
},
|
||||
{
|
||||
name: "Bad Scope",
|
||||
arguments: lint.Arguments{
|
||||
[]any{
|
||||
"1.a",
|
||||
"//"}},
|
||||
wantErr: errors.New("failed to parse configuration for string-format: unable to parse rule scope [argument 0, option 0, scope index 0]")},
|
||||
"//",
|
||||
},
|
||||
},
|
||||
wantErr: errors.New("failed to parse configuration for string-format: unable to parse rule scope [argument 0, option 0, scope index 0]"),
|
||||
},
|
||||
{
|
||||
name: "Bad Regex",
|
||||
arguments: lint.Arguments{
|
||||
[]any{
|
||||
"method[1].a",
|
||||
"/(/"}},
|
||||
wantErr: errors.New("failed to parse configuration for string-format: unable to compile /(/ as regexp [argument 0, option 1]")},
|
||||
"/(/",
|
||||
},
|
||||
},
|
||||
wantErr: errors.New("failed to parse configuration for string-format: unable to compile /(/ as regexp [argument 0, option 1]"),
|
||||
},
|
||||
{
|
||||
name: "Sample Config",
|
||||
arguments: lint.Arguments{
|
||||
[]any{
|
||||
"core.WriteError[1].Message", "/^([^A-Z]$)/", "must not start with a capital letter"},
|
||||
"core.WriteError[1].Message", "/^([^A-Z]$)/", "must not start with a capital letter",
|
||||
},
|
||||
[]any{
|
||||
"fmt.Errorf[0]", "/^|[^\\.!?]$/", "must not end in punctuation"},
|
||||
"fmt.Errorf[0]", "/^|[^\\.!?]$/", "must not end in punctuation",
|
||||
},
|
||||
[]any{
|
||||
"panic", "/^[^\\n]*$/", "must not contain line breaks"}}},
|
||||
"panic", "/^[^\\n]*$/", "must not contain line breaks",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Underscores in Scope",
|
||||
arguments: lint.Arguments{
|
||||
[]any{
|
||||
"some_pkg._some_function_name[5].some_member",
|
||||
"//"}}},
|
||||
"//",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Underscores in Multiple Scopes",
|
||||
arguments: lint.Arguments{
|
||||
[]any{
|
||||
"fmt.Errorf[0],core.WriteError[1].Message",
|
||||
"//"}}},
|
||||
"//",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "', ' Delimiter",
|
||||
arguments: lint.Arguments{
|
||||
[]any{
|
||||
"abc, mt.Errorf",
|
||||
"//"}}},
|
||||
"//",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "' ,' Delimiter",
|
||||
arguments: lint.Arguments{
|
||||
[]any{
|
||||
"abc ,mt.Errorf",
|
||||
"//"}}},
|
||||
"//",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "', ' Delimiter",
|
||||
arguments: lint.Arguments{
|
||||
[]any{
|
||||
"abc, mt.Errorf",
|
||||
"//"}}},
|
||||
"//",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "', ' Delimiter",
|
||||
arguments: lint.Arguments{
|
||||
[]any{
|
||||
"abc, mt.Errorf",
|
||||
"//"}}},
|
||||
"//",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Empty Middle Scope",
|
||||
arguments: lint.Arguments{
|
||||
[]any{
|
||||
"abc, ,mt.Errorf",
|
||||
"//"}},
|
||||
wantErr: errors.New("failed to parse configuration for string-format: empty scope in rule scopes: [argument 0, option 0, scope index 1]")},
|
||||
"//",
|
||||
},
|
||||
},
|
||||
wantErr: errors.New("failed to parse configuration for string-format: empty scope in rule scopes: [argument 0, option 0, scope index 1]"),
|
||||
},
|
||||
{
|
||||
name: "Empty First Scope",
|
||||
arguments: lint.Arguments{
|
||||
[]any{
|
||||
",mt.Errorf",
|
||||
"//"}},
|
||||
wantErr: errors.New("failed to parse configuration for string-format: empty scope in rule scopes: [argument 0, option 0, scope index 0]")},
|
||||
"//",
|
||||
},
|
||||
},
|
||||
wantErr: errors.New("failed to parse configuration for string-format: empty scope in rule scopes: [argument 0, option 0, scope index 0]"),
|
||||
},
|
||||
{
|
||||
name: "Bad First Scope",
|
||||
arguments: lint.Arguments{
|
||||
[]any{
|
||||
"1.a,fmt.Errorf[0]",
|
||||
"//"}},
|
||||
wantErr: errors.New("failed to parse configuration for string-format: unable to parse rule scope [argument 0, option 0, scope index 0]")},
|
||||
"//",
|
||||
},
|
||||
},
|
||||
wantErr: errors.New("failed to parse configuration for string-format: unable to parse rule scope [argument 0, option 0, scope index 0]"),
|
||||
},
|
||||
{
|
||||
name: "Bad Second Scope",
|
||||
arguments: lint.Arguments{
|
||||
[]any{
|
||||
"fmt.Errorf[0],1.a",
|
||||
"//"}},
|
||||
wantErr: errors.New("failed to parse configuration for string-format: unable to parse rule scope [argument 0, option 0, scope index 1]")}}
|
||||
"//",
|
||||
},
|
||||
},
|
||||
wantErr: errors.New("failed to parse configuration for string-format: unable to parse rule scope [argument 0, option 0, scope index 1]"),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
@@ -631,7 +631,7 @@ func checkTOMLTag(checkCtx *checkContext, tag *structtag.Tag, _ *ast.Field) (mes
|
||||
}
|
||||
|
||||
func checkURLTag(checkCtx *checkContext, tag *structtag.Tag, _ *ast.Field) (message string, succeeded bool) {
|
||||
var delimiter = ""
|
||||
var delimiter string
|
||||
for _, opt := range tag.Options {
|
||||
switch opt {
|
||||
case "int", "omitempty", "numbered", "brackets",
|
||||
|
||||
@@ -42,13 +42,15 @@ type lintUnsecureURLSchemeRule struct {
|
||||
onFailure func(lint.Failure)
|
||||
}
|
||||
|
||||
const schemeSeparator = "://"
|
||||
const schemeHTTP = "http"
|
||||
const schemeWS = "ws"
|
||||
const urlPrefixHTTP = schemeHTTP + schemeSeparator
|
||||
const urlPrefixWS = schemeWS + schemeSeparator
|
||||
const lenURLPrefixHTTP = len(urlPrefixHTTP)
|
||||
const lenURLPrefixWS = len(urlPrefixWS)
|
||||
const (
|
||||
schemeSeparator = "://"
|
||||
schemeHTTP = "http"
|
||||
schemeWS = "ws"
|
||||
urlPrefixHTTP = schemeHTTP + schemeSeparator
|
||||
urlPrefixWS = schemeWS + schemeSeparator
|
||||
lenURLPrefixHTTP = len(urlPrefixHTTP)
|
||||
lenURLPrefixWS = len(urlPrefixWS)
|
||||
)
|
||||
|
||||
func (w lintUnsecureURLSchemeRule) Visit(node ast.Node) ast.Visitor {
|
||||
n, ok := node.(*ast.BasicLit)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
func TestCommentSpacings(t *testing.T) {
|
||||
testRule(t, "comment_spacings", &rule.CommentSpacingsRule{}, &lint.RuleConfig{
|
||||
Arguments: []any{"myOwnDirective:", "+optional"}},
|
||||
Arguments: []any{"myOwnDirective:", "+optional"},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ func TestMaxControlNestingDefault(t *testing.T) {
|
||||
|
||||
func TestMaxControlNesting(t *testing.T) {
|
||||
testRule(t, "max_control_nesting", &rule.MaxControlNestingRule{}, &lint.RuleConfig{
|
||||
Arguments: []any{int64(2)}},
|
||||
Arguments: []any{int64(2)},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -13,19 +13,25 @@ func TestStringFormat(t *testing.T) {
|
||||
[]any{
|
||||
"stringFormatMethod1", // The first argument is checked by default
|
||||
"/^[A-Z]/",
|
||||
"must start with a capital letter"},
|
||||
"must start with a capital letter",
|
||||
},
|
||||
|
||||
[]any{
|
||||
"stringFormatMethod2[2].d",
|
||||
"/[^\\.]$/"}, // Must not end with a period
|
||||
"/[^\\.]$/",
|
||||
}, // Must not end with a period
|
||||
[]any{
|
||||
"s.Method3[2]",
|
||||
"!/^[Tt][Hh]/",
|
||||
"must not start with 'th'"},
|
||||
"must not start with 'th'",
|
||||
},
|
||||
[]any{
|
||||
"s.Method4", // same as before, but called from a struct
|
||||
"!/^[Ot][Tt]/",
|
||||
"must not start with 'ot'"}}})
|
||||
"must not start with 'ot'",
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestStringFormatDuplicatedStrings(t *testing.T) {
|
||||
|
||||
@@ -16,19 +16,22 @@ func TestVarNaming(t *testing.T) {
|
||||
[]any{},
|
||||
[]any{},
|
||||
[]any{map[string]any{"skip-initialism-name-checks": true}},
|
||||
}})
|
||||
},
|
||||
})
|
||||
testRule(t, "var_naming_skip_initialism_name_checks_false", &rule.VarNamingRule{}, &lint.RuleConfig{
|
||||
Arguments: []any{
|
||||
[]any{},
|
||||
[]any{},
|
||||
[]any{map[string]any{"skip-initialism-name-checks": false}},
|
||||
}})
|
||||
},
|
||||
})
|
||||
testRule(t, "var_naming_allowlist_blocklist_skip_initialism_name_checks", &rule.VarNamingRule{}, &lint.RuleConfig{
|
||||
Arguments: []any{
|
||||
[]any{"ID"},
|
||||
[]any{"VM"},
|
||||
[]any{map[string]any{"skip-initialism-name-checks": true}},
|
||||
}})
|
||||
},
|
||||
})
|
||||
|
||||
testRule(t, "var_naming_test", &rule.VarNamingRule{}, &lint.RuleConfig{})
|
||||
|
||||
@@ -49,19 +52,25 @@ func TestVarNaming(t *testing.T) {
|
||||
})
|
||||
testRule(t, "var_naming_meaningless_package_name", &rule.VarNamingRule{}, &lint.RuleConfig{})
|
||||
testRule(t, "var_naming_meaningless_package_name", &rule.VarNamingRule{}, &lint.RuleConfig{
|
||||
Arguments: []any{[]any{}, []any{},
|
||||
Arguments: []any{
|
||||
[]any{},
|
||||
[]any{},
|
||||
[]any{map[string]any{"skip-package-name-checks": false}},
|
||||
},
|
||||
})
|
||||
testRule(t, "var_naming_bad_package_name", &rule.VarNamingRule{}, &lint.RuleConfig{
|
||||
Arguments: []any{[]any{}, []any{},
|
||||
Arguments: []any{
|
||||
[]any{},
|
||||
[]any{},
|
||||
[]any{map[string]any{"skip-package-name-checks": false, "extra-bad-package-names": []any{"helpers"}}},
|
||||
},
|
||||
})
|
||||
testRule(t, "var_naming_top_level_pkg", &rule.VarNamingRule{}, &lint.RuleConfig{})
|
||||
testRule(t, "var_naming_std_lib_conflict", &rule.VarNamingRule{}, &lint.RuleConfig{})
|
||||
testRule(t, "var_naming_std_lib_conflict_skip", &rule.VarNamingRule{}, &lint.RuleConfig{
|
||||
Arguments: []any{[]any{}, []any{},
|
||||
Arguments: []any{
|
||||
[]any{},
|
||||
[]any{},
|
||||
[]any{map[string]any{"skip-package-name-collision-with-go-std": true}},
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user