Skip to content

Commit

Permalink
lint and add TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
gabotechs committed Feb 9, 2024
1 parent bcf8653 commit f0c1dae
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func loadConfig() (*config.Config, error) {
cfg.Python.IgnoreFromImportsAsExports = true
cfg.Python.IgnoreDirectoryImports = true

// TODO: the excluded list should be relative to the CWD
cfg.Exclude = append(cfg.Exclude, exclude...)
// validate exclusion patterns.
for _, exclusion := range cfg.Exclude {
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func ParseConfig(cfgPath string) (*Config, error) {
return &cfg, err
}
cfg.Path = filepath.Dir(absCfgPath)
// TODO: The exclusion list should be either absolute glob paths or relative to the config file.

decoder := yaml.NewDecoder(bytes.NewReader(content))
decoder.KnownFields(true)
Expand Down
2 changes: 1 addition & 1 deletion internal/graph/cycles.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (g *Graph[T]) RemoveElementaryCycles() []Cycle {
// RemoveCycles removes all cycles in the graph, giving preference to cycles that start
// from the provided nodes.
func (g *Graph[T]) RemoveCycles(nodes []*Node[T]) []Cycle {
var cycles []Cycle
cycles := make([]Cycle, 0)

// First, remove the cycles computed from each entrypoint. This allows
// us trim the cycles in a more "controlled way"
Expand Down
24 changes: 13 additions & 11 deletions internal/language/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (p *Parser) Node(id string) (*graph.Node[*FileInfo], error) {
return graph.MakeNode(id, file), nil
}

//nolint:gocyclo
func (p *Parser) Deps(n *graph.Node[*FileInfo]) ([]*graph.Node[*FileInfo], error) {
imports, err := p.gatherImportsFromFile(n.Id)
if err != nil {
Expand Down Expand Up @@ -128,30 +129,31 @@ func (p *Parser) Deps(n *graph.Node[*FileInfo]) ([]*graph.Node[*FileInfo], error
for el := exports.Exports.Front(); el != nil; el = el.Next() {
resolvedImports.Set(el.Value, true)
}
continue
} else if len(importEntry.Names) == 0 {
resolvedImports.Set(importEntry.Path, true)
}
for _, name := range importEntry.Names {
if exportPath, ok := exports.Exports.Get(name); ok {
resolvedImports.Set(exportPath, true)
} else {
// TODO: this is not retro-compatible, do it in a different PR.
// n.AddErrors(fmt.Errorf("name %s is imported by %s but not exported by %s", name, n.Id, importEntry.Id)).
} else {
for _, name := range importEntry.Names {
if exportPath, ok := exports.Exports.Get(name); ok {
resolvedImports.Set(exportPath, true)
} else {
// TODO: this is not retro-compatible, do it in a different PR.
// n.AddErrors(fmt.Errorf("name %s is imported by %s but not exported by %s", name, n.Id, importEntry.Id)).
}
}
}
}

deps := make([]*graph.Node[*FileInfo], 0)
for _, imported := range resolvedImports.Keys() {
if p.shouldExclude(imported) {
continue
}
node, err := p.Node(imported)
if err != nil {
n.AddErrors(err)
continue
}
if !p.shouldExclude(p.Display(node).Name) {
deps = append(deps, node)
}
deps = append(deps, node)
}
return deps, nil
}
Expand Down
4 changes: 1 addition & 3 deletions internal/python/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ func TestLanguage_ParseImports_Errors(t *testing.T) {
lang, err := MakePythonLanguage(nil)
a.NoError(err)

file := language.FileInfo{
Content: &tt.File,
}
file := language.FileInfo{Content: &tt.File} //nolint:gosec

result, err := lang.ParseImports(&file)
a.NoError(err)
Expand Down

0 comments on commit f0c1dae

Please sign in to comment.