liveBook · Manning

No-debugger

As explained in Essential TypeScript 5, Third Edition

The no-debugger rule prohibits debugger statements in source code.

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

How Essential TypeScript 5, Third Edition covers it

How deep it goes
Explains lint diagnostics and targeted suppression, but does not examine debugger execution mechanics.
Examples
Uses an index.ts file, a debugger statement, an eslint-disable-line comment, and npx eslint . output.
What it assumes
Assumes familiarity with TypeScript source files, ESLint, and debugger statements.
What you can do after
Operate ESLint with no-debugger enabled and make narrowly scoped exceptions during debugging.
How it connects
Connects ESLint, TypeScript linting, debugger statements, and eslint-disable-line comments.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Essential TypeScript 5, Third Edition. The section links point to the parts of the book it draws on.