From fcec674b071d91bd24e85a2e73b3eba2f20f57ba Mon Sep 17 00:00:00 2001 From: "Maciej \"Iwan\" Iwanowski" Date: Sun, 15 Nov 2020 20:05:34 +0100 Subject: [PATCH] Renaming some variables to improve readability --- api.go | 8 ++++---- cmd/goconst/main.go | 10 +++++----- parser.go | 6 +++--- visitor.go | 4 ++-- visitor_test.go | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/api.go b/api.go index cf86686..a53725f 100644 --- a/api.go +++ b/api.go @@ -52,12 +52,12 @@ func Run(files []*ast.File, fset *token.FileSet, cfg *Config) ([]Issue, error) { func buildIssues(p *Parser, issues []Issue) []Issue { //return nil - for str, results := range p.strs { - for typ, violations := range results.Violations { - violation := violations[0] + for str, violations := range p.strs { + for typ, positions := range violations.Positions { + violation := positions[0] i := Issue{ Pos: violation.Position, - OccurrencesCount: len(violations), + OccurrencesCount: len(positions), Str: str, Typ: typ, } diff --git a/cmd/goconst/main.go b/cmd/goconst/main.go index 453e806..bdf2312 100644 --- a/cmd/goconst/main.go +++ b/cmd/goconst/main.go @@ -122,7 +122,7 @@ func printOutput(strs goconst.Strings, consts goconst.Constants, output string) } case "text": for str, violations := range strs { - for _, positions := range violations.Violations { + for _, positions := range violations.Positions { for _, position := range positions { fmt.Printf( `%s:%d:%d:%d other occurrence(s) of "%s" found in: %s`, @@ -154,13 +154,13 @@ func printOutput(strs goconst.Strings, consts goconst.Constants, output string) func occurrences(item *goconst.Violations, current goconst.ExtendedPos) string { occurrences := []string{} - for _, violations := range item.Violations { - for _, xpos := range violations { - if xpos == current { + for _, positions := range item.Positions { + for _, position := range positions { + if position == current { continue } occurrences = append(occurrences, fmt.Sprintf( - "%s:%d:%d", xpos.Filename, xpos.Line, xpos.Column, + "%s:%d:%d", position.Filename, position.Line, position.Column, )) } } diff --git a/parser.go b/parser.go index 550a70c..a05e938 100644 --- a/parser.go +++ b/parser.go @@ -92,7 +92,7 @@ func (p *Parser) ParseTree() (Strings, Constants, error) { func (p *Parser) ProcessResults() { for str, item := range p.strs { // Filter out items whose occurrences don't match the min value - if len(item.Violations) < p.minOccurrences { + if len(item.Positions) < p.minOccurrences { delete(p.strs, str) } @@ -152,8 +152,8 @@ func (p *Parser) parseDir(dir string) error { type Strings map[string]*Violations type Violations struct { - Total int - Violations map[Type][]ExtendedPos + Total int + Positions map[Type][]ExtendedPos } type Constants map[string]ConstType diff --git a/visitor.go b/visitor.go index 5ec00ee..36ca4e6 100644 --- a/visitor.go +++ b/visitor.go @@ -129,10 +129,10 @@ func (v *treeVisitor) addString(str string, pos token.Pos, typ Type) { _, ok := v.p.strs[str] if !ok { v.p.strs[str] = &Violations{ - Violations: map[Type][]ExtendedPos{}, + Positions: map[Type][]ExtendedPos{}, } } - v.p.strs[str].Violations[typ] = append(v.p.strs[str].Violations[typ], ExtendedPos{ + v.p.strs[str].Positions[typ] = append(v.p.strs[str].Positions[typ], ExtendedPos{ packageName: v.packageName, Position: v.fileSet.Position(pos), }) diff --git a/visitor_test.go b/visitor_test.go index 75b7cf1..dbd8446 100644 --- a/visitor_test.go +++ b/visitor_test.go @@ -58,7 +58,7 @@ func TestAddString(t *testing.T) { Strings{ "foobar": { Total: 3, - Violations: map[Type][]ExtendedPos{ + Positions: map[Type][]ExtendedPos{ Assignment: { { Position: token.Position{}, @@ -116,7 +116,7 @@ func TestAddString(t *testing.T) { Strings{ "foobar": { Total: 3, - Violations: map[Type][]ExtendedPos{ + Positions: map[Type][]ExtendedPos{ Assignment: { { Position: token.Position{}, @@ -137,7 +137,7 @@ func TestAddString(t *testing.T) { }, "barbaz": { Total: 3, - Violations: map[Type][]ExtendedPos{ + Positions: map[Type][]ExtendedPos{ Case: { { Position: token.Position{},