@vijayhardaha/dev-config 2.0.2 → 2.0.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/package.json +1 -1
- package/src/eslint/lib/build-config.js +23 -1
- package/src/eslint/next.js +7 -2
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@ import prettierRecommended from 'eslint-plugin-prettier/recommended';
|
|
|
7
7
|
import { globalIgnores } from './ignores.js';
|
|
8
8
|
import { commonLanguageOptions } from './language-options.js';
|
|
9
9
|
import { commonRules } from './rules.js';
|
|
10
|
+
import { commonParser } from './setup.js';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Filters conditional plugins based on user options.
|
|
@@ -95,6 +96,25 @@ const stripPlugins = (flatConfigs, pluginNames) => {
|
|
|
95
96
|
});
|
|
96
97
|
};
|
|
97
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Removes the parser from individual configs when the main config provides one.
|
|
101
|
+
* Prevents parser conflicts (e.g., eslint-config-next/parser vs `@typescript-eslint/parser`).
|
|
102
|
+
*
|
|
103
|
+
* @param {object[]} flatConfigs - Flat config array.
|
|
104
|
+
*
|
|
105
|
+
* @returns {object[]} Config array with parsers removed.
|
|
106
|
+
*/
|
|
107
|
+
const stripParser = (flatConfigs) =>
|
|
108
|
+
flatConfigs.map((config) => {
|
|
109
|
+
if (!config.languageOptions?.parser) return config;
|
|
110
|
+
|
|
111
|
+
const { parser: _, ...languageOptions } = config.languageOptions;
|
|
112
|
+
|
|
113
|
+
return Object.keys(languageOptions).length > 0
|
|
114
|
+
? { ...config, languageOptions }
|
|
115
|
+
: { ...config, languageOptions: undefined };
|
|
116
|
+
});
|
|
117
|
+
|
|
98
118
|
/**
|
|
99
119
|
* Merges user-provided global ignores with common defaults.
|
|
100
120
|
*
|
|
@@ -141,6 +161,7 @@ const buildConfigObject = ({
|
|
|
141
161
|
),
|
|
142
162
|
languageOptions: {
|
|
143
163
|
...commonLanguageOptions,
|
|
164
|
+
...(typescript && commonParser),
|
|
144
165
|
...extraLanguageOptions,
|
|
145
166
|
...(typescript && { parserOptions: { tsconfigRootDir: process.cwd(), ...parserOptions } }),
|
|
146
167
|
},
|
|
@@ -204,6 +225,7 @@ export const buildConfig = ({
|
|
|
204
225
|
const flatConfigs = flattenPlugins(mergedPlugins);
|
|
205
226
|
const wrappedConfigs = fixPlugins(flatConfigs);
|
|
206
227
|
const strippedConfigs = stripPlugins(wrappedConfigs, Object.keys(centralPlugins));
|
|
228
|
+
const parsedConfigs = typescript ? stripParser(strippedConfigs) : strippedConfigs;
|
|
207
229
|
const mergedGlobalIgnores = mergeGlobalIgnores(opts.globalIgnores);
|
|
208
230
|
|
|
209
231
|
const configObject = buildConfigObject({
|
|
@@ -217,5 +239,5 @@ export const buildConfig = ({
|
|
|
217
239
|
extraRules,
|
|
218
240
|
});
|
|
219
241
|
|
|
220
|
-
return defineConfig([...mergedGlobalIgnores, ...
|
|
242
|
+
return defineConfig([...mergedGlobalIgnores, ...parsedConfigs, configObject]);
|
|
221
243
|
};
|
package/src/eslint/next.js
CHANGED
|
@@ -10,14 +10,18 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import nextCoreWebVitals from 'eslint-config-next/core-web-vitals';
|
|
13
|
+
import reactPlugin from 'eslint-plugin-react';
|
|
14
|
+
import reactHooks from 'eslint-plugin-react-hooks';
|
|
15
|
+
import tsEslint from 'typescript-eslint';
|
|
13
16
|
|
|
14
17
|
import { buildConfig, files } from './lib/index.js';
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
20
|
* Removes the next/typescript item from the core-web-vitals config array.
|
|
18
21
|
* The \@typescript-eslint plugin is registered on the main config object
|
|
19
|
-
*
|
|
20
|
-
*
|
|
22
|
+
* via centralPlugins, which avoids plugin redefinition errors. The
|
|
23
|
+
* next/typescript config is also removed to prevent parser conflicts with
|
|
24
|
+
* the centrally-managed TypeScript setup.
|
|
21
25
|
*
|
|
22
26
|
* @param {import('eslint').Linter.Config[]} configs - Config array to process.
|
|
23
27
|
*
|
|
@@ -52,6 +56,7 @@ export const createConfig = (options = {}) => {
|
|
|
52
56
|
return buildConfig({
|
|
53
57
|
files: files.withTs,
|
|
54
58
|
builtinPlugins: [...prepareNextConfig(nextCoreWebVitals)],
|
|
59
|
+
centralPlugins: { react: reactPlugin, 'react-hooks': reactHooks, '@typescript-eslint': tsEslint.plugin },
|
|
55
60
|
parserOptions: { ecmaFeatures: { jsx: true } },
|
|
56
61
|
settings: { react: { version: 'detect' } },
|
|
57
62
|
rules: {
|