Skip to content

Commit

Permalink
fix: fix static check failures
Browse files Browse the repository at this point in the history
  • Loading branch information
voidint committed Nov 22, 2023
1 parent c324fc7 commit e8cab4b
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 23 deletions.
18 changes: 10 additions & 8 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/urfave/cli/v2"
"github.com/voidint/g/build"
"github.com/voidint/g/version"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

var (
Expand All @@ -37,11 +39,11 @@ func Run() {
ghomeDir = ghome()
goroot = filepath.Join(ghomeDir, "go")
downloadsDir = filepath.Join(ghomeDir, "downloads")
if err = os.MkdirAll(downloadsDir, 0755); err != nil {
if err = os.MkdirAll(downloadsDir, 0750); err != nil {
return err
}
versionsDir = filepath.Join(ghomeDir, "versions")
return os.MkdirAll(versionsDir, 0755)
return os.MkdirAll(versionsDir, 0750)
}
app.Commands = commands

Expand Down Expand Up @@ -132,7 +134,7 @@ type versionOut struct {
}

const (
rawMode = 0
textMode = 0
jsonMode = 1
)

Expand All @@ -156,18 +158,18 @@ func render(mode uint8, installed map[string]bool, items []*version.Version, out

enc := json.NewEncoder(out)
enc.SetIndent("", " ")
enc.Encode(&vs)
_ = enc.Encode(&vs)

default:
for _, item := range items {
if inused, found := installed[item.Name()]; found {
if inused {
color.New(color.FgGreen).Fprintf(out, "* %s\n", item.Name())
_, _ = color.New(color.FgGreen).Fprintf(out, "* %s\n", item.Name())
} else {
color.New(color.FgGreen).Fprintf(out, " %s\n", item.Name())
_, _ = color.New(color.FgGreen).Fprintf(out, " %s\n", item.Name())
}
} else {
fmt.Fprintf(out, " %s\n", item.Name())
_, _ = fmt.Fprintf(out, " %s\n", item.Name())
}
}
}
Expand All @@ -187,7 +189,7 @@ func wrapstring(str string) string {
}
words := strings.Fields(str)
if len(words) > 0 {
words[0] = strings.Title(words[0])
words[0] = cases.Title(language.English).String(words[0])
}
return fmt.Sprintf("[g] %s", strings.Join(words, " "))
}
2 changes: 1 addition & 1 deletion cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Test_render(t *testing.T) {
}
sort.Sort(version.Collection(items))

render(rawMode, map[string]bool{"1.8.1": true}, items, &buf)
render(textMode, map[string]bool{"1.8.1": true}, items, &buf)
assert.Equal(t, " 1.7\n* 1.8.1\n 1.10beta2\n 1.19beta1\n 1.21rc4\n 1.21.0\n", buf.String())
})
}
Expand Down
4 changes: 2 additions & 2 deletions cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var (
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Usage: "Output format. One of: (raw, json).",
Usage: "Output format. One of: (text, json).",
},
},
Action: list,
Expand All @@ -27,7 +27,7 @@ var (
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Usage: "Output format. One of: (raw, json).",
Usage: "Output format. One of: (text, json).",
},
},
Action: listRemote,
Expand Down
2 changes: 1 addition & 1 deletion cli/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func list(ctx *cli.Context) (err error) {
case "json":
renderMode = jsonMode
default:
renderMode = rawMode
renderMode = textMode
}

render(renderMode, installed(), items, ansi.NewAnsiStdout())
Expand Down
2 changes: 1 addition & 1 deletion cli/ls_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func listRemote(ctx *cli.Context) (err error) {
case "json":
renderMode = jsonMode
default:
renderMode = rawMode
renderMode = textMode
}

render(renderMode, installed(), vs, ansi.NewAnsiStdout())
Expand Down
2 changes: 1 addition & 1 deletion collector/aliyun/aliyun_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (c *Collector) ArchivedVersions() (items []*version.Version, err error) {
func (c *Collector) AllVersions() (vers []*version.Version, err error) {
items := c.findGoFileItems(c.doc.Find(".table"))
if len(items) == 0 {
return make([]*version.Version, 0, 0), nil
return make([]*version.Version, 0), nil
}
if vers, err = convert2Versions(items); err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/stretchr/testify v1.8.4
github.com/urfave/cli/v2 v2.25.7
github.com/voidint/go-update v1.0.0
golang.org/x/text v0.14.0
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
Expand Down
8 changes: 4 additions & 4 deletions pkg/errs/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewPackageNotFoundError(kind, goos, goarch string) error {
}

func (e PackageNotFoundError) Error() string {
return fmt.Sprintf("Package not found [%s,%s,%s]", e.goos, e.goarch, e.kind)
return fmt.Sprintf("package not found [%s,%s,%s]", e.goos, e.goarch, e.kind)
}

// VersionNotFoundError 版本不存在错误
Expand All @@ -66,7 +66,7 @@ func NewVersionNotFoundError(version, goos, goarch string) error {
}

func (e VersionNotFoundError) Error() string {
return fmt.Sprintf("Version not found %q [%s,%s]", e.version, e.goos, e.goarch)
return fmt.Sprintf("version not found %q [%s,%s]", e.version, e.goos, e.goarch)
}

func (e VersionNotFoundError) Version() string {
Expand All @@ -87,7 +87,7 @@ func NewMalformedVersionError(version string, err error) error {
}

func (e MalformedVersionError) Error() string {
return fmt.Sprintf("Malformed version string %q", e.version)
return fmt.Sprintf("malformed version string %q", e.version)
}

func (e MalformedVersionError) Err() error {
Expand Down Expand Up @@ -146,7 +146,7 @@ func NewDownloadError(url string, err error) error {
// Error 返回错误字符串
func (e DownloadError) Error() string {
var buf strings.Builder
buf.WriteString(fmt.Sprintf("Resource(%s) download failed", e.url))
buf.WriteString(fmt.Sprintf("resource(%s) download failed", e.url))
if e.err != nil {
buf.WriteString(" ==> " + e.err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/errs/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ func TestDownloadError(t *testing.T) {
assert.NotNil(t, e)
assert.Equal(t, url, e.URL())
assert.Equal(t, core, e.Err())
assert.Equal(t, fmt.Sprintf("Resource(%s) download failed ==> %s", url, core.Error()), e.Error())
assert.Equal(t, fmt.Sprintf("resource(%s) download failed ==> %s", url, core.Error()), e.Error())
})
}
4 changes: 2 additions & 2 deletions version/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func NewFinder(items []*Version, opts ...func(fdr *Finder)) *Finder {
items: items,
}

if opts != nil {
for _, setter := range opts {
for _, setter := range opts {
if opts != nil {
setter(&fdr)
}
}
Expand Down
4 changes: 2 additions & 2 deletions version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestVerifyChecksum(t *testing.T) {
})

t.Run("校验和不匹配", func(t *testing.T) {
f.Seek(0, 0)
_, _ = f.Seek(0, 0)
h := sha1.New()
_, err = io.Copy(h, f)
assert.Nil(t, err)
Expand All @@ -158,7 +158,7 @@ func TestVerifyChecksum(t *testing.T) {
})

t.Run("SHA1", func(t *testing.T) {
f.Seek(0, 0)
_, _ = f.Seek(0, 0)
h := sha1.New()
_, err = io.Copy(h, f)
assert.Nil(t, err)
Expand Down

0 comments on commit e8cab4b

Please sign in to comment.