Skip to content

Commit 9b479ee

Browse files
elliotsdaixiang0☃ Elliot Shepherd
authored
Small fixes for issues found when running against our codebase (#10)
* fix wrong exit code Signed-off-by: Xiang Dai <[email protected]> * remove duplicate blank in comment Signed-off-by: Xiang Dai <[email protected]> * Remove extra space Signed-off-by: Xiang Dai <[email protected]> * Refactor gci.Run Signed-off-by: Xiang Dai <[email protected]> * Small fixes for issues found when running against our codebase * Update for latest changes Co-authored-by: Xiang Dai <[email protected]> Co-authored-by: ☃ Elliot Shepherd <[email protected]>
1 parent 7eb50f3 commit 9b479ee

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pkg/gci/gci.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (p *pkg) fmt() []byte {
126126
ret = append(ret, linebreak)
127127
}
128128
}
129-
if ret[len(ret)-1] == linebreak {
129+
if len(ret) > 0 && ret[len(ret)-1] == linebreak {
130130
ret = ret[:len(ret)-1]
131131
}
132132

@@ -353,6 +353,11 @@ func Run(filename string, set *FlagSet) ([]byte, []byte, error) {
353353
return nil, nil, nil
354354
}
355355
end := bytes.Index(src[start:], importEndFlag) + start
356+
357+
// in case import flags are part of a codegen template, or otherwise "wrong"
358+
if start+len(importStartFlag) > end {
359+
return nil, nil, nil
360+
}
356361

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

0 commit comments

Comments
 (0)