/** * Test file for JavaScript/TypeScript LSP diagnostics * Tests error, warning, info, and hint virtual text colors */ // ERROR: Undefined variable console.log(undefinedVariable); // ERROR: Undefined function nonexistentFunction(); // WARNING: Unused variable const unusedVariable = "I'm never used"; // ERROR: Type error (if using TypeScript or JSDoc) /** * @param {string} name * @param {number} age */ function greet(name, age) { console.log(`Hello ${name}, you are ${age}`); } greet("Alice", "not a number"); // Type mismatch // WARNING: Unreachable code function earlyReturn() { return "done"; console.log("Never executed"); // Unreachable } // ERROR: Invalid property access const obj = {}; console.log(obj.nonexistent.nested.property); // WARNING: Comparison with different types if ("5" == 5) { // Should use === console.log("loose equality"); } // ERROR: Missing parameter greet("Bob"); // Missing age parameter // INFO: Unnecessary type assertion (TypeScript) const num = 123; const str = String(num); // Could be simplified // HINT: Variable can be const instead of let let neverReassigned = "should be const"; console.log(neverReassigned); // ERROR: Division by zero (some linters catch this) const result = 10 / 0; // WARNING: Duplicate case label const value = 1; switch (value) { case 1: console.log("one"); break; case 1: // Duplicate case console.log("one again"); break; } // ERROR: Invalid this context const obj2 = { name: "test", greet: () => { console.log(this.name); // Arrow function doesn't bind this } }; console.log("JavaScript diagnostic test complete!");