The no-debugger rule prevents debugger statements from remaining in TypeScript source files. ESLint reports an error when it encounters one, helping keep temporary debugging code out of normal execution. section 6.3 section 6.3.1
Use the rule with these practical decisions:
- Keep it enabled generally because a leftover debugger statement can interrupt application execution. section 6.3.1
- Avoid disabling it globally merely to accommodate an active investigation; suppress the warning only for the statement being examined. section 6.3.1
- Use an eslint-disable-line comment followed by no-debugger when a temporary debugger statement is intentional. section 6.3.1
Suppressing one intentional debugger statement
In src/index.ts, place the rule name on the same line as the statement:\n\ndebugger; // eslint-disable-line no-debugger\n\nRunning npx eslint . then suppresses the no-debugger diagnostic for that statement while the rule remains active elsewhere. section 6.3.1 section 6.3
Listing 6.13 Disabling a rule for a single statement in the index.ts file in the src folder
import { sum } from "./calc.js";
let printMessage = (msg: string): void => console.log(`Message: ${ msg }`);
let message = ("Hello, TypeScript");
printMessage(message);
debugger; // eslint-disable-line no-debugger
let total = sum(100, 200, 300);
console.log(`Total: ${total}`);
Browse the complete TypeScript file showing a targeted no-debugger exception in context. section 6.3.1
