@nx/eslint 0.0.0-pr-30715-a5f5e3b → 0.0.0-pr-31222-862e973
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/LICENSE +1 -1
- package/README.md +1 -1
- package/migrations.json +98 -119
- package/package.json +7 -6
- package/src/executors/lint/utility/eslint-utils.js +0 -6
- package/src/generators/convert-to-flat-config/converters/json-converter.d.ts +1 -1
- package/src/generators/convert-to-flat-config/converters/json-converter.js +18 -10
- package/src/generators/convert-to-flat-config/generator.js +17 -18
- package/src/generators/convert-to-flat-config/schema.d.ts +0 -2
- package/src/generators/convert-to-inferred/convert-to-inferred.js +1 -2
- package/src/generators/init/global-eslint-config.d.ts +1 -1
- package/src/generators/init/global-eslint-config.js +6 -17
- package/src/generators/init/init-migration.d.ts +1 -1
- package/src/generators/init/init-migration.js +13 -18
- package/src/generators/init/init.d.ts +0 -1
- package/src/generators/init/init.js +6 -31
- package/src/generators/lint-project/lint-project.d.ts +0 -1
- package/src/generators/lint-project/lint-project.js +15 -37
- package/src/generators/lint-project/setup-root-eslint.d.ts +0 -1
- package/src/generators/lint-project/setup-root-eslint.js +1 -2
- package/src/generators/utils/eslint-file.d.ts +2 -3
- package/src/generators/utils/eslint-file.js +28 -160
- package/src/generators/utils/flat-config/ast-utils.d.ts +4 -12
- package/src/generators/utils/flat-config/ast-utils.js +63 -412
- package/src/generators/utils/linter.d.ts +0 -3
- package/src/generators/utils/linter.js +2 -2
- package/src/generators/workspace-rule/files/__name__.spec.ts__tmpl__ +2 -11
- package/src/generators/workspace-rule/workspace-rule.d.ts +2 -2
- package/src/generators/workspace-rule/workspace-rule.js +3 -11
- package/src/generators/workspace-rules-project/workspace-rules-project.js +1 -4
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
- package/src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files.d.ts +2 -0
- package/src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files.js +44 -0
- package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.d.ts +2 -0
- package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.js +47 -0
- package/src/migrations/update-17-1-0/update-typescript-eslint.d.ts +2 -0
- package/src/migrations/update-17-1-0/update-typescript-eslint.js +74 -0
- package/src/migrations/update-17-2-0/simplify-eslint-patterns.d.ts +2 -0
- package/src/migrations/update-17-2-0/simplify-eslint-patterns.js +46 -0
- package/src/migrations/update-17-2-9/move-options-to-target-defaults.d.ts +2 -0
- package/src/migrations/update-17-2-9/move-options-to-target-defaults.js +107 -0
- package/src/plugins/plugin.js +10 -21
- package/src/utils/config-file.d.ts +1 -3
- package/src/utils/config-file.js +2 -5
- package/src/utils/flat-config.d.ts +0 -1
- package/src/utils/flat-config.js +3 -9
- package/src/utils/version-utils.d.ts +0 -1
- package/src/utils/version-utils.js +9 -13
- package/src/utils/versions.d.ts +2 -3
- package/src/utils/versions.js +3 -4
- package/src/migrations/update-20-2-0/update-typescript-eslint-v8-13-0.d.ts +0 -2
- package/src/migrations/update-20-2-0/update-typescript-eslint-v8-13-0.js +0 -23
- package/src/migrations/update-20-3-0/add-file-extensions-to-overrides.d.ts +0 -2
- package/src/migrations/update-20-3-0/add-file-extensions-to-overrides.js +0 -49
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.findEslintFile = findEslintFile;
|
|
4
4
|
exports.isEslintConfigSupported = isEslintConfigSupported;
|
|
5
5
|
exports.updateRelativePathsInConfig = updateRelativePathsInConfig;
|
|
6
|
-
exports.determineEslintConfigFormat = determineEslintConfigFormat;
|
|
7
6
|
exports.addOverrideToLintConfig = addOverrideToLintConfig;
|
|
8
7
|
exports.updateOverrideInLintConfig = updateOverrideInLintConfig;
|
|
9
8
|
exports.lintConfigHasOverride = lintConfigHasOverride;
|
|
@@ -21,18 +20,12 @@ const version_utils_1 = require("../../utils/version-utils");
|
|
|
21
20
|
const versions_1 = require("../../utils/versions");
|
|
22
21
|
const ast_utils_1 = require("./flat-config/ast-utils");
|
|
23
22
|
const path_utils_1 = require("./flat-config/path-utils");
|
|
24
|
-
const ts = require("typescript");
|
|
25
|
-
const posix_1 = require("node:path/posix");
|
|
26
23
|
function findEslintFile(tree, projectRoot) {
|
|
27
|
-
if (projectRoot === undefined) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (tree.exists(file)) {
|
|
33
|
-
return file;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
24
|
+
if (projectRoot === undefined && tree.exists(config_file_1.baseEsLintConfigFile)) {
|
|
25
|
+
return config_file_1.baseEsLintConfigFile;
|
|
26
|
+
}
|
|
27
|
+
if (projectRoot === undefined && tree.exists(config_file_1.baseEsLintFlatConfigFile)) {
|
|
28
|
+
return config_file_1.baseEsLintFlatConfigFile;
|
|
36
29
|
}
|
|
37
30
|
projectRoot ??= '';
|
|
38
31
|
for (const file of config_file_1.ESLINT_CONFIG_FILENAMES) {
|
|
@@ -47,10 +40,7 @@ function isEslintConfigSupported(tree, projectRoot = '') {
|
|
|
47
40
|
if (!eslintFile) {
|
|
48
41
|
return false;
|
|
49
42
|
}
|
|
50
|
-
return
|
|
51
|
-
eslintFile.endsWith('.config.js') ||
|
|
52
|
-
eslintFile.endsWith('.config.cjs') ||
|
|
53
|
-
eslintFile.endsWith('.config.mjs'));
|
|
43
|
+
return eslintFile.endsWith('.json') || eslintFile.endsWith('.config.js');
|
|
54
44
|
}
|
|
55
45
|
function updateRelativePathsInConfig(tree, sourcePath, destinationPath) {
|
|
56
46
|
if (sourcePath === destinationPath ||
|
|
@@ -94,17 +84,6 @@ function replaceFlatConfigPaths(config, sourceRoot, offset, destinationRoot, tre
|
|
|
94
84
|
`require('${newPath}')` +
|
|
95
85
|
newConfig.slice(match.index + match[0].length);
|
|
96
86
|
}
|
|
97
|
-
// Handle import statements
|
|
98
|
-
const importRegex = RegExp(/import\s+.*?\s+from\s+['"](.*)['"]/g);
|
|
99
|
-
while ((match = importRegex.exec(newConfig)) !== null) {
|
|
100
|
-
const oldPath = match[1];
|
|
101
|
-
const newPath = offsetFilePath(sourceRoot, oldPath, offset, tree);
|
|
102
|
-
// Replace the old path with the updated path
|
|
103
|
-
newConfig =
|
|
104
|
-
newConfig.slice(0, match.index + match[0].indexOf(oldPath)) +
|
|
105
|
-
newPath +
|
|
106
|
-
newConfig.slice(match.index + match[0].indexOf(oldPath) + oldPath.length);
|
|
107
|
-
}
|
|
108
87
|
// replace projects
|
|
109
88
|
const projectRegex = RegExp(/project:\s?\[?['"](.*)['"]\]?/g);
|
|
110
89
|
while ((match = projectRegex.exec(newConfig)) !== null) {
|
|
@@ -130,37 +109,14 @@ function offsetFilePath(projectRoot, pathToFile, offset, tree) {
|
|
|
130
109
|
}
|
|
131
110
|
return (0, devkit_1.joinPathFragments)(offset, projectRoot, pathToFile);
|
|
132
111
|
}
|
|
133
|
-
function determineEslintConfigFormat(content) {
|
|
134
|
-
const sourceFile = ts.createSourceFile('', content, ts.ScriptTarget.Latest, true);
|
|
135
|
-
// Check if there's an `export default` in the AST
|
|
136
|
-
const hasExportDefault = sourceFile.statements.some((statement) => ts.isExportAssignment(statement) && !statement.isExportEquals);
|
|
137
|
-
return hasExportDefault ? 'mjs' : 'cjs';
|
|
138
|
-
}
|
|
139
112
|
function addOverrideToLintConfig(tree, root, override, options = {
|
|
140
113
|
insertAtTheEnd: true,
|
|
141
114
|
}) {
|
|
142
115
|
const isBase = options.checkBaseConfig && findEslintFile(tree, root).includes('.base');
|
|
143
116
|
if ((0, flat_config_1.useFlatConfig)(tree)) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
for (const file of config_file_1.BASE_ESLINT_CONFIG_FILENAMES) {
|
|
147
|
-
if (tree.exists((0, devkit_1.joinPathFragments)(root, file))) {
|
|
148
|
-
fileName = (0, devkit_1.joinPathFragments)(root, file);
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
for (const f of flat_config_1.eslintFlatConfigFilenames) {
|
|
155
|
-
if (tree.exists((0, devkit_1.joinPathFragments)(root, f))) {
|
|
156
|
-
fileName = (0, devkit_1.joinPathFragments)(root, f);
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
117
|
+
const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? config_file_1.baseEsLintFlatConfigFile : (0, flat_config_1.getRootESLintFlatConfigFilename)(tree));
|
|
118
|
+
const flatOverride = (0, ast_utils_1.generateFlatOverride)(override);
|
|
161
119
|
let content = tree.read(fileName, 'utf8');
|
|
162
|
-
const format = content.includes('export default') ? 'mjs' : 'cjs';
|
|
163
|
-
const flatOverride = (0, ast_utils_1.generateFlatOverride)(override, format);
|
|
164
120
|
// Check if the provided override using legacy eslintrc properties or plugins, if so we need to add compat
|
|
165
121
|
if ((0, ast_utils_1.overrideNeedsCompat)(override)) {
|
|
166
122
|
content = (0, ast_utils_1.addFlatCompatToFlatConfig)(content);
|
|
@@ -181,28 +137,15 @@ function addOverrideToLintConfig(tree, root, override, options = {
|
|
|
181
137
|
});
|
|
182
138
|
}
|
|
183
139
|
}
|
|
184
|
-
function updateOverrideInLintConfig(tree,
|
|
185
|
-
let fileName;
|
|
186
|
-
let root = rootOrFile;
|
|
187
|
-
if (tree.exists(rootOrFile) && tree.isFile(rootOrFile)) {
|
|
188
|
-
fileName = rootOrFile;
|
|
189
|
-
root = (0, posix_1.dirname)(rootOrFile);
|
|
190
|
-
}
|
|
140
|
+
function updateOverrideInLintConfig(tree, root, lookup, update) {
|
|
191
141
|
if ((0, flat_config_1.useFlatConfig)(tree)) {
|
|
192
|
-
|
|
193
|
-
for (const f of flat_config_1.eslintFlatConfigFilenames) {
|
|
194
|
-
if (tree.exists((0, devkit_1.joinPathFragments)(root, f))) {
|
|
195
|
-
fileName = (0, devkit_1.joinPathFragments)(root, f);
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
142
|
+
const fileName = (0, devkit_1.joinPathFragments)(root, (0, flat_config_1.getRootESLintFlatConfigFilename)(tree));
|
|
200
143
|
let content = tree.read(fileName, 'utf8');
|
|
201
144
|
content = (0, ast_utils_1.replaceOverride)(content, root, lookup, update);
|
|
202
145
|
tree.write(fileName, content);
|
|
203
146
|
}
|
|
204
147
|
else {
|
|
205
|
-
fileName
|
|
148
|
+
const fileName = (0, devkit_1.joinPathFragments)(root, '.eslintrc.json');
|
|
206
149
|
if (!tree.exists(fileName)) {
|
|
207
150
|
return;
|
|
208
151
|
}
|
|
@@ -225,62 +168,32 @@ function updateOverrideInLintConfig(tree, rootOrFile, lookup, update) {
|
|
|
225
168
|
});
|
|
226
169
|
}
|
|
227
170
|
}
|
|
228
|
-
function lintConfigHasOverride(tree,
|
|
229
|
-
|
|
230
|
-
let root = rootOrFile;
|
|
231
|
-
if (tree.exists(rootOrFile) && tree.isFile(rootOrFile)) {
|
|
232
|
-
fileName = rootOrFile;
|
|
233
|
-
root = (0, posix_1.dirname)(rootOrFile);
|
|
234
|
-
}
|
|
235
|
-
if (!fileName && !isEslintConfigSupported(tree, root)) {
|
|
171
|
+
function lintConfigHasOverride(tree, root, lookup, checkBaseConfig = false) {
|
|
172
|
+
if (!isEslintConfigSupported(tree, root)) {
|
|
236
173
|
return false;
|
|
237
174
|
}
|
|
238
|
-
const isBase =
|
|
239
|
-
checkBaseConfig &&
|
|
240
|
-
findEslintFile(tree, root).includes('.base');
|
|
241
|
-
if (isBase) {
|
|
242
|
-
for (const file of config_file_1.BASE_ESLINT_CONFIG_FILENAMES) {
|
|
243
|
-
if (tree.exists((0, devkit_1.joinPathFragments)(root, file))) {
|
|
244
|
-
fileName = (0, devkit_1.joinPathFragments)(root, file);
|
|
245
|
-
break;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
175
|
+
const isBase = checkBaseConfig && findEslintFile(tree, root).includes('.base');
|
|
249
176
|
if ((0, flat_config_1.useFlatConfig)(tree)) {
|
|
250
|
-
|
|
251
|
-
for (const f of flat_config_1.eslintFlatConfigFilenames) {
|
|
252
|
-
if (tree.exists((0, devkit_1.joinPathFragments)(root, f))) {
|
|
253
|
-
fileName = (0, devkit_1.joinPathFragments)(root, f);
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
177
|
+
const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? config_file_1.baseEsLintFlatConfigFile : (0, flat_config_1.getRootESLintFlatConfigFilename)(tree));
|
|
258
178
|
const content = tree.read(fileName, 'utf8');
|
|
259
179
|
return (0, ast_utils_1.hasOverride)(content, lookup);
|
|
260
180
|
}
|
|
261
181
|
else {
|
|
262
|
-
fileName
|
|
182
|
+
const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? config_file_1.baseEsLintConfigFile : '.eslintrc.json');
|
|
263
183
|
return (0, devkit_1.readJson)(tree, fileName).overrides?.some(lookup) || false;
|
|
264
184
|
}
|
|
265
185
|
}
|
|
266
186
|
function replaceOverridesInLintConfig(tree, root, overrides) {
|
|
267
187
|
if ((0, flat_config_1.useFlatConfig)(tree)) {
|
|
268
|
-
|
|
269
|
-
for (const f of flat_config_1.eslintFlatConfigFilenames) {
|
|
270
|
-
if (tree.exists((0, devkit_1.joinPathFragments)(root, f))) {
|
|
271
|
-
fileName = (0, devkit_1.joinPathFragments)(root, f);
|
|
272
|
-
break;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
188
|
+
const fileName = (0, devkit_1.joinPathFragments)(root, (0, flat_config_1.getRootESLintFlatConfigFilename)(tree));
|
|
275
189
|
let content = tree.read(fileName, 'utf8');
|
|
276
|
-
const format = content.includes('export default') ? 'mjs' : 'cjs';
|
|
277
190
|
// Check if any of the provided overrides using legacy eslintrc properties or plugins, if so we need to add compat
|
|
278
191
|
if (overrides.some(ast_utils_1.overrideNeedsCompat)) {
|
|
279
192
|
content = (0, ast_utils_1.addFlatCompatToFlatConfig)(content);
|
|
280
193
|
}
|
|
281
194
|
content = (0, ast_utils_1.removeOverridesFromLintConfig)(content);
|
|
282
195
|
overrides.forEach((override) => {
|
|
283
|
-
const flatOverride = (0, ast_utils_1.generateFlatOverride)(override
|
|
196
|
+
const flatOverride = (0, ast_utils_1.generateFlatOverride)(override);
|
|
284
197
|
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, flatOverride);
|
|
285
198
|
});
|
|
286
199
|
tree.write(fileName, content);
|
|
@@ -296,21 +209,7 @@ function replaceOverridesInLintConfig(tree, root, overrides) {
|
|
|
296
209
|
function addExtendsToLintConfig(tree, root, plugin, insertAtTheEnd = false) {
|
|
297
210
|
if ((0, flat_config_1.useFlatConfig)(tree)) {
|
|
298
211
|
const pluginExtends = [];
|
|
299
|
-
|
|
300
|
-
for (const f of flat_config_1.eslintFlatConfigFilenames) {
|
|
301
|
-
if (tree.exists((0, devkit_1.joinPathFragments)(root, f))) {
|
|
302
|
-
fileName = (0, devkit_1.joinPathFragments)(root, f);
|
|
303
|
-
break;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
// Check the file extension to determine the format of the config if it is .js we look for the export
|
|
307
|
-
const eslintConfigFormat = fileName.endsWith('.mjs')
|
|
308
|
-
? 'mjs'
|
|
309
|
-
: fileName.endsWith('.cjs')
|
|
310
|
-
? 'cjs'
|
|
311
|
-
: tree.read(fileName, 'utf-8').includes('module.exports')
|
|
312
|
-
? 'cjs'
|
|
313
|
-
: 'mjs';
|
|
212
|
+
const fileName = (0, devkit_1.joinPathFragments)(root, (0, flat_config_1.getRootESLintFlatConfigFilename)(tree));
|
|
314
213
|
let shouldImportEslintCompat = false;
|
|
315
214
|
// assume eslint version is 9 if not found, as it's what we'd be generating by default
|
|
316
215
|
const eslintVersion = (0, version_utils_1.getInstalledEslintVersion)(tree) ?? versions_1.eslint9__eslintVersion;
|
|
@@ -357,9 +256,9 @@ function addExtendsToLintConfig(tree, root, plugin, insertAtTheEnd = false) {
|
|
|
357
256
|
}
|
|
358
257
|
tree.write(fileName, content);
|
|
359
258
|
if (shouldImportEslintCompat) {
|
|
360
|
-
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@eslint/compat': versions_1.eslintCompat
|
|
259
|
+
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@eslint/compat': versions_1.eslintCompat }, undefined, true);
|
|
361
260
|
}
|
|
362
|
-
return (
|
|
261
|
+
return () => { };
|
|
363
262
|
}
|
|
364
263
|
else {
|
|
365
264
|
const plugins = (Array.isArray(plugin) ? plugin : [plugin]).map((p) => typeof p === 'string' ? p : p.name);
|
|
@@ -378,13 +277,7 @@ function addExtendsToLintConfig(tree, root, plugin, insertAtTheEnd = false) {
|
|
|
378
277
|
function addPredefinedConfigToFlatLintConfig(tree, root, predefinedConfigName, moduleName = 'nx', moduleImportPath = '@nx/eslint-plugin', spread = true, insertAtTheEnd = true) {
|
|
379
278
|
if (!(0, flat_config_1.useFlatConfig)(tree))
|
|
380
279
|
throw new Error('Predefined configs can only be used with flat configs');
|
|
381
|
-
|
|
382
|
-
for (const f of flat_config_1.eslintFlatConfigFilenames) {
|
|
383
|
-
if (tree.exists((0, devkit_1.joinPathFragments)(root, f))) {
|
|
384
|
-
fileName = (0, devkit_1.joinPathFragments)(root, f);
|
|
385
|
-
break;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
280
|
+
const fileName = (0, devkit_1.joinPathFragments)(root, (0, flat_config_1.getRootESLintFlatConfigFilename)(tree));
|
|
388
281
|
let content = tree.read(fileName, 'utf8');
|
|
389
282
|
content = (0, ast_utils_1.addImportToFlatConfig)(content, moduleName, moduleImportPath);
|
|
390
283
|
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatPredefinedConfig)(predefinedConfigName, moduleName, spread), { insertAtTheEnd });
|
|
@@ -393,13 +286,7 @@ function addPredefinedConfigToFlatLintConfig(tree, root, predefinedConfigName, m
|
|
|
393
286
|
function addPluginsToLintConfig(tree, root, plugin) {
|
|
394
287
|
const plugins = Array.isArray(plugin) ? plugin : [plugin];
|
|
395
288
|
if ((0, flat_config_1.useFlatConfig)(tree)) {
|
|
396
|
-
|
|
397
|
-
for (const f of flat_config_1.eslintFlatConfigFilenames) {
|
|
398
|
-
if (tree.exists((0, devkit_1.joinPathFragments)(root, f))) {
|
|
399
|
-
fileName = (0, devkit_1.joinPathFragments)(root, f);
|
|
400
|
-
break;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
289
|
+
const fileName = (0, devkit_1.joinPathFragments)(root, (0, flat_config_1.getRootESLintFlatConfigFilename)(tree));
|
|
403
290
|
let content = tree.read(fileName, 'utf8');
|
|
404
291
|
const mappedPlugins = [];
|
|
405
292
|
plugins.forEach((name) => {
|
|
@@ -423,33 +310,14 @@ function addPluginsToLintConfig(tree, root, plugin) {
|
|
|
423
310
|
}
|
|
424
311
|
function addIgnoresToLintConfig(tree, root, ignorePatterns) {
|
|
425
312
|
if ((0, flat_config_1.useFlatConfig)(tree)) {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
if (!fileName) {
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
let content = tree.read(fileName, 'utf8');
|
|
437
|
-
if ((0, ast_utils_1.hasFlatConfigIgnoresBlock)(content)) {
|
|
438
|
-
content = (0, ast_utils_1.addPatternsToFlatConfigIgnoresBlock)(content, ignorePatterns);
|
|
439
|
-
tree.write(fileName, content);
|
|
440
|
-
}
|
|
441
|
-
else {
|
|
442
|
-
const block = (0, ast_utils_1.generateAst)({
|
|
443
|
-
ignores: ignorePatterns.map((path) => (0, path_utils_1.mapFilePath)(path)),
|
|
444
|
-
});
|
|
445
|
-
tree.write(fileName, (0, ast_utils_1.addBlockToFlatConfigExport)(content, block));
|
|
446
|
-
}
|
|
313
|
+
const fileName = (0, devkit_1.joinPathFragments)(root, (0, flat_config_1.getRootESLintFlatConfigFilename)(tree));
|
|
314
|
+
const block = (0, ast_utils_1.generateAst)({
|
|
315
|
+
ignores: ignorePatterns.map((path) => (0, path_utils_1.mapFilePath)(path)),
|
|
316
|
+
});
|
|
317
|
+
tree.write(fileName, (0, ast_utils_1.addBlockToFlatConfigExport)(tree.read(fileName, 'utf8'), block));
|
|
447
318
|
}
|
|
448
319
|
else {
|
|
449
320
|
const fileName = (0, devkit_1.joinPathFragments)(root, '.eslintrc.json');
|
|
450
|
-
if (!tree.exists(fileName)) {
|
|
451
|
-
return;
|
|
452
|
-
}
|
|
453
321
|
(0, devkit_1.updateJson)(tree, fileName, (json) => {
|
|
454
322
|
const ignoreSet = new Set([
|
|
455
323
|
...(json.ignorePatterns ?? []),
|
|
@@ -4,20 +4,13 @@ import * as ts from 'typescript';
|
|
|
4
4
|
* Remove all overrides from the config file
|
|
5
5
|
*/
|
|
6
6
|
export declare function removeOverridesFromLintConfig(content: string): string;
|
|
7
|
-
export declare function addPatternsToFlatConfigIgnoresBlock(content: string, ignorePatterns: string[]): string;
|
|
8
|
-
export declare function hasFlatConfigIgnoresBlock(content: string): boolean;
|
|
9
7
|
export declare function hasOverride(content: string, lookup: (override: Linter.ConfigOverride<Linter.RulesRecord>) => boolean): boolean;
|
|
10
8
|
/**
|
|
11
9
|
* Finds an override matching the lookup function and applies the update function to it
|
|
12
10
|
*/
|
|
13
11
|
export declare function replaceOverride(content: string, root: string, lookup: (override: Linter.ConfigOverride<Linter.RulesRecord>) => boolean, update?: (override: Partial<Linter.ConfigOverride<Linter.RulesRecord>>) => Partial<Linter.ConfigOverride<Linter.RulesRecord>>): string;
|
|
14
12
|
/**
|
|
15
|
-
* Adding
|
|
16
|
-
* The imports are added based on a few rules:
|
|
17
|
-
* 1. If it's a default import and matches the variable, return content unchanged.
|
|
18
|
-
* 2. If it's a named import and the variables are not part of the import object, add them.
|
|
19
|
-
* 3. If no existing import and variable is a string, add a default import.
|
|
20
|
-
* 4. If no existing import and variable is an array, add it as an object import.
|
|
13
|
+
* Adding require statement to the top of the file
|
|
21
14
|
*/
|
|
22
15
|
export declare function addImportToFlatConfig(content: string, variable: string | string[], imp: string): string;
|
|
23
16
|
/**
|
|
@@ -25,7 +18,7 @@ export declare function addImportToFlatConfig(content: string, variable: string
|
|
|
25
18
|
*/
|
|
26
19
|
export declare function removeImportFromFlatConfig(content: string, variable: string, imp: string): string;
|
|
27
20
|
/**
|
|
28
|
-
* Injects new ts.expression to the end of the module.exports
|
|
21
|
+
* Injects new ts.expression to the end of the module.exports array.
|
|
29
22
|
*/
|
|
30
23
|
export declare function addBlockToFlatConfigExport(content: string, config: ts.Expression | ts.SpreadElement, options?: {
|
|
31
24
|
insertAtTheEnd?: boolean;
|
|
@@ -50,7 +43,7 @@ export declare function addFlatCompatToFlatConfig(content: string): string;
|
|
|
50
43
|
* Generate node list representing the imports and the exports blocks
|
|
51
44
|
* Optionally add flat compat initialization
|
|
52
45
|
*/
|
|
53
|
-
export declare function createNodeList(importsMap: Map<string, string>, exportElements: ts.Expression[]
|
|
46
|
+
export declare function createNodeList(importsMap: Map<string, string>, exportElements: ts.Expression[]): ts.NodeArray<ts.VariableStatement | ts.Identifier | ts.ExpressionStatement | ts.SourceFile>;
|
|
54
47
|
export declare function generateSpreadElement(name: string): ts.SpreadElement;
|
|
55
48
|
export declare function generatePluginExtendsElement(plugins: string[]): ts.SpreadElement;
|
|
56
49
|
export declare function generatePluginExtendsElementWithCompatFixup(plugin: string): ts.SpreadElement;
|
|
@@ -62,7 +55,6 @@ export declare function stringifyNodeList(nodes: ts.NodeArray<ts.VariableStateme
|
|
|
62
55
|
* generates AST require statement
|
|
63
56
|
*/
|
|
64
57
|
export declare function generateRequire(variableName: string | ts.ObjectBindingPattern, imp: string): ts.VariableStatement;
|
|
65
|
-
export declare function generateESMImport(variableName: string | ts.ObjectBindingPattern, imp: string): ts.ImportDeclaration;
|
|
66
58
|
export declare function overrideNeedsCompat(override: Partial<Linter.ConfigOverride<Linter.RulesRecord>>): string | string[] | {
|
|
67
59
|
[name: string]: boolean;
|
|
68
60
|
};
|
|
@@ -72,7 +64,7 @@ export declare function overrideNeedsCompat(override: Partial<Linter.ConfigOverr
|
|
|
72
64
|
*/
|
|
73
65
|
export declare function generateFlatOverride(_override: Partial<Linter.ConfigOverride<Linter.RulesRecord>> & {
|
|
74
66
|
ignores?: Linter.FlatConfig['ignores'];
|
|
75
|
-
}
|
|
67
|
+
}): ts.ObjectLiteralExpression | ts.SpreadElement;
|
|
76
68
|
export declare function generateFlatPredefinedConfig(predefinedConfigName: string, moduleName?: string, spread?: boolean): ts.ObjectLiteralExpression | ts.SpreadElement | ts.ElementAccessExpression;
|
|
77
69
|
export declare function mapFilePaths<T extends Partial<Linter.ConfigOverride<Linter.RulesRecord>>>(_override: T): T;
|
|
78
70
|
/**
|