1
0
mirror of https://github.com/mgechev/revive.git synced 2025-02-03 13:11:25 +02:00

format sources w/ gofumpt (#643)

Signed-off-by: subham sarkar <sarkar.subhams2@gmail.com>
This commit is contained in:
subham sarkar 2022-03-02 12:54:55 +05:30 committed by GitHub
parent 54d9a09ab5
commit 577441d60c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 39 additions and 37 deletions

View File

@ -180,7 +180,7 @@ const defaultConfidence = 0.8
// GetConfig yields the configuration // GetConfig yields the configuration
func GetConfig(configPath string) (*lint.Config, error) { func GetConfig(configPath string) (*lint.Config, error) {
var config = &lint.Config{} config := &lint.Config{}
switch { switch {
case configPath != "": case configPath != "":
config.Confidence = defaultConfidence config.Confidence = defaultConfidence

View File

@ -3,8 +3,9 @@ package formatter
import ( import (
"bytes" "bytes"
"encoding/xml" "encoding/xml"
"github.com/mgechev/revive/lint"
plainTemplate "text/template" plainTemplate "text/template"
"github.com/mgechev/revive/lint"
) )
// Checkstyle is an implementation of the Formatter interface // Checkstyle is an implementation of the Formatter interface
@ -29,7 +30,7 @@ type issue struct {
// Format formats the failures gotten from the lint. // Format formats the failures gotten from the lint.
func (f *Checkstyle) Format(failures <-chan lint.Failure, config lint.Config) (string, error) { 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 { for failure := range failures {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
xml.Escape(buf, []byte(failure.Failure)) xml.Escape(buf, []byte(failure.Failure))

View File

@ -34,8 +34,8 @@ func formatFailure(failure lint.Failure, severity lint.Severity) []string {
// Format formats the failures gotten from the lint. // Format formats the failures gotten from the lint.
func (f *Stylish) Format(failures <-chan lint.Failure, config lint.Config) (string, error) { func (f *Stylish) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
var result [][]string var result [][]string
var totalErrors = 0 totalErrors := 0
var total = 0 total := 0
for f := range failures { for f := range failures {
total++ total++

View File

@ -126,11 +126,13 @@ type enableDisableConfig struct {
position int position int
} }
const directiveRE = `^//[\s]*revive:(enable|disable)(?:-(line|next-line))?(?::([^\s]+))?[\s]*(?: (.+))?$` const (
const directivePos = 1 directiveRE = `^//[\s]*revive:(enable|disable)(?:-(line|next-line))?(?::([^\s]+))?[\s]*(?: (.+))?$`
const modifierPos = 2 directivePos = 1
const rulesPos = 3 modifierPos = 2
const reasonPos = 4 rulesPos = 3
reasonPos = 4
)
var re = regexp.MustCompile(directiveRE) var re = regexp.MustCompile(directiveRE)

View File

@ -159,5 +159,6 @@ func getPositionInvalidFile(filename, s string) FailurePosition {
Filename: filename, Filename: filename,
Line: line, Line: line,
Column: column, Column: column,
}} },
}
} }

View File

@ -23,7 +23,7 @@ type AbstractRule struct {
} }
// ToFailurePosition returns the failure position. // 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{ return FailurePosition{
Start: file.ToPosition(start), Start: file.ToPosition(start),
End: file.ToPosition(end), End: file.ToPosition(end),

View File

@ -22,7 +22,7 @@ func newWhiteList() whiteList {
return map[string]map[string]bool{kindINT: {}, kindFLOAT: {}, kindSTRING: {}} 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, ",") elems := strings.Split(list, ",")
for _, e := range elems { for _, e := range elems {
wl[kind][e] = true wl[kind][e] = true
@ -120,7 +120,6 @@ func (w lintAddConstantRule) Visit(node ast.Node) ast.Visitor {
} }
return w return w
} }
func (w lintAddConstantRule) checkStrLit(n *ast.BasicLit) { func (w lintAddConstantRule) checkStrLit(n *ast.BasicLit) {

View File

@ -63,7 +63,7 @@ func (w *lintBoolLiteral) Visit(node ast.Node) ast.Visitor {
return w 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{ w.onFailure(lint.Failure{
Confidence: 1, Confidence: 1,
Node: node, Node: node,

View File

@ -16,7 +16,7 @@ func (r *CallToGCRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
failures = append(failures, failure) failures = append(failures, failure)
} }
var gcTriggeringFunctions = map[string]map[string]bool{ gcTriggeringFunctions := map[string]map[string]bool{
"runtime": {"GC": true}, "runtime": {"GC": true},
} }

View File

@ -3,7 +3,6 @@ package rule
import ( import (
"fmt" "fmt"
"go/ast" "go/ast"
"strings" "strings"
"sync" "sync"
@ -71,7 +70,7 @@ func (r *ConfusingNamingRule) Name() string {
return "confusing-naming" 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) { func checkMethodName(holder string, id *ast.Ident, w *lintConfusingNames) {
if id.Name == "init" && holder == defaultStructName { if id.Name == "init" && holder == defaultStructName {
// ignore init functions // ignore init functions
@ -128,7 +127,7 @@ type lintConfusingNames struct {
const defaultStructName = "_" // used to map functions 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 { func getStructName(r *ast.FieldList) string {
result := defaultStructName result := defaultStructName

View File

@ -15,7 +15,6 @@ type ContextAsArgumentRule struct {
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *ContextAsArgumentRule) Apply(file *lint.File, args lint.Arguments) []lint.Failure { func (r *ContextAsArgumentRule) Apply(file *lint.File, args lint.Arguments) []lint.Failure {
if r.allowTypesLUT == nil { if r.allowTypesLUT == nil {
r.allowTypesLUT = getAllowTypesFromArguments(args) r.allowTypesLUT = getAllowTypesFromArguments(args)
} }

View File

@ -17,7 +17,7 @@ func (r *DeepExitRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
failures = append(failures, failure) failures = append(failures, failure)
} }
var exitFunctions = map[string]map[string]bool{ exitFunctions := map[string]map[string]bool{
"os": {"Exit": true}, "os": {"Exit": true},
"syscall": {"Exit": true}, "syscall": {"Exit": true},
"log": { "log": {

View File

@ -122,11 +122,12 @@ func (w lintDeferRule) visitSubtree(n ast.Node, inADefer, inALoop, inAFuncLit bo
inADefer: inADefer, inADefer: inADefer,
inALoop: inALoop, inALoop: inALoop,
inAFuncLit: inAFuncLit, inAFuncLit: inAFuncLit,
allow: w.allow} allow: w.allow,
}
ast.Walk(nw, n) 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] { if !w.allow[subcase] {
return return
} }

View File

@ -17,7 +17,7 @@ type ErrorStringsRule struct{}
func (r *ErrorStringsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (r *ErrorStringsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
var errorFunctions = map[string]map[string]struct{}{ errorFunctions := map[string]map[string]struct{}{
"fmt": { "fmt": {
"Errorf": {}, "Errorf": {},
}, },

View File

@ -61,7 +61,7 @@ func (r *ExportedRule) Name() string {
return "exported" 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 any, we expect a slice of strings as configuration
if len(args) < 1 { if len(args) < 1 {
return return

View File

@ -2,8 +2,9 @@ package rule
import ( import (
"fmt" "fmt"
"github.com/mgechev/revive/lint"
"go/ast" "go/ast"
"github.com/mgechev/revive/lint"
) )
// FlagParamRule lints given else constructs. // FlagParamRule lints given else constructs.

View File

@ -43,7 +43,7 @@ func (r *FunctionLength) Name() string {
return "function-length" 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 { if len(arguments) != 2 {
panic(fmt.Sprintf(`invalid configuration for "function-length" rule, expected 2 arguments but got %d`, len(arguments))) panic(fmt.Sprintf(`invalid configuration for "function-length" rule, expected 2 arguments but got %d`, len(arguments)))
} }

View File

@ -2,7 +2,6 @@ package rule
import ( import (
"go/ast" "go/ast"
"strings" "strings"
"github.com/mgechev/revive/lint" "github.com/mgechev/revive/lint"

View File

@ -35,7 +35,6 @@ type rangeValInClosure struct {
} }
func (w rangeValInClosure) Visit(node ast.Node) ast.Visitor { func (w rangeValInClosure) Visit(node ast.Node) ast.Visitor {
// Find the variables updated by the loop statement. // Find the variables updated by the loop statement.
var vars []*ast.Ident var vars []*ast.Ident
addVar := func(expr ast.Expr) { addVar := func(expr ast.Expr) {

View File

@ -2,9 +2,10 @@ package rule
import ( import (
"fmt" "fmt"
"github.com/mgechev/revive/lint"
"go/ast" "go/ast"
"go/token" "go/token"
"github.com/mgechev/revive/lint"
) )
// RedefinesBuiltinIDRule warns when a builtin identifier is shadowed. // RedefinesBuiltinIDRule warns when a builtin identifier is shadowed.
@ -14,14 +15,14 @@ type RedefinesBuiltinIDRule struct{}
func (r *RedefinesBuiltinIDRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (r *RedefinesBuiltinIDRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
var builtInConstAndVars = map[string]bool{ builtInConstAndVars := map[string]bool{
"true": true, "true": true,
"false": true, "false": true,
"iota": true, "iota": true,
"nil": true, "nil": true,
} }
var builtFunctions = map[string]bool{ builtFunctions := map[string]bool{
"append": true, "append": true,
"cap": true, "cap": true,
"close": true, "close": true,
@ -39,7 +40,7 @@ func (r *RedefinesBuiltinIDRule) Apply(file *lint.File, _ lint.Arguments) []lint
"recover": true, "recover": true,
} }
var builtInTypes = map[string]bool{ builtInTypes := map[string]bool{
"ComplexType": true, "ComplexType": true,
"FloatType": true, "FloatType": true,
"IntegerType": true, "IntegerType": true,

View File

@ -276,7 +276,8 @@ func (rule stringFormatSubrule) lintMessage(s string, node ast.Node) {
rule.parent.onFailure(lint.Failure{ rule.parent.onFailure(lint.Failure{
Confidence: 1, Confidence: 1,
Failure: failure, Failure: failure,
Node: node}) Node: node,
})
} }
// #endregion // #endregion

View File

@ -53,7 +53,6 @@ func (w lintStructTagRule) Visit(node ast.Node) ast.Visitor {
} }
return w return w
} }
// checkTaggedField checks the tag of the given field. // checkTaggedField checks the tag of the given field.

View File

@ -18,7 +18,7 @@ func (r *SuperfluousElseRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fa
failures = append(failures, failure) failures = append(failures, failure)
} }
var branchingFunctions = map[string]map[string]bool{ branchingFunctions := map[string]map[string]bool{
"os": {"Exit": true}, "os": {"Exit": true},
"log": { "log": {
"Fatal": true, "Fatal": true,

View File

@ -16,7 +16,7 @@ func (r *UnreachableCodeRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fa
failures = append(failures, failure) failures = append(failures, failure)
} }
var branchingFunctions = map[string]map[string]bool{ branchingFunctions := map[string]map[string]bool{
"os": {"Exit": true}, "os": {"Exit": true},
"log": { "log": {
"Fatal": true, "Fatal": true,