CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel--plugin-proposal-object-rest-spread

Babel plugin that transforms ECMAScript object rest and spread syntax into ES5-compatible code.

85

1.06x

Quality

Pending

Does it follow best practices?

Impact

85%

1.06x

Average score across 10 eval scenarios

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

task.mdevals/scenario-2/

Variable Usage Analyzer

Build a tool that analyzes JavaScript source code to find all variables that are declared but never used. The tool should parse the code, traverse the abstract syntax tree, and report unused variables along with their locations.

Requirements

The analyzer should:

  1. Accept JavaScript source code as a string input
  2. Parse the code into an abstract syntax tree
  3. Identify all variable declarations (using var, let, const)
  4. Track which declared variables are referenced in the code
  5. Report any variables that are declared but never referenced
  6. Include the line number and variable name for each unused variable

The analyzer should handle:

  • Function parameters (they should not be reported as unused even if not referenced in the function body)
  • Variables in nested scopes (block scope, function scope)
  • Variables shadowed in inner scopes

Output Format

The analyzer should return an array of objects, where each object represents an unused variable:

[
  { name: "variableName", line: 5 },
  { name: "anotherVar", line: 12 }
]

If all variables are used, return an empty array.

Test Cases

  • Given code with an unused variable declared with const, it reports that variable @test
  • Given code where all variables are used, it returns an empty array @test
  • Given code with an unused variable in a nested block scope, it reports that variable @test
  • Given code with an unused function parameter, it does NOT report that parameter as unused @test

Implementation

@generates

API

/**
 * Analyzes JavaScript source code to find unused variables
 *
 * @param {string} code - The JavaScript source code to analyze
 * @returns {Array<{name: string, line: number}>} Array of unused variables with their line numbers
 */
function analyzeUnusedVariables(code) {
  // IMPLEMENTATION HERE
}

module.exports = { analyzeUnusedVariables };

Dependencies { .dependencies }

@babel/parser { .dependency }

Provides JavaScript parsing capabilities to convert source code into an abstract syntax tree.

@babel/traverse { .dependency }

Provides AST traversal capabilities with visitor pattern support for analyzing the syntax tree.

tile.json