@nx/eslint 17.2.0-beta.6 → 17.2.0-beta.8

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/migrations.json CHANGED
@@ -32,6 +32,11 @@
32
32
  "version": "17.1.0-beta.1",
33
33
  "description": "Updates for @typescript-utils/utils v6.9.1+",
34
34
  "implementation": "./src/migrations/update-17-1-0/update-typescript-eslint"
35
+ },
36
+ "simplify-eslint-patterns": {
37
+ "version": "17.2.0-beta.0",
38
+ "description": "Simplify eslintFilePatterns",
39
+ "implementation": "./src/migrations/update-17-2-0/simplify-eslint-patterns"
35
40
  }
36
41
  },
37
42
  "packageJsonUpdates": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/eslint",
3
- "version": "17.2.0-beta.6",
3
+ "version": "17.2.0-beta.8",
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,10 +35,10 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "tslib": "^2.3.0",
38
- "@nx/devkit": "17.2.0-beta.6",
39
- "@nx/js": "17.2.0-beta.6",
38
+ "@nx/devkit": "17.2.0-beta.8",
39
+ "@nx/js": "17.2.0-beta.8",
40
40
  "typescript": "~5.2.2",
41
- "@nx/linter": "17.2.0-beta.6"
41
+ "@nx/linter": "17.2.0-beta.8"
42
42
  },
