liveBook · Manning

Eslint-disable-line comment

As explained in Essential TypeScript 5, Third Edition

An eslint-disable-line comment directive suppresses specified linting rules for the statement on the same line.

An eslint-disable-line comment suppresses one or more named ESLint rules for the statement on the same line. Use it when an exception is limited to one statement rather than an entire project or file. section 6.3.1

Suppressing no-debugger for one statement

In src/index.ts, place the directive after the statement that intentionally contains a debugger statement: debugger; // eslint-disable-line no-debugger The rule name restricts the exception to no-debugger. Omitting rule names can disable all linting rules, so name the specific rule whenever possible. section 6.3.1

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}`);

View the complete TypeScript listing showing the inline directive in context with imports, typed functions, and subsequent application code. section 6.3.1

How Essential TypeScript 5, Third Edition covers it

How deep it goes
Defines single-statement suppression and mentions block-comment variants, but does not detail ESLint parsing or directive internals.
Examples
Demonstrates `debugger; // eslint-disable-line no-debugger` in the `src/index.ts` file.
What it assumes
Assumes familiarity with linting and rule configuration, then demonstrates the exception in a TypeScript source file.
What you can do after
Apply it via ESLint by naming one or more rules after `eslint-disable-line` on the affected statement.
How it connects
Connects inline suppression to ESLint configuration, linting rules, and the debugger statement.

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.