Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format sources w/ gofumpt #643

Merged
merged 1 commit into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ const defaultConfidence = 0.8

// GetConfig yields the configuration
func GetConfig(configPath string) (*lint.Config, error) {
var config = &lint.Config{}
config := &lint.Config{}
switch {
case configPath != "":
config.Confidence = defaultConfidence
Expand Down
5 changes: 3 additions & 2 deletions formatter/checkstyle.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package formatter
import (
"bytes"
"encoding/xml"
"github.com/mgechev/revive/lint"
plainTemplate "text/template"

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

// Checkstyle is an implementation of the Formatter interface
Expand All @@ -29,7 +30,7 @@ type issue struct {

// Format formats the failures gotten from the lint.
func (f *Checkstyle) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
var issues = map[string][]issue{}
issues := map[string][]issue{}
for failure := range failures {
buf := new(bytes.Buffer)
xml.Escape(buf, []byte(failure.Failure))
Expand Down
4 changes: 2 additions & 2 deletions formatter/stylish.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func formatFailure(failure lint.Failure, severity lint.Severity) []string {
// Format formats the failures gotten from the lint.
func (f *Stylish) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
var result [][]string
var totalErrors = 0
var total = 0
totalErrors := 0
total := 0

for f := range failures {
total++
Expand Down
12 changes: 7 additions & 5 deletions lint/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,13 @@ type enableDisableConfig struct {
position int
}

const directiveRE = `^//[\s]*revive:(enable|disable)(?:-(line|next-line))?(?::([^\s]+))?[\s]*(?: (.+))?$`
const directivePos = 1
const modifierPos = 2
const rulesPos = 3
const reasonPos = 4
const (
directiveRE = `^//[\s]*revive:(enable|disable)(?:-(line|next-line))?(?::([^\s]+))?[\s]*(?: (.+))?$`
directivePos = 1
modifierPos = 2
rulesPos = 3
reasonPos = 4
)

var re = regexp.MustCompile(directiveRE)

Expand Down
3 changes: 2 additions & 1 deletion lint/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,6 @@ func getPositionInvalidFile(filename, s string) FailurePosition {
Filename: filename,
Line: line,
Column: column,
}}
},
}
}
2 changes: 1 addition & 1 deletion lint/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type AbstractRule struct {
}

// ToFailurePosition returns the failure position.
func ToFailurePosition(start token.Pos, end token.Pos, file *File) FailurePosition {
func ToFailurePosition(start, end token.Pos, file *File) FailurePosition {
return FailurePosition{
Start: file.ToPosition(start),
End: file.ToPosition(end),
Expand Down
3 changes: 1 addition & 2 deletions rule/add-constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func newWhiteList() whiteList {
return map[string]map[string]bool{kindINT: {}, kindFLOAT: {}, kindSTRING: {}}
}

func (wl whiteList) add(kind string, list string) {
func (wl whiteList) add(kind, list string) {
elems := strings.Split(list, ",")
for _, e := range elems {
wl[kind][e] = true
Expand Down Expand Up @@ -120,7 +120,6 @@ func (w lintAddConstantRule) Visit(node ast.Node) ast.Visitor {
}

return w

}

func (w lintAddConstantRule) checkStrLit(n *ast.BasicLit) {
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 @@ -63,7 +63,7 @@ func (w *lintBoolLiteral) Visit(node ast.Node) ast.Visitor {
return w
}

func (w lintBoolLiteral) addFailure(node ast.Node, msg string, cat string) {
func (w lintBoolLiteral) addFailure(node ast.Node, msg, cat string) {
w.onFailure(lint.Failure{
Confidence: 1,
Node: node,
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 @@ -16,7 +16,7 @@ func (r *CallToGCRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
failures = append(failures, failure)
}

var gcTriggeringFunctions = map[string]map[string]bool{
gcTriggeringFunctions := map[string]map[string]bool{
"runtime": {"GC": true},
}

Expand Down
5 changes: 2 additions & 3 deletions rule/confusing-naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package rule
import (
"fmt"
"go/ast"

"strings"
"sync"

Expand Down Expand Up @@ -71,7 +70,7 @@ func (r *ConfusingNamingRule) Name() string {
return "confusing-naming"
}

//checkMethodName checks if a given method/function name is similar (just case differences) to other method/function of the same struct/file.
// checkMethodName checks if a given method/function name is similar (just case differences) to other method/function of the same struct/file.
func checkMethodName(holder string, id *ast.Ident, w *lintConfusingNames) {
if id.Name == "init" && holder == defaultStructName {
// ignore init functions
Expand Down Expand Up @@ -128,7 +127,7 @@ type lintConfusingNames struct {

const defaultStructName = "_" // used to map functions

//getStructName of a function receiver. Defaults to defaultStructName
// getStructName of a function receiver. Defaults to defaultStructName
func getStructName(r *ast.FieldList) string {
result := defaultStructName

Expand Down
3 changes: 2 additions & 1 deletion rule/constant-logical-expr.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package rule

import (
"github.com/mgechev/revive/lint"
"go/ast"
"go/token"

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

// ConstantLogicalExprRule warns on constant logical expressions.
Expand Down
1 change: 0 additions & 1 deletion rule/context-as-argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type ContextAsArgumentRule struct {

// Apply applies the rule to given file.
func (r *ContextAsArgumentRule) Apply(file *lint.File, args lint.Arguments) []lint.Failure {

if r.allowTypesLUT == nil {
r.allowTypesLUT = getAllowTypesFromArguments(args)
}
Expand Down
2 changes: 1 addition & 1 deletion rule/deep-exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (r *DeepExitRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
failures = append(failures, failure)
}

var exitFunctions = map[string]map[string]bool{
exitFunctions := map[string]map[string]bool{
"os": {"Exit": true},
"syscall": {"Exit": true},
"log": {
Expand Down
5 changes: 3 additions & 2 deletions rule/defer.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,12 @@ func (w lintDeferRule) visitSubtree(n ast.Node, inADefer, inALoop, inAFuncLit bo
inADefer: inADefer,
inALoop: inALoop,
inAFuncLit: inAFuncLit,
allow: w.allow}
allow: w.allow,
}
ast.Walk(nw, n)
}

func (w lintDeferRule) newFailure(msg string, node ast.Node, confidence float64, cat string, subcase string) {
func (w lintDeferRule) newFailure(msg string, node ast.Node, confidence float64, cat, subcase string) {
if !w.allow[subcase] {
return
}
Expand Down
2 changes: 1 addition & 1 deletion rule/error-strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type ErrorStringsRule struct{}
func (r *ErrorStringsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure

var errorFunctions = map[string]map[string]struct{}{
errorFunctions := map[string]map[string]struct{}{
"fmt": {
"Errorf": {},
},
Expand Down
2 changes: 1 addition & 1 deletion rule/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (r *ExportedRule) Name() string {
return "exported"
}

func (r *ExportedRule) getConf(args lint.Arguments) (checkPrivateReceivers bool, disableStutteringCheck bool, sayRepetitiveInsteadOfStutters bool) {
func (r *ExportedRule) getConf(args lint.Arguments) (checkPrivateReceivers, disableStutteringCheck, sayRepetitiveInsteadOfStutters bool) {
// if any, we expect a slice of strings as configuration
if len(args) < 1 {
return
Expand Down
3 changes: 2 additions & 1 deletion rule/flag-param.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package rule

import (
"fmt"
"github.com/mgechev/revive/lint"
"go/ast"

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

// FlagParamRule lints given else constructs.
Expand Down
2 changes: 1 addition & 1 deletion rule/function-length.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (r *FunctionLength) Name() string {
return "function-length"
}

func (r *FunctionLength) parseArguments(arguments lint.Arguments) (maxStmt int64, maxLines int64) {
func (r *FunctionLength) parseArguments(arguments lint.Arguments) (maxStmt, maxLines int64) {
if len(arguments) != 2 {
panic(fmt.Sprintf(`invalid configuration for "function-length" rule, expected 2 arguments but got %d`, len(arguments)))
}
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 @@ -2,7 +2,6 @@ package rule

import (
"go/ast"

"strings"

"github.com/mgechev/revive/lint"
Expand Down
1 change: 0 additions & 1 deletion rule/range-val-in-closure.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type rangeValInClosure struct {
}

func (w rangeValInClosure) Visit(node ast.Node) ast.Visitor {

// Find the variables updated by the loop statement.
var vars []*ast.Ident
addVar := func(expr ast.Expr) {
Expand Down
9 changes: 5 additions & 4 deletions rule/redefines-builtin-id.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package rule

import (
"fmt"
"github.com/mgechev/revive/lint"
"go/ast"
"go/token"

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

// RedefinesBuiltinIDRule warns when a builtin identifier is shadowed.
Expand All @@ -14,14 +15,14 @@ type RedefinesBuiltinIDRule struct{}
func (r *RedefinesBuiltinIDRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure

var builtInConstAndVars = map[string]bool{
builtInConstAndVars := map[string]bool{
"true": true,
"false": true,
"iota": true,
"nil": true,
}

var builtFunctions = map[string]bool{
builtFunctions := map[string]bool{
"append": true,
"cap": true,
"close": true,
Expand All @@ -39,7 +40,7 @@ func (r *RedefinesBuiltinIDRule) Apply(file *lint.File, _ lint.Arguments) []lint
"recover": true,
}

var builtInTypes = map[string]bool{
builtInTypes := map[string]bool{
"ComplexType": true,
"FloatType": true,
"IntegerType": true,
Expand Down
3 changes: 2 additions & 1 deletion rule/string-format.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ func (rule stringFormatSubrule) lintMessage(s string, node ast.Node) {
rule.parent.onFailure(lint.Failure{
Confidence: 1,
Failure: failure,
Node: node})
Node: node,
})
}

// #endregion
1 change: 0 additions & 1 deletion rule/struct-tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func (w lintStructTagRule) Visit(node ast.Node) ast.Visitor {
}

return w

}

// checkTaggedField checks the tag of the given field.
Expand Down
2 changes: 1 addition & 1 deletion rule/superfluous-else.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (r *SuperfluousElseRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fa
failures = append(failures, failure)
}

var branchingFunctions = map[string]map[string]bool{
branchingFunctions := map[string]map[string]bool{
"os": {"Exit": true},
"log": {
"Fatal": true,
Expand Down
2 changes: 1 addition & 1 deletion rule/unreachable-code.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (r *UnreachableCodeRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fa
failures = append(failures, failure)
}

var branchingFunctions = map[string]map[string]bool{
branchingFunctions := map[string]map[string]bool{
"os": {"Exit": true},
"log": {
"Fatal": true,
Expand Down