@keeex/eslint-config 1.7.2 → 1.7.3

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.2",
4
+ "version": "1.7.3",
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:import/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 (
@@ -138,6 +138,19 @@ const rulesBase = {
138
138
  };
139
139
 
140
140
  module.exports = {
141
+ settings: (presetConfig, allOptions) => {
142
+ if (useTypes(presetConfig) && allOptions["import"]) {
143
+ return {
144
+ "import/parsers": {"@typescript-eslint/parser": [".ts", ".tsx"]},
145
+ "import/resolver": {
146
+ "typescript": {
147
+ alwaysTryTypes: true,
148
+ project: presetConfig,
149
+ },
150
+ },
151
+ };
152
+ }
153
+ },
141
154
  overrides: [
142
155
  {
143
156
  files: [
@@ -154,28 +167,43 @@ module.exports = {
154
167
  }
155
168
  return null;
156
169
  },
157
- extendsBase: presetOptions => {
170
+ extendsBase: (presetOptions, allOptions) => {
158
171
  const typescriptBase = [
159
172
  "plugin:@typescript-eslint/eslint-recommended",
160
173
  "plugin:@typescript-eslint/recommended",
161
174
  "plugin:@typescript-eslint/recommended-requiring-type-checking",
162
175
  ];
163
- if (useTypes(presetOptions)) {
164
- return [
165
- ...typescriptBase,
166
- ...extendsBaseType,
167
- ];
168
- }
169
- return typescriptBase;
176
+ const typeExtends = useTypes(presetOptions)
177
+ ? extendsBaseType
178
+ : [];
179
+ const importExtends = allOptions["import"]
180
+ ? ["plugin:import/typescript"]
181
+ : [];
182
+ return [
183
+ ...typescriptBase,
184
+ ...typeExtends,
185
+ ...importExtends,
186
+ ];
170
187
  },
171
- rules: presetOptions => {
172
- if (useTypes(presetOptions)) {
173
- return {
174
- ...rulesBase,
175
- ...rulesType,
176
- };
177
- }
178
- return rulesBase;
188
+ rules: (presetOptions, allOptions) => {
189
+ const importOverride = allOptions.import
190
+ ? {
191
+ "import/no-unresolved": "off",
192
+ "import/extensions": [
193
+ "error",
194
+ "always",
195
+ {"ts": "never"},
196
+ ],
197
+ }
198
+ : undefined;
199
+ const typesOverride = useTypes(presetOptions)
200
+ ? rulesType
201
+ : undefined;
202
+ return {
203
+ ...rulesBase,
204
+ ...typesOverride,
205
+ ...importOverride,
206
+ };
179
207
  },
180
208
  },
181
209
  ],
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);