Skip to content

Commit

Permalink
Small fixes for issues found when running against our codebase (#10)
Browse files Browse the repository at this point in the history
* fix wrong exit code

Signed-off-by: Xiang Dai <long0dai@foxmail.com>

* remove duplicate blank in comment

Signed-off-by: Xiang Dai <long0dai@foxmail.com>

* Remove extra space

Signed-off-by: Xiang Dai <long0dai@foxmail.com>

* Refactor gci.Run

Signed-off-by: Xiang Dai <long0dai@foxmail.com>

* Small fixes for issues found when running against our codebase

* Update for latest changes

Co-authored-by: Xiang Dai <long0dai@foxmail.com>
Co-authored-by: ☃ Elliot Shepherd <elliot@identitii.com>
  • Loading branch information
3 people authored Jun 7, 2021
1 parent 7eb50f3 commit 9b479ee
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/gci/gci.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (p *pkg) fmt() []byte {
ret = append(ret, linebreak)
}
}
if ret[len(ret)-1] == linebreak {
if len(ret) > 0 && ret[len(ret)-1] == linebreak {
ret = ret[:len(ret)-1]
}

Expand Down Expand Up @@ -353,6 +353,11 @@ func Run(filename string, set *FlagSet) ([]byte, []byte, error) {
return nil, nil, nil
}
end := bytes.Index(src[start:], importEndFlag) + start

// in case import flags are part of a codegen template, or otherwise "wrong"
if start+len(importStartFlag) > end {
return nil, nil, nil
}

ret := bytes.Split(src[start+len(importStartFlag):end], []byte(linebreak))

Expand Down

0 comments on commit 9b479ee

Please sign in to comment.