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

chore: Enable filepathJoin checker for gocritic #13758

Merged
merged 2 commits into from
Aug 14, 2023
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
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ linters-settings:
- evalOrder
- exitAfterDefer
- externalErrorReassign
- filepathJoin
- flagName
- mapKey
- nilValReturn
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ func TestConfig_MultipleProcessorsOrder(t *testing.T) {
c := config.NewConfig()
filenames := make([]string, 0, len(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...))

Expand Down
2 changes: 2 additions & 0 deletions internal/globpath/globpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ func TestCompileAndMatch(t *testing.T) {
// test exclamation mark creates non-matching list without a range
{path: filepath.Join(testdataDir, "log[!2]*"), matches: 2},
// 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},
// 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},
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/diskio/diskio_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func resolveName(name string) string {
return name
}
// Try to prepend "/dev"
resolved, err = filepath.EvalSymlinks(filepath.Join("/dev", name))
resolved, err = filepath.EvalSymlinks("/dev/" + name)
if err != nil {
return name
}
Expand Down
8 changes: 4 additions & 4 deletions plugins/inputs/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestRefreshFilePaths(t *testing.T) {
require.NoError(t, err)

r := File{
Files: []string{filepath.Join(wd, "dev/testfiles/**.log")},
Files: []string{filepath.Join(wd, "dev", "testfiles", "**.log")},
}
err = r.Init()
require.NoError(t, err)
Expand All @@ -42,7 +42,7 @@ func TestFileTag(t *testing.T) {
wd, err := os.Getwd()
require.NoError(t, err)
r := File{
Files: []string{filepath.Join(wd, "dev/testfiles/json_a.log")},
Files: []string{filepath.Join(wd, "dev", "testfiles", "json_a.log")},
FileTag: "filename",
}
require.NoError(t, r.Init())
Expand All @@ -67,7 +67,7 @@ func TestJSONParserCompile(t *testing.T) {
var acc testutil.Accumulator
wd, _ := os.Getwd()
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())

Expand All @@ -86,7 +86,7 @@ func TestGrokParser(t *testing.T) {
wd, _ := os.Getwd()
var acc testutil.Accumulator
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()
require.NoError(t, err)
Expand Down
3 changes: 1 addition & 2 deletions plugins/inputs/powerdns_recursor/powerdns_recursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package powerdns_recursor
import (
_ "embed"
"fmt"
"path/filepath"
"strconv"
"time"

Expand Down Expand Up @@ -44,7 +43,7 @@ func (p *PowerdnsRecursor) Init() error {
}

if p.SocketDir == "" {
p.SocketDir = filepath.Join("/", "var", "run")
p.SocketDir = "/var/run"
}

switch p.ControlProtocolVersion {
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/prometheus/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (p *Prometheus) startK8s(ctx context.Context) error {
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)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/system/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ partitionRange:
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
usage = append(usage, du)
partitions = append(partitions, &p)
Expand Down
2 changes: 1 addition & 1 deletion plugins/processors/port_name/services_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import (
)

func servicesPath() string {
return filepath.Join(os.Getenv("WINDIR"), `system32\drivers\etc\services`)
return filepath.Join(os.Getenv("WINDIR"), "system32", "drivers", "etc", "services")
}
2 changes: 1 addition & 1 deletion testutil/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TempSocket(tb testing.TB) string {
// 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
if runtime.GOOS == "darwin" {
sock := filepath.Join("/tmp", "sock")
sock := "/tmp/sock"

tb.Cleanup(func() {
require.NoError(tb, os.RemoveAll(sock))
Expand Down
Loading