From 05a7d162f6f5e71fc07aed3f5c0e51cabfe99a8d Mon Sep 17 00:00:00 2001 From: John Coene Date: Sat, 14 Sep 2024 17:57:48 +0200 Subject: [PATCH] fix: hint on library and require closes #56 --- walker/walk.go | 8 ++++++++ walker/walk_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/walker/walk.go b/walker/walk.go index 3733ce9..9ce3d2e 100644 --- a/walker/walk.go +++ b/walker/walk.go @@ -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) diff --git a/walker/walk_test.go b/walker/walk_test.go index 3fbb3b0..421ff06 100644 --- a/walker/walk_test.go +++ b/walker/walk_test.go @@ -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) +}