From 520c92270eed6e90c1a796e8af275980f01705e0 Mon Sep 17 00:00:00 2001 From: Henrique Barcelos Date: Fri, 13 Sep 2019 21:49:55 -0300 Subject: [PATCH] Docs: Added naming convention details to plugin usage (#12202) * Docs: Added naming convention details user guide Added clarification about the answer regarding #12190. * Docs: reverted markdown list style to the original --- docs/developer-guide/working-with-plugins.md | 2 +- docs/user-guide/configuring.md | 65 ++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/docs/developer-guide/working-with-plugins.md b/docs/developer-guide/working-with-plugins.md index 5a8fd764b38..a2b238cc936 100644 --- a/docs/developer-guide/working-with-plugins.md +++ b/docs/developer-guide/working-with-plugins.md @@ -1,6 +1,6 @@ # Working with Plugins -Each plugin is an npm module with a name in the format of `eslint-plugin-`, such as `eslint-plugin-jquery`. You can also use scoped packages in the format of `@/eslint-plugin-` such as `@jquery/eslint-plugin-jquery`. +Each plugin is an npm module with a name in the format of `eslint-plugin-`, such as `eslint-plugin-jquery`. You can also use scoped packages in the format of `@/eslint-plugin-` such as `@jquery/eslint-plugin-jquery` or even `@/eslint-plugin` such as `@jquery/eslint-plugin`. ## Create a Plugin diff --git a/docs/user-guide/configuring.md b/docs/user-guide/configuring.md index 0818f85e2a5..8f5fd286d3a 100644 --- a/docs/user-guide/configuring.md +++ b/docs/user-guide/configuring.md @@ -323,6 +323,71 @@ And in YAML: **Note:** Plugins are resolved relative to the current working directory of the ESLint process. In other words, ESLint will load the same plugin as a user would obtain by running `require('eslint-plugin-pluginname')` in a Node REPL from their project root. +### Naming Convention + +#### Include a Plugin + +The `eslint-plugin-` prefix can be omitted for non-scoped packages + +```js +{ + // ... + "plugins": [ + "jquery", // means eslint-plugin-jquery + ] + // ... +} +``` + +The same rule does apply to scoped packages: + +```js +{ + // ... + "plugins": [ + "@jquery/jquery", // means @jquery/eslint-plugin-jquery + "@foobar" // means @foobar/eslint-plugin + ] + // ... +} +``` + +#### Use a Plugin + +When using rules, environments or configs defined by plugins, they must be referenced following the convention: + +* `eslint-plugin-foo` → `foo/a-rule` +* `@foo/eslint-plugin` → `@foo/a-config` +* `@foo/eslint-plugin-bar` → `@foo/bar/a-environment` + +For example: + +```js +{ + // ... + "plugins": [ + "jquery", // eslint-plugin-jquery + "@foo/foo", // @foo/eslint-plugin-foo + "@bar" // @bar/eslint-plugin + ], + "extends": [ + "plugin:@foo/foo/recommended", + "plugin:@bar/recommended" + ], + "rules": [ + "jquery/a-rule": "error", + "@foo/foo/some-rule": "error", + "@bar/another-rule": "error" + ], + "env": { + "jquery/jquery": true, + "@foo/foo/env-foo": true, + "@bar/env-bar": true, + } + // ... +} +``` + ## Configuring Rules ESLint comes with a large number of rules. You can modify which rules your project uses either using configuration comments or configuration files. To change a rule setting, you must set the rule ID equal to one of these values: