chore: Enable filepathJoin checker for gocritic (#13758)

Co-authored-by: Pawel Zak <Pawel Zak>
This commit is contained in:
Paweł Żak 2023-08-14 23:18:20 +02:00 committed by GitHub
parent 0d36ce0354
commit 5661341813
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 14 additions and 12 deletions

View File

@ -95,6 +95,7 @@ linters-settings:
- evalOrder - evalOrder
- exitAfterDefer - exitAfterDefer
- externalErrorReassign - externalErrorReassign
- filepathJoin
- flagName - flagName
- mapKey - mapKey
- nilValReturn - nilValReturn

View File

@ -907,7 +907,7 @@ func TestConfig_MultipleProcessorsOrder(t *testing.T) {
c := config.NewConfig() c := config.NewConfig()
filenames := make([]string, 0, len(test.filename)) filenames := make([]string, 0, len(test.filename))
for _, fn := range test.filename { for _, fn := range test.filename {
filenames = append(filenames, filepath.Join("./testdata/processor_order", fn)) filenames = append(filenames, filepath.Join(".", "testdata", "processor_order", fn))
} }
require.NoError(t, c.LoadAll(filenames...)) require.NoError(t, c.LoadAll(filenames...))

View File

@ -42,8 +42,10 @@ func TestCompileAndMatch(t *testing.T) {
// test exclamation mark creates non-matching list without a range // test exclamation mark creates non-matching list without a range
{path: filepath.Join(testdataDir, "log[!2]*"), matches: 2}, {path: filepath.Join(testdataDir, "log[!2]*"), matches: 2},
// test exclamation mark creates non-matching list without a range // test exclamation mark creates non-matching list without a range
//nolint:gocritic // filepathJoin - '\\' used to escape in glob, not path separator
{path: filepath.Join(testdataDir, "log\\[!*"), matches: 1}, {path: filepath.Join(testdataDir, "log\\[!*"), matches: 1},
// test exclamation mark creates non-matching list without a range // test exclamation mark creates non-matching list without a range
//nolint:gocritic // filepathJoin - '\\' used to escape in glob, not path separator
{path: filepath.Join(testdataDir, "log\\[^*"), matches: 0}, {path: filepath.Join(testdataDir, "log\\[^*"), matches: 0},
} }

View File

@ -132,7 +132,7 @@ func resolveName(name string) string {
return name return name
} }
// Try to prepend "/dev" // Try to prepend "/dev"
resolved, err = filepath.EvalSymlinks(filepath.Join("/dev", name)) resolved, err = filepath.EvalSymlinks("/dev/" + name)
if err != nil { if err != nil {
return name return name
} }

View File

@ -27,7 +27,7 @@ func TestRefreshFilePaths(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
r := File{ r := File{
Files: []string{filepath.Join(wd, "dev/testfiles/**.log")}, Files: []string{filepath.Join(wd, "dev", "testfiles", "**.log")},
} }
err = r.Init() err = r.Init()
require.NoError(t, err) require.NoError(t, err)
@ -42,7 +42,7 @@ func TestFileTag(t *testing.T) {
wd, err := os.Getwd() wd, err := os.Getwd()
require.NoError(t, err) require.NoError(t, err)
r := File{ r := File{
Files: []string{filepath.Join(wd, "dev/testfiles/json_a.log")}, Files: []string{filepath.Join(wd, "dev", "testfiles", "json_a.log")},
FileTag: "filename", FileTag: "filename",
} }
require.NoError(t, r.Init()) require.NoError(t, r.Init())
@ -67,7 +67,7 @@ func TestJSONParserCompile(t *testing.T) {
var acc testutil.Accumulator var acc testutil.Accumulator
wd, _ := os.Getwd() wd, _ := os.Getwd()
r := File{ r := File{
Files: []string{filepath.Join(wd, "dev/testfiles/json_a.log")}, Files: []string{filepath.Join(wd, "dev", "testfiles", "json_a.log")},
} }
require.NoError(t, r.Init()) require.NoError(t, r.Init())
@ -86,7 +86,7 @@ func TestGrokParser(t *testing.T) {
wd, _ := os.Getwd() wd, _ := os.Getwd()
var acc testutil.Accumulator var acc testutil.Accumulator
r := File{ r := File{
Files: []string{filepath.Join(wd, "dev/testfiles/grok_a.log")}, Files: []string{filepath.Join(wd, "dev", "testfiles", "grok_a.log")},
} }
err := r.Init() err := r.Init()
require.NoError(t, err) require.NoError(t, err)

View File

@ -4,7 +4,6 @@ package powerdns_recursor
import ( import (
_ "embed" _ "embed"
"fmt" "fmt"
"path/filepath"
"strconv" "strconv"
"time" "time"
@ -44,7 +43,7 @@ func (p *PowerdnsRecursor) Init() error {
} }
if p.SocketDir == "" { if p.SocketDir == "" {
p.SocketDir = filepath.Join("/", "var", "run") p.SocketDir = "/var/run"
} }
switch p.ControlProtocolVersion { switch p.ControlProtocolVersion {

View File

@ -63,7 +63,7 @@ func (p *Prometheus) startK8s(ctx context.Context) error {
return fmt.Errorf("failed to get current user: %w", err) return fmt.Errorf("failed to get current user: %w", err)
} }
kubeconfig := filepath.Join(u.HomeDir, ".kube/config") kubeconfig := filepath.Join(u.HomeDir, ".kube", "config")
config, err = loadConfig(kubeconfig) config, err = loadConfig(kubeconfig)
if err != nil { if err != nil {

View File

@ -172,7 +172,7 @@ partitionRange:
continue continue
} }
du.Path = filepath.Join("/", strings.TrimPrefix(p.Mountpoint, hostMountPrefix)) du.Path = filepath.Join(string(os.PathSeparator), strings.TrimPrefix(p.Mountpoint, hostMountPrefix))
du.Fstype = p.Fstype du.Fstype = p.Fstype
usage = append(usage, du) usage = append(usage, du)
partitions = append(partitions, &p) partitions = append(partitions, &p)

View File

@ -8,5 +8,5 @@ import (
) )
func servicesPath() string { func servicesPath() string {
return filepath.Join(os.Getenv("WINDIR"), `system32\drivers\etc\services`) return filepath.Join(os.Getenv("WINDIR"), "system32", "drivers", "etc", "services")
} }

View File

@ -19,7 +19,7 @@ func TempSocket(tb testing.TB) string {
// If the name of the test is long, the path length could exceed 104 // If the name of the test is long, the path length could exceed 104
// characters, and this would result in listen unix ...: bind: invalid argument // characters, and this would result in listen unix ...: bind: invalid argument
if runtime.GOOS == "darwin" { if runtime.GOOS == "darwin" {
sock := filepath.Join("/tmp", "sock") sock := "/tmp/sock"
tb.Cleanup(func() { tb.Cleanup(func() {
require.NoError(tb, os.RemoveAll(sock)) require.NoError(tb, os.RemoveAll(sock))