@keeex/eslint-config 1.8.3 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -24,6 +24,7 @@ module.exports = eslintConfig(
24
24
  reacthooks: true,
25
25
  reactnative: true,
26
26
  typescript: "./tsconfig.json",
27
+ deprecation: true,
27
28
  mocha: true,
28
29
  },
29
30
  {
@@ -107,6 +108,10 @@ Instead, it is advised to provide the path to the typescript configuration file
107
108
  (typically `tsconfig.json`), in which case rules that requires typing
108
109
  informations are enabled.
109
110
 
111
+ ### Deprecation
112
+ Warn when using deprecated calls/properties.
113
+ This only work with TypeScript enabled with project types.
114
+
110
115
  ### React/JSX
111
116
  To improve handling of React/JSX, set `jsx` to true.
112
117
  It is also possible to pass a string indicating the expected React version.
@@ -153,6 +158,7 @@ Dependencies
153
158
  Depend on `eslint`.
154
159
  If typescript is enabled, `@typescript-eslint/eslint-plugin`,
155
160
  `@typescript-eslint/parser` must be installed.
161
+ If deprecation is enabled, `eslint-plugin-deprecation` must be installed.
156
162
  If React/JSX is enabled, `eslint-plugin-react` must be installed.
157
163
  If React Hooks is enabled, `eslint-plugin-react-hooks` must be installed.
158
164
  If React Native is enabled, `eslint-plugin-react-native` must be installed.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@keeex/eslint-config",
3
3
  "description": "Common eslint configuration",
4
- "version": "1.8.3",
4
+ "version": "1.9.0",
5
5
  "main": "src/index.js",
6
6
  "files": [
7
7
  "src/**/*.js"
@@ -33,6 +33,7 @@
33
33
  "eslint": "8.x",
34
34
  "eslint-import-resolver-typescript": "2.x",
35
35
  "eslint-plugin-chai-friendly": "0.x",
36
+ "eslint-plugin-deprecation": "^1.3.3",
36
37
  "eslint-plugin-import": "2.x",
37
38
  "eslint-plugin-mocha": "10.x",
38
39
  "eslint-plugin-promise": "6.x",
@@ -65,6 +66,9 @@
65
66
  "eslint-plugin-chai-friendly": {
66
67
  "optional": true
67
68
  },
69
+ "eslint-plugin-deprecation": {
70
+ "optional": true
71
+ },
68
72
  "eslint-plugin-react-hooks": {
69
73
  "optional": true
70
74
  },
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ plugins: (presetSettings, allOptions) => {
3
+ if (typeof allOptions.typescript !== "string") return undefined;
4
+ return ["deprecation"];
5
+ },
6
+ rules: {},
7
+ };
@@ -8,6 +8,12 @@ const {
8
8
  * Check if types-based rules can be used
9
9
  */
10
10
  const useTypes = presetOptions => typeof presetOptions === "string";
11
+ const useDeprecation = (presetOptions, allOptions) => {
12
+ if (!useTypes(presetOptions)) return false;
13
+ const deprecationKey = "deprecation";
14
+ if (!(deprecationKey in allOptions)) return true;
15
+ return allOptions[deprecationKey] === true;
16
+ };
11
17
 
12
18
  const rulesBase = {
13
19
  "@typescript-eslint/array-type": [
@@ -287,10 +293,14 @@ module.exports = {
287
293
  const typesOverride = useTypes(presetOptions)
288
294
  ? rulesType
289
295
  : undefined;
296
+ const deprecationOverride = useDeprecation(presetOptions, allOptions)
297
+ ? {"deprecation/deprecation": "warn"}
298
+ : undefined;
290
299
  return {
291
300
  ...rulesBase,
292
301
  ...typesOverride,
293
302
  ...importOverride,
303
+ ...deprecationOverride,
294
304
  };
295
305
  },
296
306
  },
package/src/index.js CHANGED
@@ -4,6 +4,7 @@ const cfgImport = require("./config/import.js");
4
4
  const cfgReactHooks = require("./config/reacthooks.js");
5
5
  const cfgReactNative = require("./config/reactnative.js");
6
6
  const cfgTypescript = require("./config/typescript.js");
7
+ const cfgDeprecation = require("./config/deprecation.js");
7
8
  const cfgPromise = require("./config/promise.js");
8
9
  const cfgMocha = require("./config/mocha.js");
9
10
 
@@ -54,15 +55,16 @@ const addPlugins = (
54
55
  config,
55
56
  presetPlugins,
56
57
  presetConfig,
58
+ allOptions,
57
59
  ) => {
58
- const newPlugins = applyConfig(presetPlugins, presetConfig);
60
+ const newPlugins = applyConfig(presetPlugins, presetConfig, allOptions);
59
61
  if (!newPlugins) return;
60
62
 
61
63
  if (!config.plugins) {
62
- config.plugins = [...presetPlugins];
64
+ config.plugins = [...newPlugins];
63
65
  return;
64
66
  }
65
- presetPlugins.forEach(newPlugin => {
67
+ newPlugins.forEach(newPlugin => {
66
68
  if (config.plugins.includes(newPlugin)) return;
67
69
 
68
70
  config.plugins.push(newPlugin);
@@ -201,6 +203,7 @@ const presets = {
201
203
  "reacthooks": cfgReactHooks,
202
204
  "reactnative": cfgReactNative,
203
205
  "typescript": cfgTypescript,
206
+ "deprecation": cfgDeprecation,
204
207
  "mocha": cfgMocha,
205
208
  };
206
209
 
@@ -213,6 +216,7 @@ const presetsOrder = [
213
216
  "reactnative",
214
217
  "reacthooks",
215
218
  "typescript",
219
+ "deprecation",
216
220
  "mocha",
217
221
  ];
218
222
 
@@ -229,7 +233,7 @@ const mergePreset = (
229
233
  addParserOptions(config, presetDef.parserOptions, presetConfig);
230
234
  addSettings(config, presetDef.settings, presetConfig, allOptions);
231
235
  addEnvs(config, presetDef.env, presetConfig);
232
- addPlugins(config, presetDef.plugins, presetConfig);
236
+ addPlugins(config, presetDef.plugins, presetConfig, allOptions);
233
237
  addExtends(config, presetDef.extendsBase, presetConfig, allOptions);
234
238
  addRules(config, presetDef.rules, presetConfig, allOptions);
235
239
  if (presetDef.overrides) {
@@ -275,6 +279,7 @@ module.exports = (
275
279
  if (config.base === undefined) config.base = true;
276
280
  if (config.promise === undefined) config.promise = true;
277
281
  if (config.import === undefined) config.import = true;
282
+ if (config.deprecation === undefined) config.deprecation = true;
278
283
 
279
284
  mergeAllPresets(result, config);
280
285
  return result;