Skip to content

Commit

Permalink
fix: hint on library and require closes #56
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCoene committed Sep 14, 2024
1 parent 8c08c54 commit 05a7d16
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions walker/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ func (w *Walker) walkCallExpression(node *ast.CallExpression) (ast.Types, ast.No
return w.walkCallExpressionMissing(node)
}

if contains(node.Name, []string{"library", "require"}) {
w.addHintf(
node.Token,
"use namespace::foo instead of library() or require()",
)
return ast.Types{}, node
}

for _, v := range node.Arguments {
w.Walk(v.Value)
w.checkIfIdentifier(v.Value)
Expand Down
26 changes: 26 additions & 0 deletions walker/walk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1184,3 +1184,29 @@ func (p: any) bar(x: int): person

w.testDiagnostics(t, expected)
}

func TestLibrary(t *testing.T) {
code := `
library(something)
require(package)
`

l := lexer.NewTest(code)

l.Run()
p := parser.New(l)

prog := p.Run()

w := New()

w.Run(prog)

expected := diagnostics.Diagnostics{
{Severity: diagnostics.Hint},
{Severity: diagnostics.Hint},
}

w.testDiagnostics(t, expected)
}

0 comments on commit 05a7d16

Please sign in to comment.