@nx/eslint 19.2.0-rc.0 → 19.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/eslint",
3
- "version": "19.2.0-rc.0",
3
+ "version": "19.2.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,12 +35,12 @@
35
35
  "eslint": "^8.0.0 || ^9.0.0"
36
36
  },
37
37
  "dependencies": {
38
- "@nx/devkit": "19.2.0-rc.0",
39
- "@nx/js": "19.2.0-rc.0",
38
+ "@nx/devkit": "19.2.0",
39
+ "@nx/js": "19.2.0",
40
40
  "semver": "^7.5.3",
41
41
  "tslib": "^2.3.0",
42
42
  "typescript": "~5.4.2",
43
- "@nx/linter": "19.2.0-rc.0"
43
+ "@nx/linter": "19.2.0"
44
44
  },
45
45
  "peerDependenciesMeta": {
46
46
  "@zkochan/js-yaml": {
@@ -1,4 +1,4 @@
1
- import { ExecutorContext } from '@nx/devkit';
1
+ import { type ExecutorContext } from '@nx/devkit';
2
2
  import type { Schema } from './schema';
3
3
  export default function run(options: Schema, context: ExecutorContext): Promise<{
4
4
  success: boolean;
@@ -2,9 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const devkit_1 = require("@nx/devkit");
4
4
  const fs_1 = require("fs");
5
+ const utils_1 = require("nx/src/tasks-runner/utils");
5
6
  const path_1 = require("path");
7
+ const config_file_1 = require("../../utils/config-file");
6
8
  const eslint_utils_1 = require("./utility/eslint-utils");
7
- const utils_1 = require("nx/src/tasks-runner/utils");
8
9
  async function run(options, context) {
9
10
  // this is only used for the hasher
10
11
  delete options.hasTypeAwareRules;
@@ -23,19 +24,14 @@ async function run(options, context) {
23
24
  ? (0, devkit_1.joinPathFragments)(options.cacheLocation, projectName)
24
25
  : undefined;
25
26
  const { printConfig, errorOnUnmatchedPattern, ...normalizedOptions } = options;
26
- /**
27
- * Until ESLint v9 is released and the new so called flat config is the default
28
- * we only want to support it if the user has explicitly opted into it by converting
29
- * their root ESLint config to use eslint.config.js
30
- */
31
- const hasFlatConfig = (0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, 'eslint.config.js'));
27
+ // locate the flat config file if it exists starting from the project root
28
+ const flatConfigFilePath = (0, config_file_1.findFlatConfigFile)(projectRoot, context.root);
29
+ const hasFlatConfig = flatConfigFilePath !== null;
32
30
  // while standard eslint uses by default closest config to the file, if otherwise not specified,
33
- // the flat config would always use the root config, so we need to explicitly set it to the local one
31
+ // the flat config would be resolved starting from the cwd, which we changed to the workspace root
32
+ // so we explicitly set the config path to the flat config file path we previously found
34
33
  if (hasFlatConfig && !normalizedOptions.eslintConfig) {
35
- const eslintConfigPath = (0, devkit_1.joinPathFragments)(projectRoot, 'eslint.config.js');
36
- if ((0, fs_1.existsSync)(eslintConfigPath)) {
37
- normalizedOptions.eslintConfig = eslintConfigPath;
38
- }
34
+ normalizedOptions.eslintConfig = path_1.posix.relative(systemRoot, flatConfigFilePath);
39
35
  }
40
36
  /**
41
37
  * We want users to have the option of not specifying the config path, and let
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveAndInstantiateESLint = void 0;
4
+ const config_file_1 = require("../../../utils/config-file");
4
5
  const resolve_eslint_class_1 = require("../../../utils/resolve-eslint-class");
5
6
  async function resolveAndInstantiateESLint(eslintConfigPath, options, useFlatConfig = false) {
6
- if (useFlatConfig &&
7
- eslintConfigPath &&
8
- !eslintConfigPath?.endsWith('eslint.config.js')) {
7
+ if (useFlatConfig && eslintConfigPath && !(0, config_file_1.isFlatConfig)(eslintConfigPath)) {
9
8
  throw new Error('When using the new Flat Config with ESLint, all configs must be named eslint.config.js and .eslintrc files may not be used. See https://eslint.org/docs/latest/use/configure/configuration-files-new');
10
9
  }
11
10
  const ESLint = await (0, resolve_eslint_class_1.resolveESLintClass)(useFlatConfig);
@@ -1,4 +1,8 @@
1
+ export declare const ESLINT_FLAT_CONFIG_FILENAMES: string[];
2
+ export declare const ESLINT_OLD_CONFIG_FILENAMES: string[];
1
3
  export declare const ESLINT_CONFIG_FILENAMES: string[];
2
4
  export declare const baseEsLintConfigFile = ".eslintrc.base.json";
3
5
  export declare const baseEsLintFlatConfigFile = "eslint.base.config.js";
4
6
  export declare function isFlatConfig(configFilePath: string): boolean;
7
+ export declare function findFlatConfigFile(directory: string, workspaceRoot: string): string | null;
8
+ export declare function findOldConfigFile(filePathOrDirectory: string, workspaceRoot: string): string | null;
@@ -1,18 +1,68 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFlatConfig = exports.baseEsLintFlatConfigFile = exports.baseEsLintConfigFile = exports.ESLINT_CONFIG_FILENAMES = void 0;
4
- exports.ESLINT_CONFIG_FILENAMES = [
3
+ exports.findOldConfigFile = exports.findFlatConfigFile = exports.isFlatConfig = exports.baseEsLintFlatConfigFile = exports.baseEsLintConfigFile = exports.ESLINT_CONFIG_FILENAMES = exports.ESLINT_OLD_CONFIG_FILENAMES = exports.ESLINT_FLAT_CONFIG_FILENAMES = void 0;
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ // TODO(leo): add support for eslint.config.mjs and eslint.config.cjs
7
+ exports.ESLINT_FLAT_CONFIG_FILENAMES = ['eslint.config.js'];
8
+ exports.ESLINT_OLD_CONFIG_FILENAMES = [
5
9
  '.eslintrc',
6
10
  '.eslintrc.js',
7
11
  '.eslintrc.cjs',
8
12
  '.eslintrc.yaml',
9
13
  '.eslintrc.yml',
10
14
  '.eslintrc.json',
11
- 'eslint.config.js',
15
+ ];
16
+ exports.ESLINT_CONFIG_FILENAMES = [
17
+ ...exports.ESLINT_OLD_CONFIG_FILENAMES,
18
+ ...exports.ESLINT_FLAT_CONFIG_FILENAMES,
12
19
  ];
13
20
  exports.baseEsLintConfigFile = '.eslintrc.base.json';
14
21
  exports.baseEsLintFlatConfigFile = 'eslint.base.config.js';
15
22
  function isFlatConfig(configFilePath) {
16
- return configFilePath.endsWith('.config.js');
23
+ const configFileName = (0, path_1.basename)(configFilePath);
24
+ return exports.ESLINT_FLAT_CONFIG_FILENAMES.includes(configFileName);
17
25
  }
18
26
  exports.isFlatConfig = isFlatConfig;
27
+ // https://eslint.org/docs/latest/use/configure/configuration-files#configuration-file-resolution
28
+ function findFlatConfigFile(directory, workspaceRoot) {
29
+ let currentDir = (0, path_1.resolve)(workspaceRoot, directory);
30
+ if (currentDir === workspaceRoot) {
31
+ return getConfigFileInDirectory(currentDir, exports.ESLINT_FLAT_CONFIG_FILENAMES);
32
+ }
33
+ while (currentDir !== workspaceRoot) {
34
+ const configFilePath = getConfigFileInDirectory(currentDir, exports.ESLINT_FLAT_CONFIG_FILENAMES);
35
+ if (configFilePath) {
36
+ return configFilePath;
37
+ }
38
+ currentDir = (0, path_1.dirname)(currentDir);
39
+ }
40
+ return null;
41
+ }
42
+ exports.findFlatConfigFile = findFlatConfigFile;
43
+ function findOldConfigFile(filePathOrDirectory, workspaceRoot) {
44
+ let currentDir = (0, fs_1.statSync)(filePathOrDirectory).isDirectory()
45
+ ? filePathOrDirectory
46
+ : (0, path_1.dirname)(filePathOrDirectory);
47
+ if (currentDir === workspaceRoot) {
48
+ return getConfigFileInDirectory(currentDir, exports.ESLINT_OLD_CONFIG_FILENAMES);
49
+ }
50
+ while (currentDir !== workspaceRoot) {
51
+ const configFilePath = getConfigFileInDirectory(currentDir, exports.ESLINT_OLD_CONFIG_FILENAMES);
52
+ if (configFilePath) {
53
+ return configFilePath;
54
+ }
55
+ currentDir = (0, path_1.dirname)(currentDir);
56
+ }
57
+ return null;
58
+ }
59
+ exports.findOldConfigFile = findOldConfigFile;
60
+ function getConfigFileInDirectory(directory, candidateFileNames) {
61
+ for (const filename of candidateFileNames) {
62
+ const filePath = (0, path_1.join)(directory, filename);
63
+ if ((0, fs_1.existsSync)(filePath)) {
64
+ return filePath;
65
+ }
66
+ }
67
+ return null;
68
+ }