Skip to content

Commit

Permalink
Avoid some var aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
metal3d committed Jun 22, 2023
1 parent d0469a4 commit 69d87de
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions ordering/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"sort"
Expand All @@ -26,28 +27,26 @@ type ReorderConfig struct {
func ReorderSource(opt ReorderConfig) (string, error) {
// in all cases, we must return the original source code if an error occurs
// get the content of the file
filename := opt.Filename
reorderStructs := opt.ReorderStructs

var content []byte
var err error
if opt.Src == nil || len(opt.Src.([]byte)) == 0 {
content, err = ioutil.ReadFile(filename)
content, err = ioutil.ReadFile(opt.Filename)
if err != nil {
return "", err
}
} else {
content = opt.Src.([]byte)
}

info, err := Parse(filename, content)
info, err := Parse(opt.Filename, content)

if err != nil {
return string(content), errors.New("Error parsing source: " + err.Error())
}

if len(info.Structs) == 0 {
return string(content), errors.New("No structs found in " + filename + ", cannot reorder")
return string(content), errors.New("No structs found in " + opt.Filename + ", cannot reorder")
}

// sort methods by name
Expand All @@ -65,9 +64,10 @@ func ReorderSource(opt ReorderConfig) (string, error) {

structNames := make([]string, 0, len(info.Methods))
for _, s := range info.Structs {
log.Println("s.Name", s.Name)
structNames = append(structNames, s.Name)
}
if reorderStructs {
if opt.ReorderStructs {
sort.Strings(structNames)
}

Expand Down Expand Up @@ -155,7 +155,7 @@ func ReorderSource(opt ReorderConfig) (string, error) {
}

if opt.Diff {
return doDiff(content, newcontent, filename)
return doDiff(content, newcontent, opt.Filename)
}
return string(newcontent), nil
}

0 comments on commit 69d87de

Please sign in to comment.