Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use "path/filepath" instead of "path" #1073

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lint/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"go/token"
"os"
"path"
"path/filepath"
"regexp"
"strconv"
Expand Down Expand Up @@ -175,7 +174,7 @@ func detectGoMod(dir string) (rootDir string, ver *goversion.Version, err error)
}

ver, err = goversion.NewVersion(modAst.Go.Version)
return path.Dir(modFileName), ver, err
return filepath.Dir(modFileName), ver, err
}

func retrieveModFile(dir string) (string, error) {
Expand All @@ -185,11 +184,11 @@ func retrieveModFile(dir string) (string, error) {
return "", fmt.Errorf("did not found %q file", lookingForFile)
}

lookingForFilePath := path.Join(dir, lookingForFile)
lookingForFilePath := filepath.Join(dir, lookingForFile)
info, err := os.Stat(lookingForFilePath)
if err != nil || info.IsDir() {
// lets check the parent dir
dir = path.Dir(dir)
dir = filepath.Dir(dir)
continue
}

Expand Down
6 changes: 3 additions & 3 deletions test/golint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package test
import (
"flag"
"os"
"path"
"path/filepath"
"regexp"
"testing"

Expand Down Expand Up @@ -53,7 +53,7 @@ func TestAll(t *testing.T) {
continue
}
t.Run(fi.Name(), func(t *testing.T) {
filePath := path.Join(baseDir, fi.Name())
filePath := filepath.Join(baseDir, fi.Name())
src, err := os.ReadFile(filePath)
if err != nil {
t.Fatalf("Failed reading %s: %v", fi.Name(), err)
Expand All @@ -64,7 +64,7 @@ func TestAll(t *testing.T) {
t.Fatalf("Failed reading %s: %v", fi.Name(), err)
}

if err := assertFailures(t, path.Dir(baseDir), fileInfo, src, rules, map[string]lint.RuleConfig{}); err != nil {
if err := assertFailures(t, filepath.Dir(baseDir), fileInfo, src, rules, map[string]lint.RuleConfig{}); err != nil {
t.Errorf("Linting %s: %v", fi.Name(), err)
}
})
Expand Down
14 changes: 7 additions & 7 deletions test/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"go/token"
"go/types"
"os"
"path"
"path/filepath"
"strconv"
"strings"
"testing"
Expand All @@ -19,9 +19,9 @@ import (
)

func testRule(t *testing.T, filename string, rule lint.Rule, config ...*lint.RuleConfig) {
baseDir := path.Join("../testdata/" + path.Dir(filename))
filename = path.Base(filename) + ".go"
fullFilePath := path.Join(baseDir, filename)
baseDir := filepath.Join("..", "testdata", filepath.Dir(filename))
filename = filepath.Base(filename) + ".go"
fullFilePath := filepath.Join(baseDir, filename)
src, err := os.ReadFile(fullFilePath)
if err != nil {
t.Fatalf("Bad filename path in test for %s: %v", rule.Name(), err)
Expand All @@ -46,7 +46,7 @@ func assertSuccess(t *testing.T, baseDir string, fi os.FileInfo, rules []lint.Ru
return os.ReadFile(file)
}, 0)

filePath := path.Join(baseDir, fi.Name())
filePath := filepath.Join(baseDir, fi.Name())
ps, err := l.Lint([][]string{{filePath}}, rules, lint.Config{
Rules: config,
})
Expand All @@ -69,12 +69,12 @@ func assertFailures(t *testing.T, baseDir string, fi os.FileInfo, src []byte, ru
return os.ReadFile(file)
}, 0)

ins := parseInstructions(t, path.Join(baseDir, fi.Name()), src)
ins := parseInstructions(t, filepath.Join(baseDir, fi.Name()), src)
if ins == nil {
return fmt.Errorf("Test file %v does not have instructions", fi.Name())
}

ps, err := l.Lint([][]string{{path.Join(baseDir, fi.Name())}}, rules, lint.Config{
ps, err := l.Lint([][]string{{filepath.Join(baseDir, fi.Name())}}, rules, lint.Config{
Rules: config,
})
if err != nil {
Expand Down
Loading