mirror of
https://github.com/mgechev/revive.git
synced 2024-11-21 17:16:40 +02:00
refactor: enforce map and slice style (#1131)
This commit is contained in:
parent
1b4440c160
commit
0afba4ff15
@ -45,7 +45,7 @@ func (*Checkstyle) Format(failures <-chan lint.Failure, config lint.Config) (str
|
|||||||
}
|
}
|
||||||
fn := failure.GetFilename()
|
fn := failure.GetFilename()
|
||||||
if issues[fn] == nil {
|
if issues[fn] == nil {
|
||||||
issues[fn] = make([]issue, 0)
|
issues[fn] = []issue{}
|
||||||
}
|
}
|
||||||
issues[fn] = append(issues[fn], iss)
|
issues[fn] = append(issues[fn], iss)
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func (*Stylish) Format(failures <-chan lint.Failure, config lint.Config) (string
|
|||||||
ps = "problem"
|
ps = "problem"
|
||||||
}
|
}
|
||||||
|
|
||||||
fileReport := make(map[string][][]string)
|
fileReport := map[string][][]string{}
|
||||||
|
|
||||||
for _, row := range result {
|
for _, row := range result {
|
||||||
if _, ok := fileReport[row[0]]; !ok {
|
if _, ok := fileReport[row[0]]; !ok {
|
||||||
|
@ -140,10 +140,10 @@ const (
|
|||||||
var re = regexp.MustCompile(directiveRE)
|
var re = regexp.MustCompile(directiveRE)
|
||||||
|
|
||||||
func (f *File) disabledIntervals(rules []Rule, mustSpecifyDisableReason bool, failures chan Failure) disabledIntervalsMap {
|
func (f *File) disabledIntervals(rules []Rule, mustSpecifyDisableReason bool, failures chan Failure) disabledIntervalsMap {
|
||||||
enabledDisabledRulesMap := make(map[string][]enableDisableConfig)
|
enabledDisabledRulesMap := map[string][]enableDisableConfig{}
|
||||||
|
|
||||||
getEnabledDisabledIntervals := func() disabledIntervalsMap {
|
getEnabledDisabledIntervals := func() disabledIntervalsMap {
|
||||||
result := make(disabledIntervalsMap)
|
result := disabledIntervalsMap{}
|
||||||
|
|
||||||
for ruleName, disabledArr := range enabledDisabledRulesMap {
|
for ruleName, disabledArr := range enabledDisabledRulesMap {
|
||||||
ruleResult := []DisabledInterval{}
|
ruleResult := []DisabledInterval{}
|
||||||
|
@ -63,7 +63,7 @@ var (
|
|||||||
func (l *Linter) Lint(packages [][]string, ruleSet []Rule, config Config) (<-chan Failure, error) {
|
func (l *Linter) Lint(packages [][]string, ruleSet []Rule, config Config) (<-chan Failure, error) {
|
||||||
failures := make(chan Failure)
|
failures := make(chan Failure)
|
||||||
|
|
||||||
perModVersions := make(map[string]*goversion.Version)
|
perModVersions := map[string]*goversion.Version{}
|
||||||
perPkgVersions := make([]*goversion.Version, len(packages))
|
perPkgVersions := make([]*goversion.Version, len(packages))
|
||||||
for n, files := range packages {
|
for n, files := range packages {
|
||||||
if len(files) == 0 {
|
if len(files) == 0 {
|
||||||
|
@ -99,10 +99,10 @@ func (p *Package) TypeCheck() error {
|
|||||||
Importer: importer.Default(),
|
Importer: importer.Default(),
|
||||||
}
|
}
|
||||||
info := &types.Info{
|
info := &types.Info{
|
||||||
Types: make(map[ast.Expr]types.TypeAndValue),
|
Types: map[ast.Expr]types.TypeAndValue{},
|
||||||
Defs: make(map[*ast.Ident]types.Object),
|
Defs: map[*ast.Ident]types.Object{},
|
||||||
Uses: make(map[*ast.Ident]types.Object),
|
Uses: map[*ast.Ident]types.Object{},
|
||||||
Scopes: make(map[ast.Node]*types.Scope),
|
Scopes: map[ast.Node]*types.Scope{},
|
||||||
}
|
}
|
||||||
var anyFile *File
|
var anyFile *File
|
||||||
var astFiles []*ast.File
|
var astFiles []*ast.File
|
||||||
@ -162,7 +162,7 @@ func (w *walker) Visit(n ast.Node) ast.Visitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Package) scanSortable() {
|
func (p *Package) scanSortable() {
|
||||||
p.sortable = make(map[string]bool)
|
p.sortable = map[string]bool{}
|
||||||
|
|
||||||
// bitfield for which methods exist on each type.
|
// bitfield for which methods exist on each type.
|
||||||
const (
|
const (
|
||||||
@ -171,7 +171,7 @@ func (p *Package) scanSortable() {
|
|||||||
bfSwap
|
bfSwap
|
||||||
)
|
)
|
||||||
nmap := map[string]int{"Len": bfLen, "Less": bfLess, "Swap": bfSwap}
|
nmap := map[string]int{"Len": bfLen, "Less": bfLess, "Swap": bfSwap}
|
||||||
has := make(map[string]int)
|
has := map[string]int{}
|
||||||
for _, f := range p.files {
|
for _, f := range p.files {
|
||||||
ast.Walk(&walker{nmap, has}, f.AST)
|
ast.Walk(&walker{nmap, has}, f.AST)
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,10 @@ warningCode = 1
|
|||||||
[rule.dot-imports]
|
[rule.dot-imports]
|
||||||
[rule.empty-block]
|
[rule.empty-block]
|
||||||
[rule.empty-lines]
|
[rule.empty-lines]
|
||||||
|
[rule.enforce-map-style]
|
||||||
|
arguments = ["literal"]
|
||||||
|
[rule.enforce-slice-style]
|
||||||
|
arguments = ["literal"]
|
||||||
[rule.error-naming]
|
[rule.error-naming]
|
||||||
[rule.error-return]
|
[rule.error-return]
|
||||||
[rule.error-strings]
|
[rule.error-strings]
|
||||||
|
@ -52,11 +52,11 @@ func (r *AddConstantRule) Apply(file *lint.File, arguments lint.Arguments) []lin
|
|||||||
|
|
||||||
w := &lintAddConstantRule{
|
w := &lintAddConstantRule{
|
||||||
onFailure: onFailure,
|
onFailure: onFailure,
|
||||||
strLits: make(map[string]int),
|
strLits: map[string]int{},
|
||||||
strLitLimit: r.strLitLimit,
|
strLitLimit: r.strLitLimit,
|
||||||
allowList: r.allowList,
|
allowList: r.allowList,
|
||||||
ignoreFunctions: r.ignoreFunctions,
|
ignoreFunctions: r.ignoreFunctions,
|
||||||
structTags: make(map[*ast.BasicLit]struct{}),
|
structTags: map[*ast.BasicLit]struct{}{},
|
||||||
}
|
}
|
||||||
|
|
||||||
ast.Walk(w, file.AST)
|
ast.Walk(w, file.AST)
|
||||||
|
@ -35,7 +35,7 @@ func (ps *packages) methodNames(lp *lint.Package) pkgMethods {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pkgm := pkgMethods{pkg: lp, methods: make(map[string]map[string]*referenceMethod), mu: &sync.Mutex{}}
|
pkgm := pkgMethods{pkg: lp, methods: map[string]map[string]*referenceMethod{}, mu: &sync.Mutex{}}
|
||||||
ps.pkgs = append(ps.pkgs, pkgm)
|
ps.pkgs = append(ps.pkgs, pkgm)
|
||||||
|
|
||||||
return pkgm
|
return pkgm
|
||||||
|
@ -42,7 +42,7 @@ func (*DotImportsRule) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *DotImportsRule) configure(arguments lint.Arguments) {
|
func (r *DotImportsRule) configure(arguments lint.Arguments) {
|
||||||
r.allowedPackages = make(allowPackages)
|
r.allowedPackages = allowPackages{}
|
||||||
if len(arguments) == 0 {
|
if len(arguments) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ func (*EmptyBlockRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
|
|||||||
failures = append(failures, failure)
|
failures = append(failures, failure)
|
||||||
}
|
}
|
||||||
|
|
||||||
w := lintEmptyBlock{make(map[*ast.BlockStmt]bool), onFailure}
|
w := lintEmptyBlock{map[*ast.BlockStmt]bool{}, onFailure}
|
||||||
ast.Walk(w, file.AST)
|
ast.Walk(w, file.AST)
|
||||||
return failures
|
return failures
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ func (r *ExportedRule) Apply(file *lint.File, args lint.Arguments) []lint.Failur
|
|||||||
onFailure: func(failure lint.Failure) {
|
onFailure: func(failure lint.Failure) {
|
||||||
failures = append(failures, failure)
|
failures = append(failures, failure)
|
||||||
},
|
},
|
||||||
genDeclMissingComments: make(map[*ast.GenDecl]bool),
|
genDeclMissingComments: map[*ast.GenDecl]bool{},
|
||||||
stuttersMsg: r.stuttersMsg,
|
stuttersMsg: r.stuttersMsg,
|
||||||
disabledChecks: r.disabledChecks,
|
disabledChecks: r.disabledChecks,
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ func parseInstructions(t *testing.T, filename string, src []byte) []instruction
|
|||||||
}
|
}
|
||||||
if line == "OK" && ins == nil {
|
if line == "OK" && ins == nil {
|
||||||
// so our return value will be non-nil
|
// so our return value will be non-nil
|
||||||
ins = make([]instruction, 0)
|
ins = []instruction{}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch extractDataMode(line) {
|
switch extractDataMode(line) {
|
||||||
|
Loading…
Reference in New Issue
Block a user