Disable the linter

by Simeon Petrov

Thumbnail for Disable the linter
  • NOTES
  • RANDOM

This is mainly a personal reference, so I don’t go into a google hunt for good examples each year.

Local - Disable by a comment

Whole file

  /* eslint-disable */
 console.log('Such creativity, WoW.');

Specific block

 /* eslint-disable */
 console.log('Such creativity, WoW.');
 /* eslint-enable */

Specific rule for a whole file

 // eslint-disable no-console
 console.log('Such creativity, WoW.');

Ignore single line

 // eslint-disable-next-line no-console
  console.log('Such creativity, WOW.');

 // OR

 console.log('WOW again.'); // eslint-disable-line no-console

Global - disable by config

Here is everything https://eslint.org/docs/latest/use/configure/ignore

.eslintignore

Ignore whole directories or file patterns. This disables every eslint rule for these files.

 build/*.{ts,js,vue}
 src/**/*.mock.ts

.eslintrc overrides

Use the overrides property in your .eslintrc file to “override” your previous settings (from plugins or rules:{ } ) for a specific pattern. This disables only specific rules for these files.

 overrides: [
     {
       files: ['src/mocks/**/*', 'src/**/__tests__/mocks/*'],
       rules: {
         camelcase: 'off',
         'sonarjs/no-duplicate-string': 'off'
       }
     },
     {
       files: ['src/**/*.spec.ts'],
       rules: {
         'no-console': process.env.NODE_ENV === 'production' ? ['error', { allow: ['error', 'info'] }] : 'off'
       }
     }
   ]