Skip to content

Commit

Permalink
chore: format sources with gofumpt
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Oct 25, 2024
1 parent 662e02c commit cf635b8
Show file tree
Hide file tree
Showing 23 changed files with 141 additions and 87 deletions.
2 changes: 1 addition & 1 deletion cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
commit = "none"
date = "unknown"
builtBy = "unknown"
//AppFs is used to operations related with user config files
// AppFs is used to operations related with user config files
AppFs = afero.NewOsFs()
)

Expand Down
17 changes: 8 additions & 9 deletions cli/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ func TestXDGConfigDirIsPrefferedFirst(t *testing.T) {

xdgDirPath := "/tmp-iofs/xdg/config"
homeDirPath := "/tmp-iofs/home/tester"
AppFs.MkdirAll(xdgDirPath, 0755)
AppFs.MkdirAll(homeDirPath, 0755)
AppFs.MkdirAll(xdgDirPath, 0o755)
AppFs.MkdirAll(homeDirPath, 0o755)

afero.WriteFile(AppFs, xdgDirPath+"/revive.toml", []byte("\n"), 0644)
afero.WriteFile(AppFs, xdgDirPath+"/revive.toml", []byte("\n"), 0o644)
t.Setenv("XDG_CONFIG_HOME", xdgDirPath)

afero.WriteFile(AppFs, homeDirPath+"/revive.toml", []byte("\n"), 0644)
afero.WriteFile(AppFs, homeDirPath+"/revive.toml", []byte("\n"), 0o644)
t.Setenv("HOME", homeDirPath)

got := buildDefaultConfigPath()
Expand All @@ -40,11 +40,10 @@ func TestXDGConfigDirIsPrefferedFirst(t *testing.T) {
}

func TestHomeConfigDir(t *testing.T) {

homeDirPath := "/tmp-iofs/home/tester"
AppFs.MkdirAll(homeDirPath, 0755)
AppFs.MkdirAll(homeDirPath, 0o755)

afero.WriteFile(AppFs, homeDirPath+"/revive.toml", []byte("\n"), 0644)
afero.WriteFile(AppFs, homeDirPath+"/revive.toml", []byte("\n"), 0o644)
t.Setenv("HOME", homeDirPath)

got := buildDefaultConfigPath()
Expand All @@ -57,9 +56,9 @@ func TestHomeConfigDir(t *testing.T) {

func TestXDGConfigDir(t *testing.T) {
xdgDirPath := "/tmp-iofs/xdg/config"
AppFs.MkdirAll(xdgDirPath, 0755)
AppFs.MkdirAll(xdgDirPath, 0o755)

afero.WriteFile(AppFs, xdgDirPath+"/revive.toml", []byte("\n"), 0644)
afero.WriteFile(AppFs, xdgDirPath+"/revive.toml", []byte("\n"), 0o644)
t.Setenv("XDG_CONFIG_HOME", xdgDirPath)

got := buildDefaultConfigPath()
Expand Down
8 changes: 5 additions & 3 deletions lint/filefilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ func (ff *FileFilter) MatchFileName(name string) bool {
return ff.rx.MatchString(name)
}

var fileFilterInvalidGlobRegexp = regexp.MustCompile(`[^/]\*\*[^/]`)
var escapeRegexSymbols = ".+{}()[]^$"
var (
fileFilterInvalidGlobRegexp = regexp.MustCompile(`[^/]\*\*[^/]`)
escapeRegexSymbols = ".+{}()[]^$"
)

func (ff *FileFilter) prepareRegexp() error {
var err error
var src = ff.raw
src := ff.raw
if src == "TEST" {
src = "~_test\\.go"
}
Expand Down
3 changes: 0 additions & 3 deletions lint/filefilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func TestFileFilter(t *testing.T) {
t.Fatalf("should not match %s", fn)
}
}

})

t.Run("just *", func(t *testing.T) {
Expand All @@ -109,7 +108,6 @@ func TestFileFilter(t *testing.T) {
t.Fatalf("should match %s", fn)
}
}

})

t.Run("just ~", func(t *testing.T) {
Expand All @@ -123,6 +121,5 @@ func TestFileFilter(t *testing.T) {
t.Fatalf("should match %s", fn)
}
}

})
}
3 changes: 1 addition & 2 deletions revivelib/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (r *Revive) Lint(patterns ...*LintPattern) (<-chan lint.Failure, error) {
if len(excludePatterns) == 0 { // if no excludes were set
excludePatterns = r.config.Exclude // use those from the configuration
}

// by default if no excludes exclude vendor
if len(excludePatterns) == 0 {
excludePatterns = []string{"vendor/..."}
Expand All @@ -95,7 +95,6 @@ func (r *Revive) Lint(patterns ...*LintPattern) (<-chan lint.Failure, error) {

revive := lint.New(func(file string) ([]byte, error) {
contents, err := os.ReadFile(file)

if err != nil {
return nil, fmt.Errorf("reading file %v: %w", file, err)
}
Expand Down
3 changes: 1 addition & 2 deletions revivelib/core_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ func TestReviveCreateInstance(t *testing.T) {
}
}

type mockRule struct {
}
type mockRule struct{}

func (*mockRule) Name() string {
return "mock-rule"
Expand Down
1 change: 0 additions & 1 deletion rule/enforce-map-style.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func (r *EnforceMapStyleRule) configure(arguments lint.Arguments) {

var err error
r.enforceMapStyle, err = mapStyleFromString(enforceMapStyle)

if err != nil {
panic(fmt.Sprintf("Invalid argument to the enforce-map-style rule: %v", err))
}
Expand Down
1 change: 0 additions & 1 deletion rule/enforce-slice-style.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func (r *EnforceSliceStyleRule) configure(arguments lint.Arguments) {

var err error
r.enforceSliceStyle, err = sliceStyleFromString(enforceSliceStyle)

if err != nil {
panic(fmt.Sprintf("Invalid argument to the enforce-slice-style rule: %v", err))
}
Expand Down
8 changes: 5 additions & 3 deletions rule/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ type disabledChecks struct {
Var bool
}

const checkNamePrivateReceivers = "privateReceivers"
const checkNamePublicInterfaces = "publicInterfaces"
const checkNameStuttering = "stuttering"
const (
checkNamePrivateReceivers = "privateReceivers"
checkNamePublicInterfaces = "publicInterfaces"
checkNameStuttering = "stuttering"
)

// isDisabled returns true if the given check is disabled, false otherwise
func (dc *disabledChecks) isDisabled(checkName string) bool {
Expand Down
6 changes: 4 additions & 2 deletions rule/function-length.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ func (*FunctionLength) Name() string {
return "function-length"
}

const defaultFuncStmtsLimit = 50
const defaultFuncLinesLimit = 75
const (
defaultFuncStmtsLimit = 50
defaultFuncLinesLimit = 75
)

func (*FunctionLength) parseArguments(arguments lint.Arguments) (maxStmt, maxLines int64) {
if len(arguments) == 0 {
Expand Down
1 change: 0 additions & 1 deletion rule/line-length-limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func (r *LineLengthLimitRule) configure(arguments lint.Arguments) {
}

r.max = int(maxLength)

}

// Apply applies the rule to given file.
Expand Down
1 change: 0 additions & 1 deletion rule/max-public-structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func (r *MaxPublicStructsRule) configure(arguments lint.Arguments) {
panic(`invalid value passed as argument number to the "max-public-structs" rule`)
}
r.max = maxStructs

}

// Apply applies the rule to given file.
Expand Down
2 changes: 1 addition & 1 deletion rule/redefines-builtin-id.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (w *lintRedefinesBuiltinID) Visit(node ast.Node) ast.Visitor {
if !isTypeOrName {
continue
}

id := obj.Name
if ok, bt := w.isBuiltIn(id); ok {
w.addFailure(name, fmt.Sprintf("redefinition of the built-in %s %s", bt, id))
Expand Down
18 changes: 10 additions & 8 deletions rule/struct-tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,16 @@ func (w lintStructTagRule) Visit(node ast.Node) ast.Visitor {
return w
}

const keyASN1 = "asn1"
const keyBSON = "bson"
const keyDefault = "default"
const keyJSON = "json"
const keyProtobuf = "protobuf"
const keyRequired = "required"
const keyXML = "xml"
const keyYAML = "yaml"
const (
keyASN1 = "asn1"
keyBSON = "bson"
keyDefault = "default"
keyJSON = "json"
keyProtobuf = "protobuf"
keyRequired = "required"
keyXML = "xml"
keyYAML = "yaml"
)

func (w lintStructTagRule) checkTagNameIfNeed(tag *structtag.Tag) (string, bool) {
isUnnamedTag := tag.Name == "" || tag.Name == "-"
Expand Down
1 change: 1 addition & 0 deletions rule/superfluous-else.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rule

import (
"fmt"

"github.com/mgechev/revive/internal/ifelse"
"github.com/mgechev/revive/lint"
)
Expand Down
1 change: 0 additions & 1 deletion rule/var-naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func (r *VarNamingRule) applyPackageCheckRules(walker *lintNames) {
Category: "naming",
})
}

}

// Apply applies the rule to given file.
Expand Down
4 changes: 2 additions & 2 deletions test/comment-spacings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import (

func TestCommentSpacings(t *testing.T) {
testRule(t, "comment-spacings", &rule.CommentSpacingsRule{}, &lint.RuleConfig{
Arguments: []any{"myOwnDirective:", "+optional"}},
)
Arguments: []any{"myOwnDirective:", "+optional"},
})
}
3 changes: 1 addition & 2 deletions test/json-data-format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import (

func TestJsonDataFormat(t *testing.T) {
testRule(t, "json-data-format-atomic", &rule.AtomicRule{})

}

func TestJsonDataFormatVarNaming(t *testing.T) {
testRule(t, "json-data-format-var-naming", &rule.VarNamingRule{}, &lint.RuleConfig{})

}
4 changes: 2 additions & 2 deletions test/max-control-nesting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import (

func TestMaxControlNesting(t *testing.T) {
testRule(t, "max-control-nesting", &rule.MaxControlNestingRule{}, &lint.RuleConfig{
Arguments: []any{int64(2)}},
)
Arguments: []any{int64(2)},
})
}
3 changes: 2 additions & 1 deletion test/redundant-import-alias_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package test

import (
"github.com/mgechev/revive/rule"
"testing"

"github.com/mgechev/revive/rule"
)

// TestRedundantImportAlias rule.
Expand Down
Loading

0 comments on commit cf635b8

Please sign in to comment.