From 3df76c61a15679e7f9a3c0e9027c228e2939aace Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Mon, 22 Jun 2020 11:54:52 +0100 Subject: [PATCH] New config: `recommended` just includes `variable-pattern` rule Part of #249 --- README.md | 12 ++++++++---- README.md.template | 10 +++++++--- docs/rules/variable-pattern.md | 2 ++ src/index.js | 5 +++++ test-self/.eslintrc.json | 5 ++++- test-self/all/.eslintrc.json | 5 +---- test-self/recommended/.eslintrc.json | 3 +++ test-self/recommended/test.js | 2 ++ 8 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 test-self/recommended/.eslintrc.json create mode 100644 test-self/recommended/test.js diff --git a/README.md b/README.md index 3974ea74..4c7a2a01 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,13 @@ Add `no-jquery` to the plugins section of your `.eslintrc` configuration file. Y } ``` -The config `plugin:no-jquery/deprecated` includes all known deprecated and removed code, and is updated as new releases of jQuery come out. You can instead use configs targeting specific versions of jQuery if you know the environment in which your code will operate. There is a config for jQuery 3.5.x+ environments (`deprecated-3.5`), and configs for other minor releases that include deprecations (`deprecated-3.4`, `deprecated-1.10` etc.). Deprecation configs are cumulative, so they include all the rules for jQuery versions below them. +## 📋 Configs -The config `plugin:no-jquery/all` includes all methods and utilies and should be used when you are aiming to remove all jQuery usage from your code. +The config **`plugin:no-jquery/recommended`** includes the recommended rule [`no-jquery/variable-pattern`](docs/rules/variable-pattern.md) which is required for method rules to work correctly. + +The config **`plugin:no-jquery/deprecated`** includes all known deprecated and removed code, and is updated as new releases of jQuery come out. You can instead use configs targeting specific versions of jQuery if you know the environment in which your code will operate. There is a config for jQuery 3.5.x+ environments (`deprecated-3.5`), and configs for other minor releases that include deprecations (`deprecated-3.4`, `deprecated-1.10` etc.). Deprecation configs are cumulative, so they include all the rules for jQuery versions below them. + +The config **`plugin:no-jquery/all`** includes all methods and utilies and should be used when you are aiming to remove all jQuery usage from your code. Alternatively, you can pick out rules individually (see below). @@ -75,7 +79,7 @@ The following global settings can be used under the `no-jquery` property to conf ## 📖 Rules -Where rules are included in the configs `slim`, `all` or `deprecated-X.X` it is indicated below. Where rules are included with options this is indicated with a `†`. +Where rules are included in the configs `recommended`, `slim`, `all` or `deprecated-X.X` it is indicated below. Where rules are included with options this is indicated with a `†`. * [`no-jquery/no-ajax`](docs/rules/no-ajax.md) `slim`, `all` * [`no-jquery/no-ajax-events`](docs/rules/no-ajax-events.md) `slim` * [`no-jquery/no-and-self`](docs/rules/no-and-self.md) `1.8` @@ -166,7 +170,7 @@ Where rules are included in the configs `slim`, `all` or `deprecated-X.X` it is * [`no-jquery/no-visibility`](docs/rules/no-visibility.md) `all` * [`no-jquery/no-when`](docs/rules/no-when.md) `all` * [`no-jquery/no-wrap`](docs/rules/no-wrap.md) `all` -* [`no-jquery/variable-pattern`](docs/rules/variable-pattern.md) +* [`no-jquery/variable-pattern`](docs/rules/variable-pattern.md) `recommended` ### ⚠️ Deprecated diff --git a/README.md.template b/README.md.template index 3d388520..36f22e71 100644 --- a/README.md.template +++ b/README.md.template @@ -33,9 +33,13 @@ Add `no-jquery` to the plugins section of your `.eslintrc` configuration file. Y } ``` -The config `plugin:no-jquery/deprecated` includes all known deprecated and removed code, and is updated as new releases of jQuery come out. You can instead use configs targeting specific versions of jQuery if you know the environment in which your code will operate. There is a config for jQuery 3.5.x+ environments (`deprecated-3.5`), and configs for other minor releases that include deprecations (`deprecated-3.4`, `deprecated-1.10` etc.). Deprecation configs are cumulative, so they include all the rules for jQuery versions below them. +## 📋 Configs -The config `plugin:no-jquery/all` includes all methods and utilies and should be used when you are aiming to remove all jQuery usage from your code. +The config **`plugin:no-jquery/recommended`** includes the recommended rule [`no-jquery/variable-pattern`](docs/rules/variable-pattern.md) which is required for method rules to work correctly. + +The config **`plugin:no-jquery/deprecated`** includes all known deprecated and removed code, and is updated as new releases of jQuery come out. You can instead use configs targeting specific versions of jQuery if you know the environment in which your code will operate. There is a config for jQuery 3.5.x+ environments (`deprecated-3.5`), and configs for other minor releases that include deprecations (`deprecated-3.4`, `deprecated-1.10` etc.). Deprecation configs are cumulative, so they include all the rules for jQuery versions below them. + +The config **`plugin:no-jquery/all`** includes all methods and utilies and should be used when you are aiming to remove all jQuery usage from your code. Alternatively, you can pick out rules individually (see below). @@ -74,7 +78,7 @@ The following global settings can be used under the `no-jquery` property to conf ## 📖 Rules -Where rules are included in the configs `slim`, `all` or `deprecated-X.X` it is indicated below. Where rules are included with options this is indicated with a `†`. +Where rules are included in the configs `recommended`, `slim`, `all` or `deprecated-X.X` it is indicated below. Where rules are included with options this is indicated with a `†`. ### ⚠️ Deprecated diff --git a/docs/rules/variable-pattern.md b/docs/rules/variable-pattern.md index aa8dbf86..b6e312b9 100644 --- a/docs/rules/variable-pattern.md +++ b/docs/rules/variable-pattern.md @@ -2,6 +2,8 @@ Disallows variable names which don't match `variablePattern` in settings (by default a `$`-prefix). +⚙️ This rule is enabled in `plugin:no-jquery/recommended`. + ## Rule details ❌ Examples of **incorrect** code: diff --git a/src/index.js b/src/index.js index b92a5dfb..0740f1b2 100644 --- a/src/index.js +++ b/src/index.js @@ -101,6 +101,11 @@ module.exports = { 'variable-pattern': require( './rules/variable-pattern' ) }, configs: { + recommended: { + rules: { + 'no-jquery/variable-pattern': 'error' + } + }, // Use this config if you are using jQuery slim build slim: { rules: { diff --git a/test-self/.eslintrc.json b/test-self/.eslintrc.json index 03d308a8..5acab89c 100644 --- a/test-self/.eslintrc.json +++ b/test-self/.eslintrc.json @@ -6,7 +6,10 @@ "$": "readonly" }, "rules": { + "no-implicit-globals": "off", "no-undef": "off", - "no-unused-expressions": "off" + "no-underscore-dangle": "off", + "no-unused-expressions": "off", + "no-unused-vars": "off" } } diff --git a/test-self/all/.eslintrc.json b/test-self/all/.eslintrc.json index e7d81d79..946e59db 100644 --- a/test-self/all/.eslintrc.json +++ b/test-self/all/.eslintrc.json @@ -1,6 +1,3 @@ { - "extends": "plugin:self/all", - "rules": { - "no-underscore-dangle": "off" - } + "extends": "plugin:self/all" } diff --git a/test-self/recommended/.eslintrc.json b/test-self/recommended/.eslintrc.json new file mode 100644 index 00000000..1539e74d --- /dev/null +++ b/test-self/recommended/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "plugin:self/recommended" +} diff --git a/test-self/recommended/test.js b/test-self/recommended/test.js new file mode 100644 index 00000000..0093745b --- /dev/null +++ b/test-self/recommended/test.js @@ -0,0 +1,2 @@ +// eslint-disable-next-line self/variable-pattern +var foo = $( '.foo' );