A lightweight VS Code extension that detects undefined and undeclared variables in JavaScript files (.js). It is designed to act as a simple "spell checker" for your variable names, helping you catch typos and scope errors without the complexity of setting up TypeScript or ESLint.
Features
Real-time Error Detection: Analyzes your code as you type or save.
Scope Awareness: Correctly handles:
Function scope (var)
Block scope (let, const)
Nested functions and blocks
Function parameters
Multi-Environment Support: Pre-configured to recognize global variables for:
The extension monitors your code for potential security vulnerabilities:
Eval Warning: eval("...") is flagged as a security risk.
Indirect Eval: setTimeout("...", 1000) allows code injection and is flagged.
Arbitrary Code Execution: new Function(...) is flagged.
XSS Prevention: Assignments to innerHTML or outerHTML triggers a warning to prevent Cross-Site Scripting.
Logic & Quality Capabilities
Const Reassignment:
const PI = 3.14;
PI = 3; // Error: Assignment to constant variable
Unused Variables:
let data = "foo"; // Warning: 'data' is declared but never read
How it Works
This extension uses acorn to parse your JavaScript code into an Abstract Syntax Tree (AST). It builds a comprehensive scope map (Global, Function, Block, Class, Catch) and tracks:
Declarations: Where variables are defined and their specific type (var/let/const/param/class).
Usages: Where variables are referenced.
Pattern Matching: Detecting specific AST nodes like CallExpression with 'eval' or AssignmentExpression to innerHTML.
Limitations
This is a static analysis tool and may not catch dynamic variable injections.
It assumes standard declaration patterns.
It is "loose" with globals—valid Node.js globals are accepted in client-side code and vice-versa, to prevent false positives in mixed-code workspaces.