Skip to content

Commit 577441d

Browse files
authored
format sources w/ gofumpt (#643)
Signed-off-by: subham sarkar <[email protected]>
1 parent 54d9a09 commit 577441d

24 files changed

+39
-37
lines changed

config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ const defaultConfidence = 0.8
180180

181181
// GetConfig yields the configuration
182182
func GetConfig(configPath string) (*lint.Config, error) {
183-
var config = &lint.Config{}
183+
config := &lint.Config{}
184184
switch {
185185
case configPath != "":
186186
config.Confidence = defaultConfidence

formatter/checkstyle.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package formatter
33
import (
44
"bytes"
55
"encoding/xml"
6-
"github.com/mgechev/revive/lint"
76
plainTemplate "text/template"
7+
8+
"github.com/mgechev/revive/lint"
89
)
910

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

3031
// Format formats the failures gotten from the lint.
3132
func (f *Checkstyle) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
32-
var issues = map[string][]issue{}
33+
issues := map[string][]issue{}
3334
for failure := range failures {
3435
buf := new(bytes.Buffer)
3536
xml.Escape(buf, []byte(failure.Failure))

formatter/stylish.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ func formatFailure(failure lint.Failure, severity lint.Severity) []string {
3434
// Format formats the failures gotten from the lint.
3535
func (f *Stylish) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
3636
var result [][]string
37-
var totalErrors = 0
38-
var total = 0
37+
totalErrors := 0
38+
total := 0
3939

4040
for f := range failures {
4141
total++

lint/file.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,13 @@ type enableDisableConfig struct {
126126
position int
127127
}
128128

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

135137
var re = regexp.MustCompile(directiveRE)
136138

lint/linter.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,6 @@ func getPositionInvalidFile(filename, s string) FailurePosition {
159159
Filename: filename,
160160
Line: line,
161161
Column: column,
162-
}}
162+
},
163+
}
163164
}

lint/rule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type AbstractRule struct {
2323
}
2424

2525
// ToFailurePosition returns the failure position.
26-
func ToFailurePosition(start token.Pos, end token.Pos, file *File) FailurePosition {
26+
func ToFailurePosition(start, end token.Pos, file *File) FailurePosition {
2727
return FailurePosition{
2828
Start: file.ToPosition(start),
2929
End: file.ToPosition(end),

rule/add-constant.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func newWhiteList() whiteList {
2222
return map[string]map[string]bool{kindINT: {}, kindFLOAT: {}, kindSTRING: {}}
2323
}
2424

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

122122
return w
123-
124123
}
125124

126125
func (w lintAddConstantRule) checkStrLit(n *ast.BasicLit) {

rule/bool-literal-in-expr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (w *lintBoolLiteral) Visit(node ast.Node) ast.Visitor {
6363
return w
6464
}
6565

66-
func (w lintBoolLiteral) addFailure(node ast.Node, msg string, cat string) {
66+
func (w lintBoolLiteral) addFailure(node ast.Node, msg, cat string) {
6767
w.onFailure(lint.Failure{
6868
Confidence: 1,
6969
Node: node,

rule/call-to-gc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (r *CallToGCRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
1616
failures = append(failures, failure)
1717
}
1818

19-
var gcTriggeringFunctions = map[string]map[string]bool{
19+
gcTriggeringFunctions := map[string]map[string]bool{
2020
"runtime": {"GC": true},
2121
}
2222

rule/confusing-naming.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package rule
33
import (
44
"fmt"
55
"go/ast"
6-
76
"strings"
87
"sync"
98

@@ -71,7 +70,7 @@ func (r *ConfusingNamingRule) Name() string {
7170
return "confusing-naming"
7271
}
7372

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

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

131-
//getStructName of a function receiver. Defaults to defaultStructName
130+
// getStructName of a function receiver. Defaults to defaultStructName
132131
func getStructName(r *ast.FieldList) string {
133132
result := defaultStructName
134133

rule/context-as-argument.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ type ContextAsArgumentRule struct {
1515

1616
// Apply applies the rule to given file.
1717
func (r *ContextAsArgumentRule) Apply(file *lint.File, args lint.Arguments) []lint.Failure {
18-
1918
if r.allowTypesLUT == nil {
2019
r.allowTypesLUT = getAllowTypesFromArguments(args)
2120
}

rule/deep-exit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (r *DeepExitRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
1717
failures = append(failures, failure)
1818
}
1919

20-
var exitFunctions = map[string]map[string]bool{
20+
exitFunctions := map[string]map[string]bool{
2121
"os": {"Exit": true},
2222
"syscall": {"Exit": true},
2323
"log": {

rule/defer.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,12 @@ func (w lintDeferRule) visitSubtree(n ast.Node, inADefer, inALoop, inAFuncLit bo
122122
inADefer: inADefer,
123123
inALoop: inALoop,
124124
inAFuncLit: inAFuncLit,
125-
allow: w.allow}
125+
allow: w.allow,
126+
}
126127
ast.Walk(nw, n)
127128
}
128129

129-
func (w lintDeferRule) newFailure(msg string, node ast.Node, confidence float64, cat string, subcase string) {
130+
func (w lintDeferRule) newFailure(msg string, node ast.Node, confidence float64, cat, subcase string) {
130131
if !w.allow[subcase] {
131132
return
132133
}

rule/error-strings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type ErrorStringsRule struct{}
1717
func (r *ErrorStringsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
1818
var failures []lint.Failure
1919

20-
var errorFunctions = map[string]map[string]struct{}{
20+
errorFunctions := map[string]map[string]struct{}{
2121
"fmt": {
2222
"Errorf": {},
2323
},

rule/exported.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (r *ExportedRule) Name() string {
6161
return "exported"
6262
}
6363

64-
func (r *ExportedRule) getConf(args lint.Arguments) (checkPrivateReceivers bool, disableStutteringCheck bool, sayRepetitiveInsteadOfStutters bool) {
64+
func (r *ExportedRule) getConf(args lint.Arguments) (checkPrivateReceivers, disableStutteringCheck, sayRepetitiveInsteadOfStutters bool) {
6565
// if any, we expect a slice of strings as configuration
6666
if len(args) < 1 {
6767
return

rule/flag-param.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package rule
22

33
import (
44
"fmt"
5-
"github.com/mgechev/revive/lint"
65
"go/ast"
6+
7+
"github.com/mgechev/revive/lint"
78
)
89

910
// FlagParamRule lints given else constructs.

rule/function-length.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (r *FunctionLength) Name() string {
4343
return "function-length"
4444
}
4545

46-
func (r *FunctionLength) parseArguments(arguments lint.Arguments) (maxStmt int64, maxLines int64) {
46+
func (r *FunctionLength) parseArguments(arguments lint.Arguments) (maxStmt, maxLines int64) {
4747
if len(arguments) != 2 {
4848
panic(fmt.Sprintf(`invalid configuration for "function-length" rule, expected 2 arguments but got %d`, len(arguments)))
4949
}

rule/max-public-structs.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package rule
22

33
import (
44
"go/ast"
5-
65
"strings"
76

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

rule/range-val-in-closure.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ type rangeValInClosure struct {
3535
}
3636

3737
func (w rangeValInClosure) Visit(node ast.Node) ast.Visitor {
38-
3938
// Find the variables updated by the loop statement.
4039
var vars []*ast.Ident
4140
addVar := func(expr ast.Expr) {

rule/redefines-builtin-id.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package rule
22

33
import (
44
"fmt"
5-
"github.com/mgechev/revive/lint"
65
"go/ast"
76
"go/token"
7+
8+
"github.com/mgechev/revive/lint"
89
)
910

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

17-
var builtInConstAndVars = map[string]bool{
18+
builtInConstAndVars := map[string]bool{
1819
"true": true,
1920
"false": true,
2021
"iota": true,
2122
"nil": true,
2223
}
2324

24-
var builtFunctions = map[string]bool{
25+
builtFunctions := map[string]bool{
2526
"append": true,
2627
"cap": true,
2728
"close": true,
@@ -39,7 +40,7 @@ func (r *RedefinesBuiltinIDRule) Apply(file *lint.File, _ lint.Arguments) []lint
3940
"recover": true,
4041
}
4142

42-
var builtInTypes = map[string]bool{
43+
builtInTypes := map[string]bool{
4344
"ComplexType": true,
4445
"FloatType": true,
4546
"IntegerType": true,

rule/string-format.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ func (rule stringFormatSubrule) lintMessage(s string, node ast.Node) {
276276
rule.parent.onFailure(lint.Failure{
277277
Confidence: 1,
278278
Failure: failure,
279-
Node: node})
279+
Node: node,
280+
})
280281
}
281282

282283
// #endregion

rule/struct-tag.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ func (w lintStructTagRule) Visit(node ast.Node) ast.Visitor {
5353
}
5454

5555
return w
56-
5756
}
5857

5958
// checkTaggedField checks the tag of the given field.

rule/superfluous-else.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (r *SuperfluousElseRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fa
1818
failures = append(failures, failure)
1919
}
2020

21-
var branchingFunctions = map[string]map[string]bool{
21+
branchingFunctions := map[string]map[string]bool{
2222
"os": {"Exit": true},
2323
"log": {
2424
"Fatal": true,

rule/unreachable-code.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (r *UnreachableCodeRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fa
1616
failures = append(failures, failure)
1717
}
1818

19-
var branchingFunctions = map[string]map[string]bool{
19+
branchingFunctions := map[string]map[string]bool{
2020
"os": {"Exit": true},
2121
"log": {
2222
"Fatal": true,

0 commit comments

Comments
 (0)