@keeex/eslint-config 1.7.1 → 1.7.4

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
@@ -158,3 +158,5 @@ If React Native is enabled, `eslint-plugin-react-native` must be installed.
158
158
  Promise support requires `eslint-plugin-promise`.
159
159
  If mocha is used as the testsuite, `eslint-plugin-mocha` must be installed.
160
160
  Import support requires `eslint-plugin-import`.
161
+
162
+ If both import and typescript is used, `eslint-import-resolver-typescript` is needed.
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.7.1",
4
+ "version": "1.7.4",
5
5
  "main": "src/index.js",
6
6
  "files": [
7
7
  "src/**/*.js"
@@ -32,7 +32,8 @@
32
32
  "eslint-plugin-promise": "6.x",
33
33
  "eslint-plugin-react": "7.x",
34
34
  "eslint-plugin-react-hooks": "4.x",
35
- "eslint-plugin-react-native": "4.x"
35
+ "eslint-plugin-react-native": "4.x",
36
+ "eslint-import-resolver-typescript": "2.x"
36
37
  },
37
38
  "peerDependenciesMeta": {
38
39
  "eslint": {
@@ -61,6 +62,9 @@
61
62
  },
62
63
  "eslint-plugin-mocha": {
63
64
  "optional": true
65
+ },
66
+ "eslint-import-resolver-typescript": {
67
+ "optional": true
64
68
  }
65
69
  },
66
70
  "publishConfig": {
@@ -27,13 +27,7 @@ const DEFAULT_CYCLE_DEPTH = 3;
27
27
 
28
28
  module.exports = {
29
29
  plugins: ["import"],
30
- extendsBase: (presetConfig, allOptions) => {
31
- const result = ["plugin:promise/recommended"];
32
- if (allOptions.typescript) {
33
- result.push("plugin:import/typescript");
34
- }
35
- return result;
36
- },
30
+ extendsBase: ["plugin:import/recommended"],
37
31
  rules: presetConfig => {
38
32
  let importDepth;
39
33
  if (
@@ -154,28 +154,45 @@ module.exports = {
154
154
  }
155
155
  return null;
156
156
  },
157
- extendsBase: presetOptions => {
157
+ extendsBase: (presetOptions, allOptions) => {
158
158
  const typescriptBase = [
159
159
  "plugin:@typescript-eslint/eslint-recommended",
160
160
  "plugin:@typescript-eslint/recommended",
161
161
  "plugin:@typescript-eslint/recommended-requiring-type-checking",
162
162
  ];
163
- if (useTypes(presetOptions)) {
164
- return [
165
- ...typescriptBase,
166
- ...extendsBaseType,
167
- ];
168
- }
169
- return typescriptBase;
163
+ const typeExtends = useTypes(presetOptions)
164
+ ? extendsBaseType
165
+ : [];
166
+ const importExtends = allOptions["import"]
167
+ ? ["plugin:import/typescript"]
168
+ : [];
169
+ return [
170
+ ...typescriptBase,
171
+ ...typeExtends,
172
+ ...importExtends,
173
+ ];
170
174
  },
171
- rules: presetOptions => {
172
- if (useTypes(presetOptions)) {
173
- return {
174
- ...rulesBase,
175
- ...rulesType,
176
- };
177
- }
178
- return rulesBase;
175
+ rules: (presetOptions, allOptions) => {
176
+ // There seem to be no way for now to have import understand that ".js" imports should refer
177
+ // to ".ts" files.
178
+ // Either it complains about needing the ".ts" suffix (which is wrong) or it enforces having
179
+ // an extension, but doesn't actually resolve the file (since we disable the ts-specific
180
+ // resolver).
181
+ // If this change in the future, restore full ts-resolver support from import plugin.
182
+ const importOverride = allOptions.import
183
+ ? {
184
+ "import/no-unresolved": "off",
185
+ "import/no-cycle": "off",
186
+ }
187
+ : undefined;
188
+ const typesOverride = useTypes(presetOptions)
189
+ ? rulesType
190
+ : undefined;
191
+ return {
192
+ ...rulesBase,
193
+ ...typesOverride,
194
+ ...importOverride,
195
+ };
179
196
  },
180
197
  },
181
198
  ],
package/src/index.js CHANGED
@@ -118,8 +118,9 @@ const addRules = (
118
118
  config,
119
119
  presetRules,
120
120
  presetConfig,
121
+ allOptions,
121
122
  ) => {
122
- const newRules = applyConfig(presetRules, presetConfig);
123
+ const newRules = applyConfig(presetRules, presetConfig, allOptions);
123
124
  if (!newRules) return;
124
125
 
125
126
  if (!config.rules) {
@@ -158,9 +159,10 @@ const addSettings = (
158
159
  config,
159
160
  presetSettings,
160
161
  presetConfig,
162
+ allOptions,
161
163
  ) => {
162
164
  const newSettings = typeof presetSettings === "function"
163
- ? presetSettings(presetConfig)
165
+ ? presetSettings(presetConfig, allOptions)
164
166
  : presetSettings;
165
167
  if (!newSettings) return;
166
168
 
@@ -225,7 +227,7 @@ const mergePreset = (
225
227
  ) => {
226
228
  setParser(config, presetDef.parser, presetConfig);
227
229
  addParserOptions(config, presetDef.parserOptions, presetConfig);
228
- addSettings(config, presetDef.settings, presetConfig);
230
+ addSettings(config, presetDef.settings, presetConfig, allOptions);
229
231
  addEnvs(config, presetDef.env, presetConfig);
230
232
  addPlugins(config, presetDef.plugins, presetConfig);
231
233
  addExtends(config, presetDef.extendsBase, presetConfig, allOptions);