@nx/eslint 18.0.0-canary.20240202-ea5befb → 18.0.0

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/generators.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "version": "0.1",
4
4
  "generators": {
5
5
  "init": {
6
- "factory": "./src/generators/init/init#lintInitGenerator",
6
+ "factory": "./src/generators/init/init#initEsLint",
7
7
  "schema": "./src/generators/init/schema.json",
8
8
  "description": "Set up the ESLint plugin.",
9
9
  "hidden": true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/eslint",
3
- "version": "18.0.0-canary.20240202-ea5befb",
3
+ "version": "18.0.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": {
@@ -33,12 +33,12 @@
33
33
  "js-yaml": "4.1.0"
34
34
  },
35
35
  "dependencies": {
36
- "@nx/devkit": "18.0.0-canary.20240202-ea5befb",
37
- "@nx/js": "18.0.0-canary.20240202-ea5befb",
36
+ "@nx/devkit": "18.0.0",
37
+ "@nx/js": "18.0.0",
38
38
  "eslint": "^8.0.0",
39
39
  "tslib": "^2.3.0",
40
40
  "typescript": "~5.3.2",
41
- "@nx/linter": "18.0.0-canary.20240202-ea5befb"
41
+ "@nx/linter": "18.0.0"
42
42
  },
43
43
  "peerDependenciesMeta": {
44
44
  "js-yaml": {
@@ -38,7 +38,6 @@ async function resolveAndInstantiateESLint(eslintConfigPath, options, useFlatCon
38
38
  * not be any html files in the project, so keeping it true would break linting every time
39
39
  */
40
40
  errorOnUnmatchedPattern: false,
41
- reportUnusedDisableDirectives: options.reportUnusedDisableDirectives || undefined,
42
41
  };
43
42
  if (useFlatConfig) {
44
43
  if (typeof options.useEslintrc !== 'undefined') {
@@ -50,6 +49,9 @@ async function resolveAndInstantiateESLint(eslintConfigPath, options, useFlatCon
50
49
  if (options.ignorePath !== undefined) {
51
50
  throw new Error('For Flat Config, ESLint removed `ignorePath` and so it is not supported as an option. See https://eslint.org/docs/latest/use/configure/configuration-files-new');
52
51
  }
52
+ if (options.reportUnusedDisableDirectives) {
53
+ throw new Error('For Flat Config, ESLint removed `reportedUnusedDisableDirectives` and so it is not supported as an option. See https://eslint.org/docs/latest/use/configure/configuration-files-new');
54
+ }
53
55
  }
54
56
  else {
55
57
  eslintOptions.rulePaths = options.rulesdir || [];
@@ -61,6 +63,8 @@ async function resolveAndInstantiateESLint(eslintConfigPath, options, useFlatCon
61
63
  * merge the provided config with others it finds automatically.
62
64
  */
63
65
  eslintOptions.useEslintrc = !options.noEslintrc;
66
+ eslintOptions.reportUnusedDisableDirectives =
67
+ options.reportUnusedDisableDirectives || undefined;
64
68
  }
65
69
  const eslint = new ESLint(eslintOptions);
66
70
  return {
@@ -8,6 +8,8 @@ const global_eslint_config_1 = require("./global-eslint-config");
8
8
  const flat_config_1 = require("../../utils/flat-config");
9
9
  const versions_1 = require("../../utils/versions");
10
10
  const ast_utils_1 = require("../utils/flat-config/ast-utils");
11
+ const plugin_1 = require("../utils/plugin");
12
+ const config_file_1 = require("../../utils/config-file");
11
13
  function migrateConfigToMonorepoStyle(projects, tree, unitTestRunner, keepExistingVersions) {
12
14
  const rootEslintConfig = (0, eslint_file_1.findEslintFile)(tree);
13
15
  let skipCleanup = false;
@@ -35,20 +37,32 @@ function migrateConfigToMonorepoStyle(projects, tree, unitTestRunner, keepExisti
35
37
  }
36
38
  // update extends in all projects' eslint configs
37
39
  projects.forEach((project) => {
40
+ let eslintFile;
38
41
  const lintTarget = findLintTarget(project);
39
42
  if (lintTarget) {
40
- const eslintFile = lintTarget.options?.eslintConfig || (0, eslint_file_1.findEslintFile)(tree, project.root);
41
- if (eslintFile) {
42
- const projectEslintPath = (0, devkit_1.joinPathFragments)(project.root, eslintFile);
43
- if (skipCleanup) {
44
- const content = tree.read(projectEslintPath, 'utf-8');
45
- tree.write(projectEslintPath, content.replace(rootEslintConfig, rootEslintConfig.replace('.base.', '.')));
46
- }
47
- else {
48
- migrateEslintFile(projectEslintPath, tree);
43
+ // If target is configured in project.json, read file from target options.
44
+ eslintFile =
45
+ lintTarget.options?.eslintConfig || (0, eslint_file_1.findEslintFile)(tree, project.root);
46
+ }
47
+ else if ((0, plugin_1.hasEslintPlugin)(tree)) {
48
+ // Otherwise, if `@nx/eslint/plugin` is used, match any of the known config files.
49
+ for (const f of config_file_1.ESLINT_CONFIG_FILENAMES) {
50
+ if (tree.exists((0, devkit_1.joinPathFragments)(project.root, f))) {
51
+ eslintFile = f;
52
+ break;
49
53
  }
50
54
  }
51
55
  }
56
+ if (eslintFile) {
57
+ const projectEslintPath = (0, devkit_1.joinPathFragments)(project.root, eslintFile);
58
+ if (skipCleanup) {
59
+ const content = tree.read(projectEslintPath, 'utf-8');
60
+ tree.write(projectEslintPath, content.replace(rootEslintConfig, rootEslintConfig.replace('.base.', '.')));
61
+ }
62
+ else {
63
+ migrateEslintFile(projectEslintPath, tree);
64
+ }
65
+ }
52
66
  });
53
67
  }
54
68
  exports.migrateConfigToMonorepoStyle = migrateConfigToMonorepoStyle;
@@ -3,5 +3,7 @@ export interface LinterInitOptions {
3
3
  skipPackageJson?: boolean;
4
4
  keepExistingVersions?: boolean;
5
5
  updatePackageScripts?: boolean;
6
+ addPlugin?: boolean;
6
7
  }
8
+ export declare function initEsLint(tree: Tree, options: LinterInitOptions): Promise<GeneratorCallback>;
7
9
  export declare function lintInitGenerator(tree: Tree, options: LinterInitOptions): Promise<GeneratorCallback>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lintInitGenerator = void 0;
3
+ exports.lintInitGenerator = exports.initEsLint = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const update_package_scripts_1 = require("@nx/devkit/src/utils/update-package-scripts");
6
6
  const versions_1 = require("../../utils/versions");
@@ -50,10 +50,10 @@ function addPlugin(tree) {
50
50
  (0, devkit_1.updateNxJson)(tree, nxJson);
51
51
  }
52
52
  async function initEsLint(tree, options) {
53
- const addPlugins = process.env.NX_PCV3 === 'true';
53
+ options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
54
54
  const hasPlugin = (0, plugin_2.hasEslintPlugin)(tree);
55
55
  const rootEslintFile = (0, eslint_file_1.findEslintFile)(tree);
56
- if (rootEslintFile && addPlugins && !hasPlugin) {
56
+ if (rootEslintFile && options.addPlugin && !hasPlugin) {
57
57
  addPlugin(tree);
58
58
  if (options.updatePackageScripts) {
59
59
  await (0, update_package_scripts_1.updatePackageScripts)(tree, plugin_1.createNodes);
@@ -64,7 +64,7 @@ async function initEsLint(tree, options) {
64
64
  return () => { };
65
65
  }
66
66
  updateProductionFileset(tree);
67
- if (addPlugins) {
67
+ if (options.addPlugin) {
68
68
  addPlugin(tree);
69
69
  }
70
70
  else {
@@ -83,7 +83,8 @@ async function initEsLint(tree, options) {
83
83
  }
84
84
  return (0, devkit_1.runTasksInSerial)(...tasks);
85
85
  }
86
+ exports.initEsLint = initEsLint;
86
87
  async function lintInitGenerator(tree, options) {
87
- return await initEsLint(tree, options);
88
+ return await initEsLint(tree, { addPlugin: false, ...options });
88
89
  }
89
90
  exports.lintInitGenerator = lintInitGenerator;
@@ -11,6 +11,8 @@ interface LintProjectOptions {
11
11
  unitTestRunner?: string;
12
12
  rootProject?: boolean;
13
13
  keepExistingVersions?: boolean;
14
+ addPlugin?: boolean;
14
15
  }
15
16
  export declare function lintProjectGenerator(tree: Tree, options: LintProjectOptions): Promise<GeneratorCallback>;
17
+ export declare function lintProjectGeneratorInternal(tree: Tree, options: LintProjectOptions): Promise<GeneratorCallback>;
16
18
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lintProjectGenerator = void 0;
3
+ exports.lintProjectGeneratorInternal = 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");
@@ -12,10 +12,16 @@ const ast_utils_1 = require("../utils/flat-config/ast-utils");
12
12
  const config_file_1 = require("../../utils/config-file");
13
13
  const plugin_1 = require("../utils/plugin");
14
14
  const setup_root_eslint_1 = require("./setup-root-eslint");
15
- async function lintProjectGenerator(tree, options) {
15
+ function lintProjectGenerator(tree, options) {
16
+ return lintProjectGeneratorInternal(tree, { addPlugin: false, ...options });
17
+ }
18
+ exports.lintProjectGenerator = lintProjectGenerator;
19
+ async function lintProjectGeneratorInternal(tree, options) {
20
+ options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
16
21
  const tasks = [];
17
22
  const initTask = await (0, init_1.lintInitGenerator)(tree, {
18
23
  skipPackageJson: options.skipPackageJson,
24
+ addPlugin: options.addPlugin,
19
25
  });
20
26
  tasks.push(initTask);
21
27
  const rootEsLintTask = (0, setup_root_eslint_1.setupRootEsLint)(tree, {
@@ -97,7 +103,7 @@ async function lintProjectGenerator(tree, options) {
97
103
  }
98
104
  return (0, devkit_1.runTasksInSerial)(...tasks);
99
105
  }
100
- exports.lintProjectGenerator = lintProjectGenerator;
106
+ exports.lintProjectGeneratorInternal = lintProjectGeneratorInternal;
101
107
  function createEsLintConfiguration(tree, projectConfig, setParserOptionsProject, rootProject) {
102
108
  // we are only extending root for non-standalone projects or their complementary e2e apps
103
109
  const extendedRootConfig = rootProject ? undefined : (0, eslint_file_1.findEslintFile)(tree);
@@ -204,10 +210,15 @@ function isMigrationToMonorepoNeeded(projects, tree) {
204
210
  if (!rootProject || !rootProject.targets) {
205
211
  return false;
206
212
  }
213
+ // check if we're inferring lint target from `@nx/eslint/plugin`
214
+ if ((0, plugin_1.hasEslintPlugin)(tree)) {
215
+ for (const f of config_file_1.ESLINT_CONFIG_FILENAMES) {
216
+ if (tree.exists(f)) {
217
+ return true;
218
+ }
219
+ }
220
+ }
207
221
  // find if root project has lint target
208
222
  const lintTarget = (0, init_migration_1.findLintTarget)(rootProject);
209
- if (!lintTarget) {
210
- return false;
211
- }
212
- return true;
223
+ return !!lintTarget;
213
224
  }
@@ -9,7 +9,7 @@ const workspace_lint_rules_1 = require("../../utils/workspace-lint-rules");
9
9
  const workspace_rules_project_1 = require("../workspace-rules-project/workspace-rules-project");
10
10
  async function lintWorkspaceRuleGenerator(tree, options) {
11
11
  // Ensure that the workspace rules project has been created
12
- const projectGeneratorCallback = await (0, workspace_rules_project_1.lintWorkspaceRulesProjectGenerator)(tree, { skipFormat: true });
12
+ const projectGeneratorCallback = await (0, workspace_rules_project_1.lintWorkspaceRulesProjectGenerator)(tree, { skipFormat: true, addPlugin: process.env.NX_ADD_PLUGINS !== 'false' });
13
13
  const ruleDir = (0, devkit_1.joinPathFragments)(workspace_lint_rules_1.workspaceLintPluginDir, options.directory ?? '');
14
14
  // Generate the required files for the new rule
15
15
  (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files'), ruleDir, {
@@ -3,5 +3,6 @@ export declare const WORKSPACE_RULES_PROJECT_NAME = "eslint-rules";
3
3
  export declare const WORKSPACE_PLUGIN_DIR = "tools/eslint-rules";
4
4
  export interface LintWorkspaceRulesProjectGeneratorOptions {
5
5
  skipFormat?: boolean;
6
+ addPlugin?: boolean;
6
7
  }
7
8
  export declare function lintWorkspaceRulesProjectGenerator(tree: Tree, options?: LintWorkspaceRulesProjectGeneratorOptions): Promise<GeneratorCallback>;
@@ -41,6 +41,7 @@ async function lintWorkspaceRulesProjectGenerator(tree, options = {}) {
41
41
  }
42
42
  // Add jest to the project and return installation task
43
43
  tasks.push(await configurationGenerator(tree, {
44
+ ...options,
44
45
  project: exports.WORKSPACE_RULES_PROJECT_NAME,
45
46
  supportTsx: false,
46
47
  skipSerializers: true,