Skip to content

Commit

Permalink
fix: use filepath instead of path for Base
Browse files Browse the repository at this point in the history
  • Loading branch information
gabotechs committed Dec 31, 2023
1 parent d0943f4 commit dccb3d9
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 18 deletions.
3 changes: 1 addition & 2 deletions internal/board/board_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package board

import (
"path"
"path/filepath"
"testing"

Expand Down Expand Up @@ -276,7 +275,7 @@ func TestBoard(t *testing.T) {
result, err := board.Render()
if tt.ExpectedError == "" {
a.NoError(err)
fullPath := filepath.Join(testPath, path.Base(t.Name())+".txt")
fullPath := filepath.Join(testPath, filepath.Base(t.Name())+".txt")
utils.GoldenTest(t, fullPath, result)
} else {
a.ErrorContains(err, tt.ExpectedError)
Expand Down
3 changes: 1 addition & 2 deletions internal/dep_tree/render_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dep_tree

import (
"path"
"path/filepath"
"testing"

Expand Down Expand Up @@ -104,7 +103,7 @@ func TestRenderGraph(t *testing.T) {
result, err := board.Render()
a.NoError(err)

outFile := filepath.Join(renderDir, path.Base(tt.Name+".txt"))
outFile := filepath.Join(renderDir, filepath.Base(tt.Name+".txt"))
utils.GoldenTest(t, outFile, result)
})
}
Expand Down
3 changes: 1 addition & 2 deletions internal/dep_tree/structured_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dep_tree

import (
"path"
"path/filepath"
"testing"

Expand Down Expand Up @@ -88,7 +87,7 @@ func TestDepTree_RenderStructuredGraph(t *testing.T) {
)
a.NoError(err)

renderOutFile := filepath.Join(structuredDir, path.Base(tt.Name+".json"))
renderOutFile := filepath.Join(structuredDir, filepath.Base(tt.Name+".json"))
utils.GoldenTest(t, renderOutFile, rendered)
})
}
Expand Down
5 changes: 2 additions & 3 deletions internal/entropy/dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package entropy

import (
"math"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -47,15 +46,15 @@ func splitBaseNames(dir string) []string {
fullPaths := splitFullPaths(dir)
result := make([]string, len(fullPaths))
for i := range fullPaths {
result[i] = path.Base(fullPaths[len(fullPaths)-i-1])
result[i] = filepath.Base(fullPaths[len(fullPaths)-i-1])
}
return result
}

func (d *DirTree) AddDirs(dir string) {
node := d.inner()
for _, p := range splitBaseNames(dir) {
base := path.Base(p)
base := filepath.Base(p)
if upper, ok := node.Get(base); ok {
node = upper.entry.inner()
} else {
Expand Down
3 changes: 1 addition & 2 deletions internal/entropy/graph.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package entropy

import (
"path"
"path/filepath"

"github.com/gabotechs/dep-tree/internal/dep_tree"
Expand Down Expand Up @@ -61,7 +60,7 @@ func makeGraph(dt *dep_tree.DepTree[language.FileInfo], parser language.NodePars
dirName := filepath.Dir(filePath)
out.Nodes = append(out.Nodes, Node{
Id: node.ID(),
FileName: path.Base(filePath),
FileName: filepath.Base(filePath),
DirName: dirName + "/",
Loc: node.Data.Loc,
Size: maxNodeSize * node.Data.Loc / maxLoc,
Expand Down
5 changes: 2 additions & 3 deletions internal/python/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package python
import (
"fmt"
"os"
"path"
"path/filepath"
"strings"

Expand All @@ -19,7 +18,7 @@ func (i *InitModuleResult) fileMap() map[string]string {
availableFiles := map[string]string{}
for _, pythonFile := range i.PythonFiles {
for _, ext := range Extensions {
fileName := path.Base(pythonFile)
fileName := filepath.Base(pythonFile)
if strings.HasSuffix(fileName, ext) {
availableFiles[strings.TrimSuffix(fileName, "."+ext)] = pythonFile
}
Expand All @@ -36,7 +35,7 @@ type DirectoryResult struct {
func (d *DirectoryResult) fileMap() map[string]string {
availableFiles := map[string]string{}
for _, pythonFile := range d.PythonFiles {
availableFiles[strings.TrimSuffix(path.Base(pythonFile), ".py")] = pythonFile
availableFiles[strings.TrimSuffix(filepath.Base(pythonFile), ".py")] = pythonFile
}
return availableFiles
}
Expand Down
3 changes: 1 addition & 2 deletions internal/rust/mod_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rust

import (
"fmt"
"path"
"path/filepath"

"github.com/gabotechs/dep-tree/internal/rust/rust_grammar"
Expand Down Expand Up @@ -35,7 +34,7 @@ func makeModTree(mainPath string, name string, parent *ModTree) (*ModTree, error
}

var searchPath string
if path.Base(mainPath) == name+".rs" {
if filepath.Base(mainPath) == name+".rs" {
searchPath = filepath.Join(filepath.Dir(mainPath), name)
} else {
searchPath = filepath.Dir(mainPath)
Expand Down
3 changes: 1 addition & 2 deletions internal/tui/tui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tui
import (
"fmt"
"os"
"path"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -113,7 +112,7 @@ func TestTui(t *testing.T) {
t.Run(tt.Name, func(t *testing.T) {
a := require.New(t)

repoPath := filepath.Join(tmp, path.Base(tt.Repo))
repoPath := filepath.Join(tmp, filepath.Base(tt.Repo))
entrypointPath := filepath.Join(repoPath, tt.Entrypoint)
if _, err := os.Stat(entrypointPath); err != nil {
_ = os.RemoveAll(repoPath)
Expand Down

0 comments on commit dccb3d9

Please sign in to comment.