Add warning for unused imports

This commit is contained in:
James Westman 2024-04-06 14:30:48 -05:00
parent 729939ad93
commit 6a078ee075
13 changed files with 53 additions and 5 deletions

View file

@ -88,6 +88,17 @@ class Import(AstNode):
def namespace_exists(self):
gir.get_namespace(self.tokens["namespace"], self.tokens["version"])
@validate()
def unused(self):
if self.namespace not in self.root.used_imports:
raise UnusedWarning(
f"Unused import: {self.namespace}",
self.range,
actions=[
CodeAction("Remove import", "", self.range.with_trailing_newline)
],
)
@property
def gir_namespace(self):
try: