Skip to content

Commit 662e02c

Browse files
authored
refactor: use "filepath" instead of "path" (#1073)
1 parent 842b3e2 commit 662e02c

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

lint/linter.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"go/token"
88
"os"
9-
"path"
109
"path/filepath"
1110
"regexp"
1211
"strconv"
@@ -175,7 +174,7 @@ func detectGoMod(dir string) (rootDir string, ver *goversion.Version, err error)
175174
}
176175

177176
ver, err = goversion.NewVersion(modAst.Go.Version)
178-
return path.Dir(modFileName), ver, err
177+
return filepath.Dir(modFileName), ver, err
179178
}
180179

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

188-
lookingForFilePath := path.Join(dir, lookingForFile)
187+
lookingForFilePath := filepath.Join(dir, lookingForFile)
189188
info, err := os.Stat(lookingForFilePath)
190189
if err != nil || info.IsDir() {
191190
// lets check the parent dir
192-
dir = path.Dir(dir)
191+
dir = filepath.Dir(dir)
193192
continue
194193
}
195194

test/golint_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package test
33
import (
44
"flag"
55
"os"
6-
"path"
6+
"path/filepath"
77
"regexp"
88
"testing"
99

@@ -53,7 +53,7 @@ func TestAll(t *testing.T) {
5353
continue
5454
}
5555
t.Run(fi.Name(), func(t *testing.T) {
56-
filePath := path.Join(baseDir, fi.Name())
56+
filePath := filepath.Join(baseDir, fi.Name())
5757
src, err := os.ReadFile(filePath)
5858
if err != nil {
5959
t.Fatalf("Failed reading %s: %v", fi.Name(), err)
@@ -64,7 +64,7 @@ func TestAll(t *testing.T) {
6464
t.Fatalf("Failed reading %s: %v", fi.Name(), err)
6565
}
6666

67-
if err := assertFailures(t, path.Dir(baseDir), fileInfo, src, rules, map[string]lint.RuleConfig{}); err != nil {
67+
if err := assertFailures(t, filepath.Dir(baseDir), fileInfo, src, rules, map[string]lint.RuleConfig{}); err != nil {
6868
t.Errorf("Linting %s: %v", fi.Name(), err)
6969
}
7070
})

test/utils_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"go/token"
1111
"go/types"
1212
"os"
13-
"path"
13+
"path/filepath"
1414
"strconv"
1515
"strings"
1616
"testing"
@@ -19,9 +19,9 @@ import (
1919
)
2020

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

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

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

77-
ps, err := l.Lint([][]string{{path.Join(baseDir, fi.Name())}}, rules, lint.Config{
77+
ps, err := l.Lint([][]string{{filepath.Join(baseDir, fi.Name())}}, rules, lint.Config{
7878
Rules: config,
7979
})
8080
if err != nil {

0 commit comments

Comments
 (0)