All Projects → mradionov → eslint-plugin-disable

mradionov / eslint-plugin-disable

Licence: MIT license
Disable ESLint plugins using file path patterns and inline comments

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to eslint-plugin-disable

eslint-plugin-rulesdir
An ESLint plugin to load project-specific ESLint rules
Stars: ✭ 28 (-45.1%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Boundaries
Eslint plugin checking architecture boundaries between elements
Stars: ✭ 157 (+207.84%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Css Modules
Project status: NOT MAINTAINED; Checks that you are using the existent css/scss classes, no more no less
Stars: ✭ 115 (+125.49%)
Mutual labels:  eslint, eslint-plugin
Typescript Eslint
✨ Monorepo for all the tooling which enables ESLint to support TypeScript
Stars: ✭ 10,831 (+21137.25%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Ember
An ESlint plugin that provides set of rules for Ember Applications based on commonly known good practices.
Stars: ✭ 240 (+370.59%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin I18n Json
Fully extendable eslint plugin for JSON i18n translation files.
Stars: ✭ 101 (+98.04%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Unicorn
Various awesome ESLint rules
Stars: ✭ 2,157 (+4129.41%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Lwc
Official ESLint rules for LWC
Stars: ✭ 51 (+0%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Eslint Comments
Additional ESLint rules for directive comments of ESLint.
Stars: ✭ 221 (+333.33%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Ava
ESLint rules for AVA
Stars: ✭ 209 (+309.8%)
Mutual labels:  eslint, eslint-plugin
Eslint Mdx
ESLint Parser/Plugin for MDX
Stars: ✭ 89 (+74.51%)
Mutual labels:  eslint, eslint-plugin
eslint-plugin-pug
An ESLint plugin for linting inline scripts in Pug files
Stars: ✭ 17 (-66.67%)
Mutual labels:  eslint, eslint-plugin
Sowing Machine
🌱A React UI toolchain & JSX alternative
Stars: ✭ 64 (+25.49%)
Mutual labels:  eslint, eslint-plugin
eslint-plugin-editorconfig
An ESLint plugin to enforce EditorConfig rules
Stars: ✭ 22 (-56.86%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Monorepo
ESLint Plugin for monorepos
Stars: ✭ 56 (+9.8%)
Mutual labels:  eslint, eslint-plugin
Eslint Import Resolver Alias
a simple Node behavior import resolution plugin for eslint-plugin-import, supporting module alias
Stars: ✭ 121 (+137.25%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin
ESLint configurations and additional rules for me
Stars: ✭ 19 (-62.75%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Vue I18n
🌐 ESLint plugin for Vue I18n
Stars: ✭ 50 (-1.96%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Lodash
ESLint rules for lodash
Stars: ✭ 208 (+307.84%)
Mutual labels:  eslint, eslint-plugin
Eslint Plugin Mocha
ESLint rules for mocha
Stars: ✭ 249 (+388.24%)
Mutual labels:  eslint, eslint-plugin

eslint-plugin-disable Build status

Disable ESLint plugins using file path patterns and inline comments

..which means all disabled plugins' errors and warnings won't appear in ESLint report.

  • Example: inline comments:

    /* eslint-plugin-disable react */
    
    function greet(name) {
      console.log('Hi, ' + name);
    }
  • Example: file path patterns (.eslintrc):

    {
      "plugins": ["react", "disable"],
      "processor": "disable/disable",
      "overrides": [
        {
          "files": ["tests/**/*.test.js"],
          "settings": {
            "disable/plugins": ["react"]
          }
        }
      ]
    }

Install

npm install eslint-plugin-disable --save-dev

Use

Add plugin to a config file (.eslintrc) and make it default processor:

{
  "plugins": ["disable"],
  "processor": "disable/disable"
}

Inline comments

Regular disable

Plugin adds a custom directive to use in files in a form of inline comment, which allows to disable entire plugins for this file. Plugin names have to be the same as in ESLint config file, separated by comma.

The following directive will disable "react" and "jsx-a11y" plugins for this particular file.

/* eslint-plugin-disable react, jsx-a11y */

function greet(name) {
  console.log('Hi, ' + name);
}

If no any plugins provided - all plugins registered in ESLint config will be disabled:

/* eslint-plugin-disable */

function greet(name) {
  console.log('Hi, ' + name);
}
Disable all except

Another custom option allows to disable all plugins except ones that are specified. It might be useful when there are a lot of plugins in the project and it is required to use one or two of them for particular files, usage of regular disable syntax might be cumbersome to maintain if there are plans to add new plugins to the project. Plugin names have to be the same as in ESLint config file, separated by comma.

The following directive will disable all plugins registered in ESLint config except "react" and "jsx-a11y".

/* eslint-plugin-disable-all-except react, jsx-a11y */

function greet(name) {
  console.log('Hi, ' + name);
}

Notes:

  • disable all except: if no plugins specified, then none of the plugins listed in ESLint config will be disabled i.e. error messages will not be removed from ESLint report
  • all target files must have a "disable/disable" processor enabled for them, including usage of ESLint 6 Overrides
  • whitespace inside block comment is ignored
  • original file is not modified
  • there is no way to restore behavior with another inline option

File paths

Regular disable

To disable plugins for file paths use new ESLint 6+ Overrides feature in config (.eslintrc). It has many different configurations for glob path patterns, ignore patterns and it basically creates a nested config for a list of files (ESLint docs for more info). This list of files should be assigned with a "disable/disable" processor in order for plugin to work. You can have multiple "overrides" entries with different paths and different plugins to disable.

The following config will:

  • disable "import" and "jsx-a11y" plugins for all files matching "tests/**/*.test.js" glob pattern
  • disable "react" plugin for all files matching "lib/*.js" glob pattern
{
  "plugins": ["import", "react", "jsx-a11y", "disable"],
  "processor": "disable/disable",
  "overrides": [
    {
      "files": ["tests/**/*.test.js"],
      "settings": {
        "disable/plugins": ["import", "jsx-a11y"]
      }
    },
    {
      "files": ["lib/*.js"],
      "settings": {
        "disable/plugins": ["react"]
      }
    }
  ]
}

To disable all registered plugins you can simply omit "disable/plugins" setting or use a star in place of plugin name:

{
  "plugins": ["import", "react", "jsx-a11y", "disable"],
  "processor": "disable/disable",
  "overrides": [
    {
      "files": ["tests/**/*.test.js"],
      "settings": {
        "disable/plugins": "*"
      }
    }
  ]
}
Disable all except

To disable all plugins except specified ones use "disableAllExcept" flag in config settings (.eslintrc).

The following config will disable all registered plugins except "react" for all files mathing "tests/**/*.test.js" glob pattern ("import" and "jsx-a11y" will be disabled).

{
  "plugins": ["import", "react", "jsx-a11y", "disable"],
  "processor": "disable/disable",
  "overrides": [
    {
      "files": ["tests/**/*.test.js"],
      "settings": {
        "disable/disableAllExcept": true,
        "disable/plugins": ["react"]
      }
    }
  ]
}

Conflicts with other plugins

Some ESLint plugins also use processors, which creates a conflict with this plugin, because ESLint does not allow to chain processors for the same source files without processing it and producing another files. There is a setting "externalProcessor", which accepts a processor identifier "pluginName/processorName" and makes this plugin to call other plugin's processor before disabling the rules.

One of the cases is "eslint-plugin-vue":

{
  "plugins": ["vue", "disable"],
  "processor": "disable/disable",
  "settings": {
    "disable/plugins": ["vue"],
    "disable/externalProcessor": "vue/.vue"
  }
}

As a plugin might export multiple processors, the only way to find out what "processorName" to use, is to browse plugin's sources. If you don't know it, then you can just skip "processorName" in identifier and only leave "pluginName" - this way the first available processor will be auto-picked.

{
  "plugins": ["vue", "disable"],
  "processor": "disable/disable",
  "settings": {
    "disable/plugins": ["vue"],
    "disable/externalProcessor": "vue"
  }
}

Option precedence

All the options are not merged together, there is a strict order in which they apply:

  1. Inline comment to disable all plugins except specified (docs)
  2. Inline comment to disable specified plugins (docs)
  3. Settings paths to disable all plugins except specified (docs)
  4. Settings paths to disable specified plugins (docs)

If first option applies, then only plugins mentioned in this option will be used to disable, the rest of the options down the list will be ignored. If first and second options do not apply (no inline comments in file), but third option does apply, then only plugins mentioned in third option will be used to disable, the rest will be ignored.

Support

eslint eslint-plugin-disable
>= 0.16.0 <6.0.0 <=1.0.5
>=6.0.0 >=2.0.0

Migrating

Origin

Unfortunately this feature is not natively supported in ESLint yet, so this module may become a temporary workaround. Read the following issues for additional information:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].