Allow debugger; statements in certain files, using ESLint - 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?

You can also disable ESLint in the same line:
debugger; // eslint-disable-line no-debugger

You can do that like this:
/* eslint-disable no-debugger */
... code that violates rule ...
/* eslint-enable no-debugger */

Update your eslint configuration file (.eslintrc etc) with such rule:
"rules": {
"no-debugger":"off"
}

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:
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.

OR, add:
"no-debugger": false
to the bottom of tslint.json, to disable this warning for all files.

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 */

Related

EsLint: Hide undefined functions Warnings

How can i hide all un-used Functions warnings in Javascript (using EsLint)? If i use following command, it will only hide warnings of the defined functions.
/* global lg, storeKeys, mergeDeep, count, preg_match */
Is there a way to hide all functions warnings without hiding the un-defined Variables? Like:
/* eslint-disable no-undef-functions */

How to allow one white line after an opening brace in ESLint-prettier?

My typescript code is setup with eslint-prettier. I'd like to have the option of formatting my functions to look like this:
function Name(){
// First line
...
}
... rather than always having to look like this:
function Name(){
// First line
...
}
Is there a setting within prettier and/or ESLint to enable this?

ESLint / VSCode, the whole object is underlined

Since the last VSCode or Eslint extension update, the whole object is underlined when an error or a warning is detected. An idea why ?
I’m guessing you’re exporting this function from Webpack configuration module. I can think of two options that come to play.
First, define named function:
module.exports = function withBaseConfiguration() {
return { /* configuration goes here */ }
}
Second, disable the ESLint rule for this file by placing following at the top:
/* eslint-disable func-names */

When use istanbul, is there any way to dynamic require config.js?

The logEnable is write in config.js, is there any way to change the value during testing? So than I can improve the branch coverage.
You could ignore parts of code from testing: https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md
Skip an if or else path with /* istanbul ignore if */ or /* istanbul ignore else */ respectively.
For all other cases, skip the next 'thing' in the source with: /* istanbul ignore next */
Or add a single test that checks just those logging functions with both logging enabled and disabled (you can override required modules, like your config, for example with proxyquire: https://github.com/thlorenz/proxyquire).

Prevent ReSharper from formatting specific code block

Is there a way to prevent ReSharper from formatting a specific code block in a file? Something like:
void MyMethod ()
{
// ReSharper disable formatting
PRE = { my top format } /* no rules */ ;
// ReSharper enable formatting
}
Now it is possible in version 2017.3 like this:
// #formatter:off — disable formatter after this line
// #formatter:on — enable formatter after this line
At the moment this is not possible. See feature request RSRP-187963.
As a workaround, if you have a big chunk of "pre-formatted" code, you could move it to an own (partial class) file and add it to the "Generated Code" configuration list. This disables R#'s "Code Cleanup" for this file. Note that it also disables the inspections! (Unfortunately the "Generated Code Region" feature only disables the inspections, not the "Code Cleanup" for a region, as of R# version 9.2.)

Resources