user7898461
user7898461

Reputation:

Allow debugger; statements in certain files, using ESLint

Say I want to use this rule:

https://eslint.org/docs/rules/no-debugger

however, I have about 15 files where I want to keep debugger; statements.

Is there something I can add at the top of the .ts/.js files, that can tell ESLint to ignore the no-debugger rule for this particular file?

Upvotes: 40

Views: 78663

Answers (6)

George Wayne
George Wayne

Reputation: 191

I think debugger need to removed, and briefly used in a development environment.

So you're better off ignoring it where you use.

For example: disable no-debugger for this line

    // eslint-disable-next-line no-debugger
    debugger

or disable no-debugger for the entire file

/* eslint-disable no-debugger */

Upvotes: 0

Arseny
Arseny

Reputation: 197

Update your eslint configuration file (.eslintrc etc) with such rule:

"rules": {
    "no-debugger":"off"
}

Upvotes: 17

Beachhouse
Beachhouse

Reputation: 5052

OR, add:

"no-debugger": false

to the bottom of tslint.json, to disable this warning for all files.

Upvotes: 2

Andrzej Gis
Andrzej Gis

Reputation: 14316

You can also disable ESLint in the same line:

debugger; // eslint-disable-line no-debugger

Upvotes: 97

Yuci
Yuci

Reputation: 30189

Probably your IDE can help. If you are using VS Code, you can mouse over debugger, click Quick Fix..., and select Disable no-debugger for the entire file, as shown as below:

enter image description here

Then the IDE will add the following comment at the top of the file to disable the rule for you:

/* eslint-disable no-debugger */

See more on the eslint no-debugger rule.

Upvotes: 9

husayt
husayt

Reputation: 15149

You can do that like this:

/* eslint-disable no-debugger */
... code that violates rule ...
/* eslint-enable no-debugger */

Upvotes: 26

Related Questions