@nx/eslint 20.5.0-beta.3 → 20.5.0-canary.20250129-3f5e863

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/eslint",
3
- "version": "20.5.0-beta.3",
3
+ "version": "20.5.0-canary.20250129-3f5e863",
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": "20.5.0-beta.3",
39
- "@nx/js": "20.5.0-beta.3",
38
+ "@nx/devkit": "20.5.0-canary.20250129-3f5e863",
39
+ "@nx/js": "20.5.0-canary.20250129-3f5e863",
40
40
  "semver": "^7.5.3",
41
41
  "tslib": "^2.3.0",
42
42
  "typescript": "~5.7.2"
@@ -113,8 +113,6 @@ const getGlobalFlatEslintConfiguration = (format, rootProject) => {
113
113
  files: [
114
114
  '**/*.ts',
115
115
  '**/*.tsx',
116
- '**/*.cts',
117
- '**/*.mts',
118
116
  '**/*.js',
119
117
  '**/*.jsx',
120
118
  '**/*.cjs',
@@ -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, '@eslint/eslintrc': versions_1.eslintrcVersion }, undefined, true);
360
+ return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@eslint/compat': versions_1.eslintCompat }, undefined, true);
361
361
  }
362
- return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@eslint/eslintrc': versions_1.eslintrcVersion }, undefined, true);
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
- 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
- }
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"')) ||
@@ -13,18 +13,7 @@ const semver_1 = require("semver");
13
13
  const config_file_1 = require("../utils/config-file");
14
14
  const resolve_eslint_class_1 = require("../utils/resolve-eslint-class");
15
15
  const pmc = (0, devkit_1.getPackageManagerCommand)();
16
- const DEFAULT_EXTENSIONS = [
17
- 'ts',
18
- 'cts',
19
- 'mts',
20
- 'tsx',
21
- 'js',
22
- 'cjs',
23
- 'mjs',
24
- 'jsx',
25
- 'html',
26
- 'vue',
27
- ];
16
+ const DEFAULT_EXTENSIONS = ['ts', 'tsx', 'js', 'jsx', 'html', 'vue'];
28
17
  const PROJECT_CONFIG_FILENAMES = ['project.json', 'package.json'];
29
18
  const ESLINT_CONFIG_GLOB_V1 = (0, globs_1.combineGlobPatterns)(config_file_1.ESLINT_CONFIG_FILENAMES.map((f) => `**/${f}`));
30
19
  const ESLINT_CONFIG_GLOB_V2 = (0, globs_1.combineGlobPatterns)([
@@ -107,7 +96,7 @@ const internalCreateNodes = async (configFilePath, options, context, projectsCac
107
96
  projects,
108
97
  };
109
98
  };
110
- const internalCreateNodesV2 = async (configFilePath, options, context, projectRootsByEslintRoots, lintableFilesPerProjectRoot, projectsCache, hashByRoot) => {
99
+ const internalCreateNodesV2 = async (configFilePath, options, context, eslintConfigFiles, projectRootsByEslintRoots, lintableFilesPerProjectRoot, projectsCache) => {
111
100
  const configDir = (0, posix_1.dirname)(configFilePath);
112
101
  const ESLint = await (0, resolve_eslint_class_1.resolveESLintClass)({
113
102
  useFlatConfigOverrideVal: (0, config_file_1.isFlatConfig)(configFilePath),
@@ -115,7 +104,12 @@ const internalCreateNodesV2 = async (configFilePath, options, context, projectRo
115
104
  const eslintVersion = ESLint.version;
116
105
  const projects = {};
117
106
  await Promise.all(projectRootsByEslintRoots.get(configDir).map(async (projectRoot) => {
118
- const hash = hashByRoot.get(projectRoot);
107
+ const parentConfigs = eslintConfigFiles.filter((eslintConfig) => isSubDir(projectRoot, (0, posix_1.dirname)(eslintConfig)));
108
+ const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, {
109
+ configFiles: eslintConfigFiles,
110
+ nxJsonConfiguration: context.nxJsonConfiguration,
111
+ workspaceRoot: context.workspaceRoot,
112
+ }, [...parentConfigs, (0, posix_1.join)(projectRoot, '.eslintignore')]);
119
113
  if (projectsCache[hash]) {
120
114
  // We can reuse the projects in the cache.
121
115
  Object.assign(projects, projectsCache[hash]);
@@ -160,13 +154,8 @@ exports.createNodesV2 = [
160
154
  const targetsCache = readTargetsCache(cachePath);
161
155
  const { eslintConfigFiles, projectRoots, projectRootsByEslintRoots } = splitConfigFiles(configFiles);
162
156
  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
157
  try {
169
- return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => internalCreateNodesV2(configFile, options, context, projectRootsByEslintRoots, lintableFilesPerProjectRoot, targetsCache, hashByRoot), eslintConfigFiles, options, context);
158
+ return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => internalCreateNodesV2(configFile, options, context, eslintConfigFiles, projectRootsByEslintRoots, lintableFilesPerProjectRoot, targetsCache), eslintConfigFiles, options, context);
170
159
  }
171
160
  finally {
172
161
  writeTargetsToCache(cachePath, targetsCache);