MCPcopy Index your code
hub / github.com/deepnote/deepnote / checkUnusedVariables

Function checkUnusedVariables

packages/cli/src/utils/analysis.ts:392–427  ·  view source on GitHub ↗

* Check for variables that are defined but never used.

(dag: BlockDependencyDag, blockMap: Map<string, BlockInfo>)

Source from the content-addressed store, hash-verified

390 * Check for variables that are defined but never used.
391 */
392function checkUnusedVariables(dag: BlockDependencyDag, blockMap: Map<string, BlockInfo>): LintIssue[] {
393 const issues: LintIssue[] = []
394
395 // Collect all used variables
396 const usedVars = new Set<string>()
397 for (const node of dag.nodes) {
398 for (const v of node.inputVariables) {
399 usedVars.add(v)
400 }
401 }
402
403 // Check each block's output variables
404 for (const node of dag.nodes) {
405 const info = blockMap.get(node.id)
406 if (!info) continue
407
408 for (const outputVar of node.outputVariables) {
409 // Skip private variables (starting with _)
410 if (outputVar.startsWith('_')) continue
411
412 if (!usedVars.has(outputVar)) {
413 issues.push({
414 severity: 'warning',
415 code: 'unused-variable',
416 message: `Variable "${outputVar}" is defined but never used`,
417 blockId: node.id,
418 blockLabel: info.label,
419 notebookName: info.notebookName,
420 details: { variable: outputVar },
421 })
422 }
423 }
424 }
425
426 return issues
427}
428
429/**
430 * Check for variables that are redefined (shadowed).

Callers 1

checkForIssuesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected