@nx/eslint 20.5.0-canary.20250214-ef08108 → 21.0.0-beta.0
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/eslint",
|
3
|
-
"version": "
|
3
|
+
"version": "21.0.0-beta.0",
|
4
4
|
"private": false,
|
5
5
|
"description": "The ESLint plugin for Nx contains executors, generators and utilities used for linting JavaScript/TypeScript projects within an Nx workspace.",
|
6
6
|
"repository": {
|
@@ -35,8 +35,8 @@
|
|
35
35
|
"eslint": "^8.0.0 || ^9.0.0"
|
36
36
|
},
|
37
37
|
"dependencies": {
|
38
|
-
"@nx/devkit": "
|
39
|
-
"@nx/js": "
|
38
|
+
"@nx/devkit": "21.0.0-beta.0",
|
39
|
+
"@nx/js": "21.0.0-beta.0",
|
40
40
|
"semver": "^7.5.3",
|
41
41
|
"tslib": "^2.3.0",
|
42
42
|
"typescript": "~5.7.2"
|
@@ -357,9 +357,9 @@ function addExtendsToLintConfig(tree, root, plugin, insertAtTheEnd = false) {
|
|
357
357
|
}
|
358
358
|
tree.write(fileName, content);
|
359
359
|
if (shouldImportEslintCompat) {
|
360
|
-
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@eslint/compat': versions_1.eslintCompat
|
360
|
+
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@eslint/compat': versions_1.eslintCompat }, undefined, true);
|
361
361
|
}
|
362
|
-
return (
|
362
|
+
return () => { };
|
363
363
|
}
|
364
364
|
else {
|
365
365
|
const plugins = (Array.isArray(plugin) ? plugin : [plugin]).map((p) => typeof p === 'string' ? p : p.name);
|
@@ -430,26 +430,13 @@ function addIgnoresToLintConfig(tree, root, ignorePatterns) {
|
|
430
430
|
break;
|
431
431
|
}
|
432
432
|
}
|
433
|
-
|
434
|
-
|
435
|
-
}
|
436
|
-
|
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
|
-
}
|
433
|
+
const block = (0, ast_utils_1.generateAst)({
|
434
|
+
ignores: ignorePatterns.map((path) => (0, path_utils_1.mapFilePath)(path)),
|
435
|
+
});
|
436
|
+
tree.write(fileName, (0, ast_utils_1.addBlockToFlatConfigExport)(tree.read(fileName, 'utf8'), block));
|
447
437
|
}
|
448
438
|
else {
|
449
439
|
const fileName = (0, devkit_1.joinPathFragments)(root, '.eslintrc.json');
|
450
|
-
if (!tree.exists(fileName)) {
|
451
|
-
return;
|
452
|
-
}
|
453
440
|
(0, devkit_1.updateJson)(tree, fileName, (json) => {
|
454
441
|
const ignoreSet = new Set([
|
455
442
|
...(json.ignorePatterns ?? []),
|
@@ -4,8 +4,6 @@ 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
|
@@ -1,8 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.removeOverridesFromLintConfig = removeOverridesFromLintConfig;
|
4
|
-
exports.addPatternsToFlatConfigIgnoresBlock = addPatternsToFlatConfigIgnoresBlock;
|
5
|
-
exports.hasFlatConfigIgnoresBlock = hasFlatConfigIgnoresBlock;
|
6
4
|
exports.hasOverride = hasOverride;
|
7
5
|
exports.replaceOverride = replaceOverride;
|
8
6
|
exports.addImportToFlatConfig = addImportToFlatConfig;
|
@@ -75,55 +73,6 @@ function findModuleExports(source) {
|
|
75
73
|
}
|
76
74
|
});
|
77
75
|
}
|
78
|
-
function addPatternsToFlatConfigIgnoresBlock(content, ignorePatterns) {
|
79
|
-
const source = ts.createSourceFile('', content, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
80
|
-
const format = content.includes('export default') ? 'mjs' : 'cjs';
|
81
|
-
const exportsArray = format === 'mjs' ? findExportDefault(source) : findModuleExports(source);
|
82
|
-
if (!exportsArray) {
|
83
|
-
return content;
|
84
|
-
}
|
85
|
-
const changes = [];
|
86
|
-
for (const node of exportsArray) {
|
87
|
-
if (!isFlatConfigIgnoresBlock(node)) {
|
88
|
-
continue;
|
89
|
-
}
|
90
|
-
const start = node.properties.pos + 1; // keep leading line break
|
91
|
-
const data = parseTextToJson(node.getFullText());
|
92
|
-
changes.push({
|
93
|
-
type: devkit_1.ChangeType.Delete,
|
94
|
-
start,
|
95
|
-
length: node.properties.end - start,
|
96
|
-
});
|
97
|
-
data.ignores = Array.from(new Set([...(data.ignores ?? []), ...ignorePatterns]));
|
98
|
-
changes.push({
|
99
|
-
type: devkit_1.ChangeType.Insert,
|
100
|
-
index: start,
|
101
|
-
text: ' ' +
|
102
|
-
JSON.stringify(data, null, 2)
|
103
|
-
.slice(2, -2) // Remove curly braces and start/end line breaks
|
104
|
-
.replaceAll(/\n/g, '\n '), // Maintain indentation
|
105
|
-
});
|
106
|
-
break;
|
107
|
-
}
|
108
|
-
return (0, devkit_1.applyChangesToString)(content, changes);
|
109
|
-
}
|
110
|
-
function hasFlatConfigIgnoresBlock(content) {
|
111
|
-
const source = ts.createSourceFile('', content, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
112
|
-
const format = content.includes('export default') ? 'mjs' : 'cjs';
|
113
|
-
const exportsArray = format === 'mjs' ? findExportDefault(source) : findModuleExports(source);
|
114
|
-
if (!exportsArray) {
|
115
|
-
return false;
|
116
|
-
}
|
117
|
-
return exportsArray.some(isFlatConfigIgnoresBlock);
|
118
|
-
}
|
119
|
-
function isFlatConfigIgnoresBlock(node) {
|
120
|
-
return (ts.isObjectLiteralExpression(node) &&
|
121
|
-
node.properties.length === 1 &&
|
122
|
-
(node.properties[0].name.getText() === 'ignores' ||
|
123
|
-
node.properties[0].name.getText() === '"ignores"') &&
|
124
|
-
ts.isPropertyAssignment(node.properties[0]) &&
|
125
|
-
ts.isArrayLiteralExpression(node.properties[0].initializer));
|
126
|
-
}
|
127
76
|
function isOverride(node) {
|
128
77
|
return ((ts.isObjectLiteralExpression(node) &&
|
129
78
|
node.properties.some((p) => p.name.getText() === 'files' || p.name.getText() === '"files"')) ||
|
package/src/plugins/plugin.js
CHANGED
@@ -107,7 +107,7 @@ const internalCreateNodes = async (configFilePath, options, context, projectsCac
|
|
107
107
|
projects,
|
108
108
|
};
|
109
109
|
};
|
110
|
-
const internalCreateNodesV2 = async (configFilePath, options, context, projectRootsByEslintRoots, lintableFilesPerProjectRoot, projectsCache
|
110
|
+
const internalCreateNodesV2 = async (configFilePath, options, context, eslintConfigFiles, projectRootsByEslintRoots, lintableFilesPerProjectRoot, projectsCache) => {
|
111
111
|
const configDir = (0, posix_1.dirname)(configFilePath);
|
112
112
|
const ESLint = await (0, resolve_eslint_class_1.resolveESLintClass)({
|
113
113
|
useFlatConfigOverrideVal: (0, config_file_1.isFlatConfig)(configFilePath),
|
@@ -115,7 +115,12 @@ const internalCreateNodesV2 = async (configFilePath, options, context, projectRo
|
|
115
115
|
const eslintVersion = ESLint.version;
|
116
116
|
const projects = {};
|
117
117
|
await Promise.all(projectRootsByEslintRoots.get(configDir).map(async (projectRoot) => {
|
118
|
-
const
|
118
|
+
const parentConfigs = eslintConfigFiles.filter((eslintConfig) => isSubDir(projectRoot, (0, posix_1.dirname)(eslintConfig)));
|
119
|
+
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, {
|
120
|
+
configFiles: eslintConfigFiles,
|
121
|
+
nxJsonConfiguration: context.nxJsonConfiguration,
|
122
|
+
workspaceRoot: context.workspaceRoot,
|
123
|
+
}, [...parentConfigs, (0, posix_1.join)(projectRoot, '.eslintignore')]);
|
119
124
|
if (projectsCache[hash]) {
|
120
125
|
// We can reuse the projects in the cache.
|
121
126
|
Object.assign(projects, projectsCache[hash]);
|
@@ -160,13 +165,8 @@ exports.createNodesV2 = [
|
|
160
165
|
const targetsCache = readTargetsCache(cachePath);
|
161
166
|
const { eslintConfigFiles, projectRoots, projectRootsByEslintRoots } = splitConfigFiles(configFiles);
|
162
167
|
const lintableFilesPerProjectRoot = await collectLintableFilesByProjectRoot(projectRoots, options, context);
|
163
|
-
const hashes = await (0, calculate_hash_for_create_nodes_1.calculateHashesForCreateNodes)(projectRoots, options, context, projectRoots.map((root) => {
|
164
|
-
const parentConfigs = eslintConfigFiles.filter((eslintConfig) => isSubDir(root, (0, posix_1.dirname)(eslintConfig)));
|
165
|
-
return [...parentConfigs, (0, posix_1.join)(root, '.eslintignore')];
|
166
|
-
}));
|
167
|
-
const hashByRoot = new Map(projectRoots.map((r, i) => [r, hashes[i]]));
|
168
168
|
try {
|
169
|
-
return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => internalCreateNodesV2(configFile, options, context, projectRootsByEslintRoots, lintableFilesPerProjectRoot, targetsCache
|
169
|
+
return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => internalCreateNodesV2(configFile, options, context, eslintConfigFiles, projectRootsByEslintRoots, lintableFilesPerProjectRoot, targetsCache), eslintConfigFiles, options, context);
|
170
170
|
}
|
171
171
|
finally {
|
172
172
|
writeTargetsToCache(cachePath, targetsCache);
|