Skip to content

Commit 6ebd82f

Browse files
authored
fix: fmt with path (#6418)
1 parent 9cab9dc commit 6ebd82f

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

pkg/goformat/runner.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ func (c *Runner) Run(paths []string) error {
7979
}
8080

8181
func (c *Runner) walk(root string, stdout *os.File) error {
82-
r, err := os.OpenRoot(root)
83-
if err != nil {
84-
return err
85-
}
86-
8782
return filepath.Walk(root, func(path string, f fs.FileInfo, err error) error {
8883
if err != nil {
8984
return err
@@ -102,7 +97,10 @@ func (c *Runner) walk(root string, stdout *os.File) error {
10297
return err
10398
}
10499

105-
in, err := r.Open(path)
100+
//nolint:gosec // See explanation below.
101+
// `path` contains the `root` but when using `r, err := os.OpenRoot(root)`, this part is not inside the file tree of `r`.
102+
// `filepath.Rel()` can be used but it seems overkill in the context and doesn't work well with a file.
103+
in, err := os.Open(path)
106104
if err != nil {
107105
return err
108106
}

0 commit comments

Comments
 (0)