@nx/eslint 17.2.0-beta.8 → 17.2.0-canary.20231206-a93ee1c

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": "17.2.0-beta.8",
3
+ "version": "17.2.0-canary.20231206-a93ee1c",
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": {
@@ -27,18 +27,18 @@
27
27
  "requirements": {},
28
28
  "migrations": "./migrations.json"
29
29
  },
30
- "executors": "./executors.json",
31
30
  "generators": "./generators.json",
31
+ "executors": "./executors.json",
32
32
  "peerDependencies": {
33
33
  "eslint": "^8.0.0",
34
34
  "js-yaml": "4.1.0"
35
35
  },
36
36
  "dependencies": {
37
+ "@nx/devkit": "17.2.0-canary.20231206-a93ee1c",
38
+ "@nx/js": "17.2.0-canary.20231206-a93ee1c",
37
39
  "tslib": "^2.3.0",
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.8"
41
+ "@nx/linter": "17.2.0-canary.20231206-a93ee1c"
42
42
  },
43
43
  "peerDependenciesMeta": {
44
44
  "eslint": {
package/plugin.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { createNodes, EslintPluginOptions } from './src/plugins/plugin';
package/plugin.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNodes = void 0;
4
+ var plugin_1 = require("./src/plugins/plugin");
5
+ Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_1.createNodes; } });
@@ -71,13 +71,14 @@ async function run(options, context) {
71
71
  }