43
43
  "peerDependenciesMeta": {
44
44
  "eslint": {
@@ -4,6 +4,7 @@ const devkit_1 = require("@nx/devkit");
4
4
  const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
6
  const eslint_utils_1 = require("./utility/eslint-utils");
7
+ const utils_1 = require("nx/src/tasks-runner/utils");
7
8
  async function run(options, context) {
8
9
  // this is only used for the hasher
9
10
  delete options.hasTypeAwareRules;
@@ -58,8 +59,15 @@ async function run(options, context) {
58
59
  }
59
60
  }
60
61
  let lintResults = [];
62
+ const normalizedLintFilePatterns = normalizedOptions.lintFilePatterns.map((pattern) => {
63
+ return (0, utils_1.interpolate)(pattern, {
64
+ workspaceRoot: '',
65
+ projectRoot: context.projectsConfigurations.projects[context.projectName].root,
66
+ projectName: context.projectName,
67
+ });
68
+ });
61
69
  try {
62
- lintResults = await eslint.lintFiles(normalizedOptions.lintFilePatterns);
70
+ lintResults = await eslint.lintFiles(normalizedLintFilePatterns);
63
71
  }
64
72
  catch (err) {
65
73
  if (err.message.includes('You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser')) {
@@ -81,7 +89,7 @@ Please see https://nx.dev/guides/eslint for full guidance on how to resolve this
81
89
  throw err;
82
90
  }
83
91
  if (lintResults.length === 0 && errorOnUnmatchedPattern) {
84
- const ignoredPatterns = (await Promise.all(normalizedOptions.lintFilePatterns.map(async (pattern) => (await eslint.isPathIgnored(pattern)) ? pattern : null)))
92
+ const ignoredPatterns = (await Promise.all(normalizedLintFilePatterns.map(async (pattern) => (await eslint.isPathIgnored(pattern)) ? pattern : null)))
85
93
  .filter((pattern) => !!pattern)
86
94
  .map((pattern) => `- '${pattern}'`);
87
95
  if (ignoredPatterns.length) {
@@ -17,7 +17,7 @@
17
17
  "lintFilePatterns": {
18
18
  "type": "array",
19
19
  "description": "One or more files/dirs/globs to pass directly to ESLint's `lintFiles()` method.",
20
- "default": [],
20
+ "default": ["{projectRoot}"],
21
21
  "items": {
22
22
  "type": "string"
23
23
  }
@@ -144,6 +144,5 @@
144
144
  "default": true
145
145
  }
146
146
  },
147
- "required": ["lintFilePatterns"],
148
147
  "examplesFile": "../../../docs/eslint-examples.md"
149
148
  }
@@ -5,6 +5,7 @@ const devkit_1 = require("@nx/devkit");
5
5
  const ts = require("typescript");
6
6
  const ast_utils_1 = require("../../utils/flat-config/ast-utils");
7
7
  const eslint_file_1 = require("../../utils/eslint-file");
8
+ const path_utils_1 = require("../../utils/flat-config/path-utils");
8
9
  /**
9
10
  * Converts an ESLint JSON config to a flat config.
10
11
  * Deletes the original file along with .eslintignore if it exists.
@@ -69,7 +70,7 @@ function convertEslintJsonToFlatConfig(tree, root, config, ignorePaths) {
69
70
  override.parser) {
70
71
  isFlatCompatNeeded = true;
71
72
  }
72
- exportElements.push((0, ast_utils_1.generateFlatOverride)(override, root));
73
+ exportElements.push((0, ast_utils_1.generateFlatOverride)(override));
73
74
  });
74
75
  }
75
76
  if (config.ignorePatterns) {
@@ -78,7 +79,7 @@ function convertEslintJsonToFlatConfig(tree, root, config, ignorePaths) {
78
79
  : [config.ignorePatterns]).filter((pattern) => !['**/*', '!**/*', 'node_modules'].includes(pattern)); // these are useless in a flat config
79
80
  if (patterns.length > 0) {
80
81
  exportElements.push((0, ast_utils_1.generateAst)({
81
- ignores: patterns.map((path) => (0, ast_utils_1.mapFilePath)(path, root)),
82
+ ignores: patterns.map((path) => (0, path_utils_1.mapFilePath)(path)),
82
83
  }));
83
84
  }
84
85
  }
@@ -88,7 +89,7 @@ function convertEslintJsonToFlatConfig(tree, root, config, ignorePaths) {
88
89
  .read(ignorePath, 'utf-8')
89
90
  .split('\n')
90
91
  .filter((line) => line.length > 0 && line !== 'node_modules')
91
- .map((path) => (0, ast_utils_1.mapFilePath)(path, root));
92
+ .map((path) => (0, path_utils_1.mapFilePath)(path));
92
93
  if (patterns.length > 0) {
93
94
  exportElements.push((0, ast_utils_1.generateAst)({ ignores: patterns }));
94
95
  }
@@ -97,7 +98,7 @@ function convertEslintJsonToFlatConfig(tree, root, config, ignorePaths) {
97
98
  // create the node list and print it to new file
98
99
  const nodeList = (0, ast_utils_1.createNodeList)(importsMap, exportElements, isFlatCompatNeeded);
99
100
  return {
100
- content: (0, ast_utils_1.stringifyNodeList)(nodeList, root),
101
+ content: (0, ast_utils_1.stringifyNodeList)(nodeList),
101
102
  addESLintRC: isFlatCompatNeeded,
102
103
  addESLintJS: isESLintJSNeeded,
103
104
  };
@@ -80,18 +80,18 @@ const getGlobalEsLintConfiguration = (unitTestRunner, rootProject) => {
80
80
  exports.getGlobalEsLintConfiguration = getGlobalEsLintConfiguration;
81
81
  const getGlobalFlatEslintConfiguration = (unitTestRunner, rootProject) => {
82
82
  const nodeList = (0, ast_utils_1.createNodeList)(new Map(), [], true);
83
- let content = (0, ast_utils_1.stringifyNodeList)(nodeList, '');
83
+ let content = (0, ast_utils_1.stringifyNodeList)(nodeList);
84
84
  content = (0, ast_utils_1.addImportToFlatConfig)(content, 'nxPlugin', '@nx/eslint-plugin');
85
85
  content = (0, ast_utils_1.addPluginsToExportsBlock)(content, [
86
86
  { name: '@nx', varName: 'nxPlugin', imp: '@nx/eslint-plugin' },
87
87
  ]);
88
88
  if (!rootProject) {
89
- content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)(moduleBoundariesOverride, ''));
89
+ content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)(moduleBoundariesOverride));
90
90
  }
91
- content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)(exports.typeScriptOverride, ''));
92
- content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)(exports.javaScriptOverride, ''));
91
+ content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)(exports.typeScriptOverride));
92
+ content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)(exports.javaScriptOverride));
93
93
  if (unitTestRunner === 'jest') {
94
- content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)(jestOverride, ''));
94
+ content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)(jestOverride));
95
95
  }
96
96
  return content;
97
97
  };
@@ -23,7 +23,7 @@ function migrateConfigToMonorepoStyle(projects, tree, unitTestRunner) {
23
23
  projects.forEach((project) => {
24
24
  const lintTarget = findLintTarget(project);
25
25
  if (lintTarget) {
26
- const eslintFile = lintTarget.options.eslintConfig || (0, eslint_file_1.findEslintFile)(tree, project.root);
26
+ const eslintFile = lintTarget.options?.eslintConfig || (0, eslint_file_1.findEslintFile)(tree, project.root);
27
27
  if (eslintFile) {
28
28
  const projectEslintPath = (0, devkit_1.joinPathFragments)(project.root, eslintFile);
29
29
  migrateEslintFile(projectEslintPath, tree);
@@ -11,6 +11,5 @@ interface LintProjectOptions {
11
11
  unitTestRunner?: string;
12
12
  rootProject?: boolean;
13
13
  }
14
- export declare function mapLintPattern(projectRoot: string, extension: string, rootProject?: boolean): string;
15
14
  export declare function lintProjectGenerator(tree: Tree, options: LintProjectOptions): Promise<import("@nx/devkit").GeneratorCallback>;
16
15
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lintProjectGenerator = exports.mapLintPattern = void 0;
3
+ exports.lintProjectGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const eslint_file_1 = require("../utils/eslint-file");
6
6
  const path_1 = require("path");
@@ -9,15 +9,6 @@ const init_migration_1 = require("../init/init-migration");
9
9
  const project_configuration_1 = require("nx/src/generators/utils/project-configuration");
10
10
  const flat_config_1 = require("../../utils/flat-config");
11
11
  const ast_utils_1 = require("../utils/flat-config/ast-utils");
12
- function mapLintPattern(projectRoot, extension, rootProject) {
13
- if (rootProject && (projectRoot === '.' || projectRoot === '')) {
14
- return `${projectRoot}/src/**/*.${extension}`;
15
- }
16
- else {
17
- return `${projectRoot}/**/*.${extension}`;
18
- }
19
- }
20
- exports.mapLintPattern = mapLintPattern;
21
12
  async function lintProjectGenerator(tree, options) {
22
13
  const installTask = (0, init_1.lintInitGenerator)(tree, {
23
14
  linter: options.linter,
@@ -26,17 +17,24 @@ async function lintProjectGenerator(tree, options) {
26
17
  rootProject: options.rootProject,
27
18
  });
28
19
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
29
- const lintFilePatterns = options.eslintFilePatterns ?? [];
30
- if (isBuildableLibraryProject(projectConfig)) {
31
- lintFilePatterns.push(`${projectConfig.root}/package.json`);
32
- }
33
20
  projectConfig.targets['lint'] = {
34
21
  executor: '@nx/eslint:lint',
35
22
  outputs: ['{options.outputFile}'],
36
- options: {
37
- lintFilePatterns: lintFilePatterns,
38
- },
39
23
  };
24
+ let lintFilePatterns = options.eslintFilePatterns;
25
+ if (!lintFilePatterns && options.rootProject && projectConfig.root === '.') {
26
+ lintFilePatterns = ['./src'];
27
+ }
28
+ if (lintFilePatterns && lintFilePatterns.length) {
29
+ if (isBuildableLibraryProject(projectConfig) &&
30
+ !lintFilePatterns.includes('{projectRoot}')) {
31
+ lintFilePatterns.push(`{projectRoot}/package.json`);
32
+ }
33
+ // only add lintFilePatterns if they are explicitly defined
34
+ projectConfig.targets['lint'].options = {
35
+ lintFilePatterns,
36
+ };
37
+ }
40
38
  // we are adding new project which is not the root project or
41
39
  // companion e2e app so we should check if migration to
42
40
  // monorepo style is needed
@@ -138,10 +136,10 @@ function createEsLintConfiguration(tree, projectConfig, setParserOptionsProject,
138
136
  nodes.push((0, ast_utils_1.generateSpreadElement)('baseConfig'));
139
137
  }
140
138
  overrides.forEach((override) => {
141
- nodes.push((0, ast_utils_1.generateFlatOverride)(override, projectConfig.root));
139
+ nodes.push((0, ast_utils_1.generateFlatOverride)(override));
142
140
  });
143
141
  const nodeList = (0, ast_utils_1.createNodeList)(importMap, nodes, isCompatNeeded);
144
- const content = (0, ast_utils_1.stringifyNodeList)(nodeList, projectConfig.root);
142
+ const content = (0, ast_utils_1.stringifyNodeList)(nodeList);
145
143
  tree.write((0, path_1.join)(projectConfig.root, 'eslint.config.js'), content);
146
144
  }
147
145
  else {
@@ -4,6 +4,7 @@ exports.getPluginImport = exports.addIgnoresToLintConfig = exports.addPluginsToL
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const flat_config_1 = require("../../utils/flat-config");
6
6
  const ast_utils_1 = require("./flat-config/ast-utils");
7
+ const path_utils_1 = require("./flat-config/path-utils");
7
8
  exports.eslintConfigFileWhitelist = [
8
9
  '.eslintrc',
9
10
  '.eslintrc.js',
@@ -112,7 +113,7 @@ function addOverrideToLintConfig(tree, root, override, options = {
112
113
  const isBase = options.checkBaseConfig && findEslintFile(tree, root).includes('.base');
113
114
  if ((0, flat_config_1.useFlatConfig)(tree)) {
114
115
  const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? exports.baseEsLintFlatConfigFile : 'eslint.config.js');
115
- const flatOverride = (0, ast_utils_1.generateFlatOverride)(override, root);
116
+ const flatOverride = (0, ast_utils_1.generateFlatOverride)(override);
116
117
  let content = tree.read(fileName, 'utf8');
117
118
  // we will be using compat here so we need to make sure it's added
118
119
  if (overrideNeedsCompat(override)) {
@@ -123,7 +124,7 @@ function addOverrideToLintConfig(tree, root, override, options = {
123
124
  else {
124
125
  const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? exports.baseEsLintConfigFile : '.eslintrc.json');
125
126
  (0, devkit_1.updateJson)(tree, fileName, (json) => {
126
- json.overrides ?? [];
127
+ json.overrides ??= [];
127
128
  if (options.insertAtTheEnd) {
128
129
  json.overrides.push(override);
129
130
  }
@@ -183,7 +184,7 @@ function replaceOverridesInLintConfig(tree, root, overrides) {
183
184
  }
184
185
  content = (0, ast_utils_1.removeOverridesFromLintConfig)(content);
185
186
  overrides.forEach((override) => {
186
- const flatOverride = (0, ast_utils_1.generateFlatOverride)(override, root);
187
+ const flatOverride = (0, ast_utils_1.generateFlatOverride)(override);
187
188
  (0, ast_utils_1.addBlockToFlatConfigExport)(content, flatOverride);
188
189
  });
189
190
  tree.write(fileName, content);
@@ -247,7 +248,7 @@ function addIgnoresToLintConfig(tree, root, ignorePatterns) {
247
248
  if ((0, flat_config_1.useFlatConfig)(tree)) {
248
249
  const fileName = (0, devkit_1.joinPathFragments)(root, 'eslint.config.js');
249
250
  const block = (0, ast_utils_1.generateAst)({
250
- ignores: ignorePatterns.map((path) => (0, ast_utils_1.mapFilePath)(path, root)),
251
+ ignores: ignorePatterns.map((path) => (0, path_utils_1.mapFilePath)(path)),
251
252
  });
252
253
  tree.write(fileName, (0, ast_utils_1.addBlockToFlatConfigExport)(tree.read(fileName, 'utf8'), block));
253
254
  }
@@ -44,7 +44,7 @@ export declare function generatePluginExtendsElement(plugins: string[]): ts.Spre
44
44
  /**
45
45
  * Stringifies TS nodes to file content string
46
46
  */
47
- export declare function stringifyNodeList(nodes: ts.NodeArray<ts.VariableStatement | ts.Identifier | ts.ExpressionStatement | ts.SourceFile>, root: string): string;
47
+ export declare function stringifyNodeList(nodes: ts.NodeArray<ts.VariableStatement | ts.Identifier | ts.ExpressionStatement | ts.SourceFile>): string;
48
48
  /**
49
49
  * generates AST require statement
50
50
  */
@@ -52,9 +52,8 @@ export declare function generateRequire(variableName: string | ts.ObjectBindingP
52
52
  /**
53
53
  * Generates AST object or spread element based on JSON override object
54
54
  */
55
- export declare function generateFlatOverride(override: Linter.ConfigOverride<Linter.RulesRecord>, root: string): ts.ObjectLiteralExpression | ts.SpreadElement;
56
- export declare function mapFilePaths(override: Linter.ConfigOverride<Linter.RulesRecord>, root: string): void;
57
- export declare function mapFilePath(filePath: string, root: string): string;
55
+ export declare function generateFlatOverride(override: Linter.ConfigOverride<Linter.RulesRecord>): ts.ObjectLiteralExpression | ts.SpreadElement;
56
+ export declare function mapFilePaths(override: Linter.ConfigOverride<Linter.RulesRecord>): void;
58
57
  /**
59
58
  * Generates an AST from a JSON-type input
60
59
  */
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateAst = exports.mapFilePath = exports.mapFilePaths = exports.generateFlatOverride = exports.generateRequire = exports.stringifyNodeList = exports.generatePluginExtendsElement = exports.generateSpreadElement = exports.createNodeList = exports.addCompatToFlatConfig = exports.addPluginsToExportsBlock = exports.removeCompatExtends = exports.removePlugin = exports.addBlockToFlatConfigExport = exports.addImportToFlatConfig = exports.replaceOverride = exports.hasOverride = exports.removeOverridesFromLintConfig = void 0;
3
+ exports.generateAst = exports.mapFilePaths = exports.generateFlatOverride = exports.generateRequire = exports.stringifyNodeList = exports.generatePluginExtendsElement = exports.generateSpreadElement = exports.createNodeList = exports.addCompatToFlatConfig = exports.addPluginsToExportsBlock = exports.removeCompatExtends = exports.removePlugin = exports.addBlockToFlatConfigExport = exports.addImportToFlatConfig = exports.replaceOverride = exports.hasOverride = exports.removeOverridesFromLintConfig = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const ts = require("typescript");
6
+ const path_utils_1 = require("./path-utils");
6
7
  /**
7
8
  * Remove all overrides from the config file
8
9
  */
@@ -63,7 +64,7 @@ function hasOverride(content, lookup) {
63
64
  // strip any spread elements
64
65
  objSource = fullNodeText.replace(/\s*\.\.\.[a-zA-Z0-9_]+,?\n?/, '');
65
66
  }
66
- const data = JSON.parse(objSource
67
+ const data = (0, devkit_1.parseJson)(objSource
67
68
  // ensure property names have double quotes so that JSON.parse works
68
69
  .replace(/'/g, '"')
69
70
  .replace(/\s([a-zA-Z0-9_]+)\s*:/g, ' "$1": '));
@@ -77,7 +78,7 @@ function hasOverride(content, lookup) {
77
78
  exports.hasOverride = hasOverride;
78
79
  const STRIP_SPREAD_ELEMENTS = /\s*\.\.\.[a-zA-Z0-9_]+,?\n?/g;
79
80
  function parseTextToJson(text) {
80
- return JSON.parse(text
81
+ return (0, devkit_1.parseJson)(text
81
82
  // ensure property names have double quotes so that JSON.parse works
82
83
  .replace(/'/g, '"')
83
84
  .replace(/\s([a-zA-Z0-9_]+)\s*:/g, ' "$1": '));
@@ -118,7 +119,7 @@ function replaceOverride(content, root, lookup, update) {
118
119
  length: end - start,
119
120
  });
120
121
  const updatedData = update(data);
121
- mapFilePaths(updatedData, root);
122
+ mapFilePaths(updatedData);
122
123
  changes.push({
123
124
  type: devkit_1.ChangeType.Insert,
124
125
  index: start,
@@ -470,9 +471,9 @@ exports.generatePluginExtendsElement = generatePluginExtendsElement;
470
471
  /**
471
472
  * Stringifies TS nodes to file content string
472
473
  */
473
- function stringifyNodeList(nodes, root) {
474
+ function stringifyNodeList(nodes) {
474
475
  const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
475
- const resultFile = ts.createSourceFile((0, devkit_1.joinPathFragments)(root, ''), '', ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
476
+ const resultFile = ts.createSourceFile('', '', ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
476
477
  return (printer
477
478
  .printList(ts.ListFormat.MultiLine, nodes, resultFile)
478
479
  // add new line before compat initialization
@@ -493,8 +494,8 @@ exports.generateRequire = generateRequire;
493
494
  /**
494
495
  * Generates AST object or spread element based on JSON override object
495
496
  */
496
- function generateFlatOverride(override, root) {
497
- mapFilePaths(override, root);
497
+ function generateFlatOverride(override) {
498
+ mapFilePaths(override);
498
499
  if (!override.env &&
499
500
  !override.extends &&
500
501
  !override.plugins &&
@@ -515,41 +516,21 @@ function generateFlatOverride(override, root) {
515
516
  ]));
516
517
  }
517
518
  exports.generateFlatOverride = generateFlatOverride;
518
- function mapFilePaths(override, root) {
519
+ function mapFilePaths(override) {
519
520
  if (override.files) {
520
521
  override.files = Array.isArray(override.files)
521
522
  ? override.files
522
523
  : [override.files];
523
- override.files = override.files.map((file) => mapFilePath(file, root));
524
+ override.files = override.files.map((file) => (0, path_utils_1.mapFilePath)(file));
524
525
  }
525
526
  if (override.excludedFiles) {
526
527
  override.excludedFiles = Array.isArray(override.excludedFiles)
527
528
  ? override.excludedFiles
528
529
  : [override.excludedFiles];
529
- override.excludedFiles = override.excludedFiles.map((file) => mapFilePath(file, root));
530
+ override.excludedFiles = override.excludedFiles.map((file) => (0, path_utils_1.mapFilePath)(file));
530
531
  }
531
532
  }
532
533
  exports.mapFilePaths = mapFilePaths;
533
- function mapFilePath(filePath, root) {
534
- if (filePath.startsWith('!')) {
535
- const fileWithoutBang = filePath.slice(1);
536
- if (fileWithoutBang.startsWith('*.')) {
537
- return `!${(0, devkit_1.joinPathFragments)(root, '**', fileWithoutBang)}`;
538
- }
539
- else if (!fileWithoutBang.startsWith(root)) {
540
- return `!${(0, devkit_1.joinPathFragments)(root, fileWithoutBang)}`;
541
- }
542
- return filePath;
543
- }
544
- if (filePath.startsWith('*.')) {
545
- return (0, devkit_1.joinPathFragments)(root, '**', filePath);
546
- }
547
- else if (!filePath.startsWith(root)) {
548
- return (0, devkit_1.joinPathFragments)(root, filePath);
549
- }
550
- return filePath;
551
- }
552
- exports.mapFilePath = mapFilePath;
553
534
  function addTSObjectProperty(elements, key, value) {
554
535
  if (value) {
555
536
  elements.push(ts.factory.createPropertyAssignment(key, generateAst(value)));
@@ -1,2 +1,3 @@
1
1
  import type { Linter } from 'eslint';
2
- export declare function updateFiles(override: Linter.ConfigOverride<Linter.RulesRecord>, root: string): Linter.ConfigOverride<Linter.RulesRecord>;
2
+ export declare function updateFiles(override: Linter.ConfigOverride<Linter.RulesRecord>): Linter.ConfigOverride<Linter.RulesRecord>;
3
+ export declare function mapFilePath(filePath: string): string;
@@ -1,31 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateFiles = void 0;
3
+ exports.mapFilePath = exports.updateFiles = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
- function updateFiles(override, root) {
5
+ function updateFiles(override) {
6
6
  if (override.files) {
7
7
  override.files = Array.isArray(override.files)
8
8
  ? override.files
9
9
  : [override.files];
10
- override.files = override.files.map((file) => mapFilePath(file, root));
10
+ override.files = override.files.map((file) => mapFilePath(file));
11
11
  }
12
12
  return override;
13
13
  }
14
14
  exports.updateFiles = updateFiles;
15
- function mapFilePath(filePath, root) {
15
+ function mapFilePath(filePath) {
16
16
  if (filePath.startsWith('!')) {
17
17
  const fileWithoutBang = filePath.slice(1);
18
18
  if (fileWithoutBang.startsWith('*.')) {
19
- return `!${(0, devkit_1.joinPathFragments)(root, '**', fileWithoutBang)}`;
20
- }
21
- else {
22
- return `!${(0, devkit_1.joinPathFragments)(root, fileWithoutBang)}`;
19
+ return `!${(0, devkit_1.joinPathFragments)('**', fileWithoutBang)}`;
23
20
  }
21
+ return filePath;
24
22
  }
25
23
  if (filePath.startsWith('*.')) {
26
- return (0, devkit_1.joinPathFragments)(root, '**', filePath);
27
- }
28
- else {
29
- return (0, devkit_1.joinPathFragments)(root, filePath);
24
+ return (0, devkit_1.joinPathFragments)('**', filePath);
30
25
  }
26
+ return filePath;
31
27
  }
28
+ exports.mapFilePath = mapFilePath;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function update(tree: Tree): Promise<void>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ async function update(tree) {
5
+ const projects = (0, devkit_1.getProjects)(tree);
6
+ for (const [projectName, projectConfiguration] of projects) {
7
+ let needsUpdate = false;
8
+ for (const [targetName, targetConfig] of Object.entries(projectConfiguration.targets ?? {})) {
9
+ if (targetConfig.executor !== '@nx/eslint:lint') {
10
+ continue;
11
+ }
12
+ needsUpdate = true;
13
+ if (projectConfiguration.targets[targetName].options?.lintFilePatterns) {
14
+ const rootPattern = getLintRoot(projectConfiguration);
15
+ const nonRootPatterns = projectConfiguration.targets[targetName].options.lintFilePatterns.filter((p) => !p.startsWith(rootPattern) && !p.startsWith('{projectRoot}'));
16
+ if (nonRootPatterns.length === 0 &&
17
+ rootPattern === projectConfiguration.root) {
18
+ // delete the lintFilePatterns option if it's the only option and matches the root of the project
19
+ delete projectConfiguration.targets[targetName].options
20
+ .lintFilePatterns;
21
+ if (Object.keys(projectConfiguration.targets[targetName].options)
22
+ .length === 0) {
23
+ delete projectConfiguration.targets[targetName].options;
24
+ }
25
+ }
26
+ else {
27
+ projectConfiguration.targets[targetName].options.lintFilePatterns = [
28
+ rootPattern,
29
+ ...nonRootPatterns,
30
+ ];
31
+ }
32
+ }
33
+ }
34
+ if (needsUpdate) {
35
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
36
+ }
37
+ }
38
+ await (0, devkit_1.formatFiles)(tree);
39
+ }
40
+ exports.default = update;
41
+ function getLintRoot({ root, sourceRoot }) {
42
+ if (root === '' || root === '.') {
43
+ return sourceRoot || './src';
44
+ }
45
+ return root;
46
+ }