From dccb3d96813d40c0c016abfe6d8a93809fbd52a5 Mon Sep 17 00:00:00 2001 From: Gabriel Musat Date: Sun, 31 Dec 2023 10:56:31 +0100 Subject: [PATCH] fix: use filepath instead of path for Base --- internal/board/board_test.go | 3 +-- internal/dep_tree/render_test.go | 3 +-- internal/dep_tree/structured_test.go | 3 +-- internal/entropy/dirs.go | 5 ++--- internal/entropy/graph.go | 3 +-- internal/python/resolve.go | 5 ++--- internal/rust/mod_tree.go | 3 +-- internal/tui/tui_test.go | 3 +-- 8 files changed, 10 insertions(+), 18 deletions(-) diff --git a/internal/board/board_test.go b/internal/board/board_test.go index ef5ce85..c215848 100644 --- a/internal/board/board_test.go +++ b/internal/board/board_test.go @@ -1,7 +1,6 @@ package board import ( - "path" "path/filepath" "testing" @@ -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) diff --git a/internal/dep_tree/render_test.go b/internal/dep_tree/render_test.go index faaba4b..1f6dfdf 100644 --- a/internal/dep_tree/render_test.go +++ b/internal/dep_tree/render_test.go @@ -1,7 +1,6 @@ package dep_tree import ( - "path" "path/filepath" "testing" @@ -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) }) } diff --git a/internal/dep_tree/structured_test.go b/internal/dep_tree/structured_test.go index ebb53ed..a9ce2df 100644 --- a/internal/dep_tree/structured_test.go +++ b/internal/dep_tree/structured_test.go @@ -1,7 +1,6 @@ package dep_tree import ( - "path" "path/filepath" "testing" @@ -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) }) } diff --git a/internal/entropy/dirs.go b/internal/entropy/dirs.go index e996c76..0c213df 100644 --- a/internal/entropy/dirs.go +++ b/internal/entropy/dirs.go @@ -2,7 +2,6 @@ package entropy import ( "math" - "path" "path/filepath" "strings" @@ -47,7 +46,7 @@ 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 } @@ -55,7 +54,7 @@ func splitBaseNames(dir string) []string { 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 { diff --git a/internal/entropy/graph.go b/internal/entropy/graph.go index c113c5d..9a57c00 100644 --- a/internal/entropy/graph.go +++ b/internal/entropy/graph.go @@ -1,7 +1,6 @@ package entropy import ( - "path" "path/filepath" "github.com/gabotechs/dep-tree/internal/dep_tree" @@ -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, diff --git a/internal/python/resolve.go b/internal/python/resolve.go index 7a4405a..8d6d0aa 100644 --- a/internal/python/resolve.go +++ b/internal/python/resolve.go @@ -3,7 +3,6 @@ package python import ( "fmt" "os" - "path" "path/filepath" "strings" @@ -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 } @@ -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 } diff --git a/internal/rust/mod_tree.go b/internal/rust/mod_tree.go index c085ed8..42aa6d1 100644 --- a/internal/rust/mod_tree.go +++ b/internal/rust/mod_tree.go @@ -2,7 +2,6 @@ package rust import ( "fmt" - "path" "path/filepath" "github.com/gabotechs/dep-tree/internal/rust/rust_grammar" @@ -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) diff --git a/internal/tui/tui_test.go b/internal/tui/tui_test.go index 9faf5e1..8a4cc3b 100644 --- a/internal/tui/tui_test.go +++ b/internal/tui/tui_test.go @@ -3,7 +3,6 @@ package tui import ( "fmt" "os" - "path" "path/filepath" "strings" "testing" @@ -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)