Skip to content

Commit

Permalink
Renaming some variables to improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
iwankgb committed Nov 15, 2020
1 parent 46a8881 commit fcec674
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions api.go
Expand Up @@ -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,
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/goconst/main.go
Expand Up @@ -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`,
Expand Down Expand Up @@ -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,
))
}
}
Expand Down
6 changes: 3 additions & 3 deletions parser.go
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions visitor.go
Expand Up @@ -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),
})
Expand Down
6 changes: 3 additions & 3 deletions visitor_test.go
Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand All @@ -137,7 +137,7 @@ func TestAddString(t *testing.T) {
},
"barbaz": {
Total: 3,
Violations: map[Type][]ExtendedPos{
Positions: map[Type][]ExtendedPos{
Case: {
{
Position: token.Position{},
Expand Down

0 comments on commit fcec674

Please sign in to comment.