chore: use go fix to enhance codebase (#29)
This pull request modernizes the codebase by adopting Go 1.21+ features, including built-in functions like min and max, standard library iterators such as strings.SplitSeq and strings.FieldsSeq, utility functions like maps.Copy and slices.Contains, and string manipulation helpers like strings.Cut and strings.CutPrefix. Feedback is provided on a test file where the usage of strings.Builder can be further optimized to avoid unnecessary string allocations during concatenation. `go fix -diff ./...`
This commit is contained in:
+10
-10
@@ -8,8 +8,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
_ "github.com/versenilvis/iris/commands"
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
)
|
||||
|
||||
// setupGitRepo creates a real git repo in a temp dir with:
|
||||
@@ -188,7 +188,6 @@ func TestGitSuggestions(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
t.Run("branch with slash is suggested correctly", func(t *testing.T) {
|
||||
res := core.Lookup("git checkout ")
|
||||
found := false
|
||||
@@ -204,13 +203,14 @@ func TestGitSuggestions(t *testing.T) {
|
||||
|
||||
t.Run("remote branches suggested for push", func(t *testing.T) {
|
||||
res := core.Lookup("git push origin ")
|
||||
cmdStr := ""
|
||||
var cmdStr strings.Builder
|
||||
for _, r := range res {
|
||||
cmdStr += r.Cmd + " "
|
||||
cmdStr.WriteString(r.Cmd)
|
||||
cmdStr.WriteByte(' ')
|
||||
}
|
||||
// should have at least dev or main from branch list
|
||||
if !strings.Contains(cmdStr, "dev") && !strings.Contains(cmdStr, "main") {
|
||||
t.Errorf("git push origin should suggest local branches, got: %s", cmdStr)
|
||||
if !strings.Contains(cmdStr.String(), "dev") && !strings.Contains(cmdStr.String(), "main") {
|
||||
t.Errorf("git push origin should suggest local branches, got: %s", cmdStr.String())
|
||||
}
|
||||
})
|
||||
|
||||
@@ -226,8 +226,8 @@ func TestGitSuggestions(t *testing.T) {
|
||||
res := core.Lookup("git checkout ")
|
||||
for _, r := range res {
|
||||
// the suggestion should not contain the active branch as a standalone word
|
||||
parts := strings.Fields(r.Cmd)
|
||||
for _, p := range parts {
|
||||
parts := strings.FieldsSeq(r.Cmd)
|
||||
for p := range parts {
|
||||
if p == activeBranch {
|
||||
t.Errorf("git checkout should not suggest active branch '%s', got: %s", activeBranch, r.Cmd)
|
||||
}
|
||||
@@ -365,8 +365,8 @@ func TestGitSuggestions(t *testing.T) {
|
||||
|
||||
res := core.Lookup("git -c core.pager=cat checkout ")
|
||||
for _, r := range res {
|
||||
parts := strings.Fields(r.Cmd)
|
||||
for _, p := range parts {
|
||||
parts := strings.FieldsSeq(r.Cmd)
|
||||
for p := range parts {
|
||||
if p == activeBranch {
|
||||
t.Errorf("git -c core.pager=cat checkout should not suggest active branch '%s', got: %s", activeBranch, r.Cmd)
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
_ "github.com/versenilvis/iris/commands"
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/commands/js"
|
||||
_ "github.com/versenilvis/iris/commands"
|
||||
)
|
||||
|
||||
func TestNpmScriptGenerator(t *testing.T) {
|
||||
@@ -20,11 +20,11 @@ func TestNpmScriptGenerator(t *testing.T) {
|
||||
pkg := map[string]any{
|
||||
"name": "test-app",
|
||||
"scripts": map[string]string{
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"test": "vitest",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview",
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"test": "vitest",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview",
|
||||
"typecheck": "tsc --noEmit",
|
||||
},
|
||||
}
|
||||
@@ -173,7 +173,7 @@ func sshHostGeneratorFromPath(configPath string) []core.Suggestion {
|
||||
_ = scanner
|
||||
|
||||
data, _ := os.ReadFile(configPath)
|
||||
for _, line := range strings.Split(string(data), "\n") {
|
||||
for line := range strings.SplitSeq(string(data), "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
if !strings.HasPrefix(strings.ToLower(line), "host ") {
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user