72
72
  catch (err) {
73
73
  if (err.message.includes('You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser')) {
74
+ const ruleName = err.message.match(/rule '([^']+)':/)?.[1];
74
75
  let eslintConfigPathForError = `for ${projectName}`;
75
76
  if (context.projectsConfigurations?.projects?.[projectName]?.root) {
76
77
  const { root } = context.projectsConfigurations.projects[projectName];
77
78
  eslintConfigPathForError = `\`${root}/.eslintrc.json\``;
78
79
  }
79
80
  console.error(`
80
- Error: You have attempted to use a lint rule which requires the full TypeScript type-checker to be available, but you do not have \`parserOptions.project\` configured to point at your project tsconfig.json files in the relevant TypeScript file "overrides" block of your project ESLint config ${eslintConfigPath || eslintConfigPathForError}
81
+ Error: You have attempted to use ${ruleName ? `the lint rule ${ruleName}` : 'a lint rule'} which requires the full TypeScript type-checker to be available, but you do not have \`parserOptions.project\` configured to point at your project tsconfig.json files in the relevant TypeScript file "overrides" block of your project ESLint config ${eslintConfigPath || eslintConfigPathForError}
81
82
 
82
83
  Please see https://nx.dev/guides/eslint for full guidance on how to resolve this issue.
83
84
  `);
@@ -5,18 +5,23 @@ const devkit_1 = require("@nx/devkit");
5
5
  const versions_1 = require("../../utils/versions");
6
6
  const eslint_file_1 = require("../utils/eslint-file");
7
7
  const global_eslint_config_1 = require("./global-eslint-config");
8
- function addTargetDefaults(tree) {
8
+ const plugin_1 = require("../utils/plugin");
9
+ function updateProductionFileset(tree) {
9
10
  const nxJson = (0, devkit_1.readNxJson)(tree);
10
11
  const productionFileSet = nxJson.namedInputs?.production;
11
12
  if (productionFileSet) {
12
- // Remove .eslintrc.json
13
13
  productionFileSet.push('!{projectRoot}/.eslintrc.json');
14
14
  productionFileSet.push('!{projectRoot}/eslint.config.js');
15
15
  // Dedupe and set
16
16
  nxJson.namedInputs.production = Array.from(new Set(productionFileSet));
17
17
  }
18
+ (0, devkit_1.updateNxJson)(tree, nxJson);
19
+ }
20
+ function addTargetDefaults(tree) {
21
+ const nxJson = (0, devkit_1.readNxJson)(tree);
18
22
  nxJson.targetDefaults ??= {};
19
23
  nxJson.targetDefaults.lint ??= {};
24
+ nxJson.targetDefaults.lint.cache ??= true;
20
25
  nxJson.targetDefaults.lint.inputs ??= [
21
26
  'default',
22
27
  `{workspaceRoot}/.eslintrc.json`,
@@ -25,11 +30,48 @@ function addTargetDefaults(tree) {
25
30
  ];
26
31
  (0, devkit_1.updateNxJson)(tree, nxJson);
27
32
  }
33
+ function addPlugin(tree) {
34
+ const nxJson = (0, devkit_1.readNxJson)(tree);
35
+ nxJson.plugins ??= [];
36
+ for (const plugin of nxJson.plugins) {
37
+ if (typeof plugin === 'string'
38
+ ? plugin === '@nx/eslint/plugin'
39
+ : plugin.plugin === '@nx/eslint/plugin') {
40
+ return;
41
+ }
42
+ }
43
+ nxJson.plugins.push({
44
+ plugin: '@nx/eslint/plugin',
45
+ options: {
46
+ targetName: 'lint',
47
+ },
48
+ });
49
+ (0, devkit_1.updateNxJson)(tree, nxJson);
50
+ }
51
+ function updateVSCodeExtensions(tree) {
52
+ if (tree.exists('.vscode/extensions.json')) {
53
+ (0, devkit_1.updateJson)(tree, '.vscode/extensions.json', (json) => {
54
+ json.recommendations ||= [];
55
+ const extension = 'dbaeumer.vscode-eslint';
56
+ if (!json.recommendations.includes(extension)) {
57
+ json.recommendations.push(extension);
58
+ }
59
+ return json;
60
+ });
61
+ }
62
+ }
28
63
  /**
29
64
  * Initializes ESLint configuration in a workspace and adds necessary dependencies.
30
65
  */
31
66
  function initEsLint(tree, options) {
32
- if ((0, eslint_file_1.findEslintFile)(tree)) {
67
+ const addPlugins = process.env.NX_PCV3 === 'true';
68
+ const hasPlugin = (0, plugin_1.hasEslintPlugin)(tree);
69
+ const rootEslintFile = (0, eslint_file_1.findEslintFile)(tree);
70
+ if (rootEslintFile && addPlugins && !hasPlugin) {
71
+ addPlugin(tree);
72
+ return () => { };
73
+ }
74
+ if (rootEslintFile) {
33
75
  return () => { };
34
76
  }
35
77
  if (!options.skipPackageJson) {
@@ -37,17 +79,14 @@ function initEsLint(tree, options) {
37
79
  }
38
80
  (0, devkit_1.writeJson)(tree, '.eslintrc.json', (0, global_eslint_config_1.getGlobalEsLintConfiguration)(options.unitTestRunner, options.rootProject));
39
81
  tree.write('.eslintignore', 'node_modules\n');
40
- addTargetDefaults(tree);
41
- if (tree.exists('.vscode/extensions.json')) {
42
- (0, devkit_1.updateJson)(tree, '.vscode/extensions.json', (json) => {
43
- json.recommendations ||= [];
44
- const extension = 'dbaeumer.vscode-eslint';
45
- if (!json.recommendations.includes(extension)) {
46
- json.recommendations.push(extension);
47
- }
48
- return json;
49
- });
82
+ updateProductionFileset(tree);
83
+ if (addPlugins) {
84
+ addPlugin(tree);
85
+ }
86
+ else {
87
+ addTargetDefaults(tree);
50
88
  }
89
+ updateVSCodeExtensions(tree);
51
90
  return !options.skipPackageJson
52
91
  ? (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
53
92
  '@nx/eslint': versions_1.nxVersion,
@@ -9,6 +9,8 @@ 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
+ const config_file_1 = require("../../utils/config-file");
13
+ const plugin_1 = require("../utils/plugin");
12
14
  async function lintProjectGenerator(tree, options) {
13
15
  const installTask = (0, init_1.lintInitGenerator)(tree, {
14
16
  linter: options.linter,
@@ -17,23 +19,39 @@ async function lintProjectGenerator(tree, options) {
17
19
  rootProject: options.rootProject,
18
20
  });
19
21
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
20
- projectConfig.targets['lint'] = {
21
- executor: '@nx/eslint:lint',
22
- outputs: ['{options.outputFile}'],
23
- };
24
22
  let lintFilePatterns = options.eslintFilePatterns;
25
23
  if (!lintFilePatterns && options.rootProject && projectConfig.root === '.') {
26
24
  lintFilePatterns = ['./src'];
27
25
  }
28
- if (lintFilePatterns && lintFilePatterns.length) {
29
- if (isBuildableLibraryProject(projectConfig) &&
30
- !lintFilePatterns.includes('{projectRoot}')) {
31
- lintFilePatterns.push(`{projectRoot}/package.json`);
26
+ if (lintFilePatterns &&
27
+ lintFilePatterns.length &&
28
+ !lintFilePatterns.includes('{projectRoot}') &&
29
+ isBuildableLibraryProject(projectConfig)) {
30
+ lintFilePatterns.push(`{projectRoot}/package.json`);
31
+ }
32
+ const hasPlugin = (0, plugin_1.hasEslintPlugin)(tree);
33
+ if (hasPlugin) {
34
+ if (lintFilePatterns &&
35
+ lintFilePatterns.length &&
36
+ lintFilePatterns.some((p) => !['./src', '{projectRoot}', projectConfig.root].includes(p))) {
37
+ projectConfig.targets['lint'] = {
38
+ command: `eslint ${lintFilePatterns
39
+ .join(' ')
40
+ .replace('{projectRoot}', projectConfig.root)}`,
41
+ };
32
42
  }
33
- // only add lintFilePatterns if they are explicitly defined
34
- projectConfig.targets['lint'].options = {
35
- lintFilePatterns,
43
+ }
44
+ else {
45
+ projectConfig.targets['lint'] = {
46
+ executor: '@nx/eslint:lint',
47
+ outputs: ['{options.outputFile}'],
36
48
  };
49
+ if (lintFilePatterns && lintFilePatterns.length) {
50
+ // only add lintFilePatterns if they are explicitly defined
51
+ projectConfig.targets['lint'].options = {
52
+ lintFilePatterns,
53
+ };
54
+ }
37
55
  }
38
56
  // we are adding new project which is not the root project or
39
57
  // companion e2e app so we should check if migration to
@@ -168,8 +186,8 @@ function isBuildableLibraryProject(projectConfig) {
168
186
  */
169
187
  function isMigrationToMonorepoNeeded(projects, tree) {
170
188
  // the base config is already created, migration has been done
171
- if (tree.exists(eslint_file_1.baseEsLintConfigFile) ||
172
- tree.exists(eslint_file_1.baseEsLintFlatConfigFile)) {
189
+ if (tree.exists(config_file_1.baseEsLintConfigFile) ||
190
+ tree.exists(config_file_1.baseEsLintFlatConfigFile)) {
173
191
  return false;
174
192
  }
175
193
  const configs = Object.values(projects);
@@ -1,8 +1,5 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { Linter } from 'eslint';
3
- export declare const eslintConfigFileWhitelist: string[];
4
- export declare const baseEsLintConfigFile = ".eslintrc.base.json";
5
- export declare const baseEsLintFlatConfigFile = "eslint.base.config.js";
6
3
  export declare function findEslintFile(tree: Tree, projectRoot?: string): string | null;
7
4
  export declare function isEslintConfigSupported(tree: Tree, projectRoot?: string): boolean;
8
5
  export declare function updateRelativePathsInConfig(tree: Tree, sourcePath: string, destinationPath: string): void;
@@ -1,29 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPluginImport = exports.addIgnoresToLintConfig = exports.addPluginsToLintConfig = exports.addExtendsToLintConfig = exports.replaceOverridesInLintConfig = exports.lintConfigHasOverride = exports.updateOverrideInLintConfig = exports.addOverrideToLintConfig = exports.updateRelativePathsInConfig = exports.isEslintConfigSupported = exports.findEslintFile = exports.baseEsLintFlatConfigFile = exports.baseEsLintConfigFile = exports.eslintConfigFileWhitelist = void 0;
3
+ exports.getPluginImport = exports.addIgnoresToLintConfig = exports.addPluginsToLintConfig = exports.addExtendsToLintConfig = exports.replaceOverridesInLintConfig = exports.lintConfigHasOverride = exports.updateOverrideInLintConfig = exports.addOverrideToLintConfig = exports.updateRelativePathsInConfig = exports.isEslintConfigSupported = exports.findEslintFile = void 0;
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
7
  const path_utils_1 = require("./flat-config/path-utils");
8
- exports.eslintConfigFileWhitelist = [
9
- '.eslintrc',
10
- '.eslintrc.js',
11
- '.eslintrc.cjs',
12
- '.eslintrc.yaml',
13
- '.eslintrc.yml',
14
- '.eslintrc.json',
15
- 'eslint.config.js',
16
- ];
17
- exports.baseEsLintConfigFile = '.eslintrc.base.json';
18
- exports.baseEsLintFlatConfigFile = 'eslint.base.config.js';
19
- function findEslintFile(tree, projectRoot = '') {
20
- if (projectRoot === '' && tree.exists(exports.baseEsLintConfigFile)) {
21
- return exports.baseEsLintConfigFile;
8
+ const config_file_1 = require("../../utils/config-file");
9
+ function findEslintFile(tree, projectRoot) {
10
+ if (projectRoot === undefined && tree.exists(config_file_1.baseEsLintConfigFile)) {
11
+ return config_file_1.baseEsLintConfigFile;
22
12
  }
23
- if (projectRoot === '' && tree.exists(exports.baseEsLintFlatConfigFile)) {
24
- return exports.baseEsLintFlatConfigFile;
13
+ if (projectRoot === undefined && tree.exists(config_file_1.baseEsLintFlatConfigFile)) {
14
+ return config_file_1.baseEsLintFlatConfigFile;
25
15
  }
26
- for (const file of exports.eslintConfigFileWhitelist) {
16
+ projectRoot ??= '';
17
+ for (const file of config_file_1.ESLINT_CONFIG_FILENAMES) {
27
18
  if (tree.exists((0, devkit_1.joinPathFragments)(projectRoot, file))) {
28
19
  return file;
29
20
  }
@@ -94,7 +85,7 @@ function replaceFlatConfigPaths(config, sourceRoot, offset, destinationRoot, tre
94
85
  return newConfig;
95
86
  }
96
87
  function offsetFilePath(projectRoot, pathToFile, offset, tree) {
97
- if (exports.eslintConfigFileWhitelist.some((eslintFile) => pathToFile.includes(eslintFile))) {
88
+ if (config_file_1.ESLINT_CONFIG_FILENAMES.some((eslintFile) => pathToFile.includes(eslintFile))) {
98
89
  // if the file is point to base eslint
99
90
  const rootEslint = findEslintFile(tree);
100
91
  if (rootEslint) {
@@ -112,7 +103,7 @@ function addOverrideToLintConfig(tree, root, override, options = {
112
103
  }) {
113
104
  const isBase = options.checkBaseConfig && findEslintFile(tree, root).includes('.base');
114
105
  if ((0, flat_config_1.useFlatConfig)(tree)) {
115
- const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? exports.baseEsLintFlatConfigFile : 'eslint.config.js');
106
+ const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? config_file_1.baseEsLintFlatConfigFile : 'eslint.config.js');
116
107
  const flatOverride = (0, ast_utils_1.generateFlatOverride)(override);
117
108
  let content = tree.read(fileName, 'utf8');
118
109
  // we will be using compat here so we need to make sure it's added
@@ -122,7 +113,7 @@ function addOverrideToLintConfig(tree, root, override, options = {
122
113
  tree.write(fileName, (0, ast_utils_1.addBlockToFlatConfigExport)(content, flatOverride, options));
123
114
  }
124
115
  else {
125
- const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? exports.baseEsLintConfigFile : '.eslintrc.json');
116
+ const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? config_file_1.baseEsLintConfigFile : '.eslintrc.json');
126
117
  (0, devkit_1.updateJson)(tree, fileName, (json) => {
127
118
  json.overrides ??= [];
128
119
  if (options.insertAtTheEnd) {
@@ -164,12 +155,12 @@ function lintConfigHasOverride(tree, root, lookup, checkBaseConfig = false) {
164
155
  }
165
156
  const isBase = checkBaseConfig && findEslintFile(tree, root).includes('.base');
166
157
  if ((0, flat_config_1.useFlatConfig)(tree)) {
167
- const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? exports.baseEsLintFlatConfigFile : 'eslint.config.js');
158
+ const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? config_file_1.baseEsLintFlatConfigFile : 'eslint.config.js');
168
159
  const content = tree.read(fileName, 'utf8');
169
160
  return (0, ast_utils_1.hasOverride)(content, lookup);
170
161
  }
171
162
  else {
172
- const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? exports.baseEsLintConfigFile : '.eslintrc.json');
163
+ const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? config_file_1.baseEsLintConfigFile : '.eslintrc.json');
173
164
  return (0, devkit_1.readJson)(tree, fileName).overrides?.some(lookup) || false;
174
165
  }
175
166
  }
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export declare function hasEslintPlugin(tree: Tree): boolean;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasEslintPlugin = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function hasEslintPlugin(tree) {
6
+ const nxJson = (0, devkit_1.readNxJson)(tree);
7
+ return nxJson.plugins?.some((p) => typeof p === 'string'
8
+ ? p === '@nx/eslint/plugin'
9
+ : p.plugin === '@nx/eslint/plugin');
10
+ }
11
+ exports.hasEslintPlugin = hasEslintPlugin;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const devkit_1 = require("@nx/devkit");
4
- const eslint_file_1 = require("../../generators/utils/eslint-file");
5
4
  const eslint_targets_1 = require("../../generators/utils/eslint-targets");
5
+ const config_file_1 = require("../../utils/config-file");
6
6
  async function addEslintInputs(tree) {
7
7
  const nxJson = (0, devkit_1.readNxJson)(tree);
8
- const globalEslintFile = eslint_file_1.eslintConfigFileWhitelist.find((file) => tree.exists(file));
8
+ const globalEslintFile = config_file_1.ESLINT_CONFIG_FILENAMES.find((file) => tree.exists(file));
9
9
  if (globalEslintFile && nxJson.namedInputs?.production) {
10
10
  const productionFileset = new Set(nxJson.namedInputs.production);
11
11
  productionFileset.add(`!{projectRoot}/${globalEslintFile}`);
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const devkit_1 = require("@nx/devkit");
4
- const eslint_file_1 = require("../../generators/utils/eslint-file");
5
4
  const eslint_targets_1 = require("../../generators/utils/eslint-targets");
5
+ const config_file_1 = require("../../utils/config-file");
6
6
  async function addEslintIgnore(tree) {
7
7
  const nxJson = (0, devkit_1.readJson)(tree, 'nx.json');
8
- const globalEslintFile = eslint_file_1.eslintConfigFileWhitelist.find((file) => tree.exists(file));
8
+ const globalEslintFile = config_file_1.ESLINT_CONFIG_FILENAMES.find((file) => tree.exists(file));
9
9
  if (globalEslintFile) {
10
10
  if (tree.exists('.eslintignore')) {
11
11
  const content = tree.read('.eslintignore', 'utf-8');
@@ -0,0 +1,5 @@
1
+ import { CreateNodes } from '@nx/devkit';
2
+ export interface EslintPluginOptions {
3
+ targetName?: string;
4
+ }
5
+ export declare const createNodes: CreateNodes<EslintPluginOptions>;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNodes = void 0;
4
+ const path_1 = require("path");
5
+ const project_configuration_utils_1 = require("nx/src/project-graph/utils/project-configuration-utils");
6
+ const fs_1 = require("fs");
7
+ const globs_1 = require("nx/src/utils/globs");
8
+ const config_file_1 = require("../utils/config-file");
9
+ exports.createNodes = [
10
+ (0, globs_1.combineGlobPatterns)(['**/project.json', '**/package.json']),
11
+ (configFilePath, options, context) => {
12
+ const projectRoot = (0, path_1.dirname)(configFilePath);
13
+ options = normalizeOptions(options);
14
+ const eslintConfigs = getEslintConfigsForProject(projectRoot, context.workspaceRoot);
15
+ if (!eslintConfigs.length) {
16
+ return {};
17
+ }
18
+ return {
19
+ projects: {
20
+ [projectRoot]: {
21
+ targets: buildEslintTargets(eslintConfigs, projectRoot, options, context),
22
+ },
23
+ },
24
+ };
25
+ },
26
+ ];
27
+ function getEslintConfigsForProject(projectRoot, workspaceRoot) {
28
+ const detectedConfigs = new Set();
29
+ const baseConfig = (0, config_file_1.findBaseEslintFile)(workspaceRoot);
30
+ if (baseConfig) {
31
+ detectedConfigs.add(baseConfig);
32
+ }
33
+ let siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(workspaceRoot, projectRoot));
34
+ if (projectRoot === '.') {
35
+ // If there's no src folder, it's not a standalone project
36
+ if (!siblingFiles.includes('src')) {
37
+ return [];
38
+ }
39
+ // If it's standalone but doesn't have eslint config, it's not a lintable
40
+ const config = siblingFiles.find((f) => config_file_1.ESLINT_CONFIG_FILENAMES.includes(f));
41
+ if (!config) {
42
+ return [];
43
+ }
44
+ detectedConfigs.add(config);
45
+ return Array.from(detectedConfigs);
46
+ }
47
+ while (projectRoot !== '.') {
48
+ // if it has an eslint config it's lintable
49
+ const config = siblingFiles.find((f) => config_file_1.ESLINT_CONFIG_FILENAMES.includes(f));
50
+ if (config) {
51
+ detectedConfigs.add(`${projectRoot}/${config}`);
52
+ return Array.from(detectedConfigs);
53
+ }
54
+ projectRoot = (0, path_1.dirname)(projectRoot);
55
+ siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(workspaceRoot, projectRoot));
56
+ }
57
+ // check whether the root has an eslint config
58
+ const config = (0, fs_1.readdirSync)(workspaceRoot).find((f) => config_file_1.ESLINT_CONFIG_FILENAMES.includes(f));
59
+ if (config) {
60
+ detectedConfigs.add(config);
61
+ return Array.from(detectedConfigs);
62
+ }
63
+ return [];
64
+ }
65
+ function buildEslintTargets(eslintConfigs, projectRoot, options, context) {
66
+ const targetDefaults = (0, project_configuration_utils_1.readTargetDefaultsForTarget)(options.targetName, context.nxJsonConfiguration.targetDefaults, '@nx/eslint:lint');
67
+ const isRootProject = projectRoot === '.';
68
+ const targets = {};
69
+ const baseTargetConfig = {
70
+ command: `eslint ${isRootProject ? './src' : '.'}`,
71
+ options: {
72
+ cwd: projectRoot,
73
+ },
74
+ };
75
+ if (eslintConfigs.some((config) => (0, config_file_1.isFlatConfig)(config))) {
76
+ baseTargetConfig.options.env = {
77
+ ESLINT_USE_FLAT_CONFIG: 'true',
78
+ };
79
+ }
80
+ targets[options.targetName] = {
81
+ ...baseTargetConfig,
82
+ cache: targetDefaults?.cache ?? true,
83
+ inputs: targetDefaults?.inputs ?? [
84
+ 'default',
85
+ ...eslintConfigs.map((config) => `{workspaceRoot}/${config}`),
86
+ '{workspaceRoot}/tools/eslint-rules/**/*',
87
+ { externalDependencies: ['eslint'] },
88
+ ],
89
+ options: {
90
+ ...baseTargetConfig.options,
91
+ },
92
+ };
93
+ return targets;
94
+ }
95
+ function normalizeOptions(options) {
96
+ options ??= {};
97
+ options.targetName ??= 'lint';
98
+ return options;
99
+ }
@@ -0,0 +1,5 @@
1
+ export declare const ESLINT_CONFIG_FILENAMES: string[];
2
+ export declare const baseEsLintConfigFile = ".eslintrc.base.json";
3
+ export declare const baseEsLintFlatConfigFile = "eslint.base.config.js";
4
+ export declare function findBaseEslintFile(workspaceRoot?: string): string | null;
5
+ export declare function isFlatConfig(configFilePath: string): boolean;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isFlatConfig = exports.findBaseEslintFile = exports.baseEsLintFlatConfigFile = exports.baseEsLintConfigFile = exports.ESLINT_CONFIG_FILENAMES = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const fs_1 = require("fs");
6
+ exports.ESLINT_CONFIG_FILENAMES = [
7
+ '.eslintrc',
8
+ '.eslintrc.js',
9
+ '.eslintrc.cjs',
10
+ '.eslintrc.yaml',
11
+ '.eslintrc.yml',
12
+ '.eslintrc.json',
13
+ 'eslint.config.js',
14
+ ];
15
+ exports.baseEsLintConfigFile = '.eslintrc.base.json';
16
+ exports.baseEsLintFlatConfigFile = 'eslint.base.config.js';
17
+ function findBaseEslintFile(workspaceRoot = '') {
18
+ if ((0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(workspaceRoot, exports.baseEsLintConfigFile))) {
19
+ return exports.baseEsLintConfigFile;
20
+ }
21
+ if ((0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(workspaceRoot, exports.baseEsLintFlatConfigFile))) {
22
+ return exports.baseEsLintFlatConfigFile;
23
+ }
24
+ for (const file of exports.ESLINT_CONFIG_FILENAMES) {
25
+ if ((0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(workspaceRoot, file))) {
26
+ return file;
27
+ }
28
+ }
29
+ return null;
30
+ }
31
+ exports.findBaseEslintFile = findBaseEslintFile;
32
+ function isFlatConfig(configFilePath) {
33
+ return configFilePath.endsWith('.config.js');
34
+ }
35
+ exports.isFlatConfig = isFlatConfig;