[feature] detect unused imports
This commit is contained in:
parent
44d80dd863
commit
4137a4dbf3
12 changed files with 62 additions and 33 deletions
|
|
@ -450,7 +450,7 @@ proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym,
|
|||
pushInfoContext(c.config, nOrig.info, sym.detailedInfo)
|
||||
|
||||
let info = getCallLineInfo(n)
|
||||
markUsed(c.config, info, sym, c.graph.usageSym)
|
||||
markUsed(c, info, sym, c.graph.usageSym)
|
||||
onUse(info, sym)
|
||||
if sym == c.p.owner:
|
||||
globalError(c.config, info, "recursive dependency: '$1'" % sym.name.s)
|
||||
|
|
@ -618,12 +618,17 @@ proc myProcess(context: PPassContext, n: PNode): PNode =
|
|||
#if c.config.cmd == cmdIdeTools: findSuggest(c, n)
|
||||
rod.storeNode(c.graph, c.module, result)
|
||||
|
||||
proc reportUnusedModules(c: PContext) =
|
||||
for i in 0..high(c.unusedImports):
|
||||
message(c.config, c.unusedImports[i][1], hintUnusedModuleX, c.unusedImports[i][0].name.s)
|
||||
|
||||
proc myClose(graph: ModuleGraph; context: PPassContext, n: PNode): PNode =
|
||||
var c = PContext(context)
|
||||
if c.config.cmd == cmdIdeTools and not c.suggestionsMade:
|
||||
suggestSentinel(c)
|
||||
closeScope(c) # close module's scope
|
||||
rawCloseScope(c) # imported symbols; don't check for unused ones!
|
||||
reportUnusedModules(c)
|
||||
result = newNode(nkStmtList)
|
||||
if n != nil:
|
||||
internalError(c.config, n.info, "n is not nil") #result := n;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue