@nx/eslint 19.5.0-canary.20240705-653cad2 → 19.5.0-canary.20240709-92e09d9

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.5.0-canary.20240705-653cad2",
3
+ "version": "19.5.0-canary.20240709-92e09d9",
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.5.0-canary.20240705-653cad2",
39
- "@nx/js": "19.5.0-canary.20240705-653cad2",
38
+ "@nx/devkit": "19.5.0-canary.20240709-92e09d9",
39
+ "@nx/js": "19.5.0-canary.20240709-92e09d9",
40
40
  "semver": "^7.5.3",
41
41
  "tslib": "^2.3.0",
42
42
  "typescript": "~5.4.2",
43
- "@nx/linter": "19.5.0-canary.20240705-653cad2"
43
+ "@nx/linter": "19.5.0-canary.20240709-92e09d9"
44
44
  },
45
45
  "peerDependenciesMeta": {
46
46
  "@zkochan/js-yaml": {
@@ -5,7 +5,9 @@ const config_file_1 = require("../../../utils/config-file");
5
5
  const resolve_eslint_class_1 = require("../../../utils/resolve-eslint-class");
6
6
  async function resolveAndInstantiateESLint(eslintConfigPath, options, useFlatConfig = false) {
7
7
  if (useFlatConfig && eslintConfigPath && !(0, config_file_1.isFlatConfig)(eslintConfigPath)) {
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');
8
+ throw new Error(
9
+ // todo: add support for eslint.config.mjs,
10
+ 'When using the new Flat Config with ESLint, all configs must be named eslint.config.js or eslint.config.cjs and .eslintrc files may not be used. See https://eslint.org/docs/latest/use/configure/configuration-files');
9
11
  }
10
12
  const ESLint = await (0, resolve_eslint_class_1.resolveESLintClass)(useFlatConfig);
11
13
  const eslintOptions = {
@@ -103,7 +103,7 @@ function addOverrideToLintConfig(tree, root, override, options = {
103
103
  }) {
104
104
  const isBase = options.checkBaseConfig && findEslintFile(tree, root).includes('.base');
105
105
  if ((0, flat_config_1.useFlatConfig)(tree)) {
106
- const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? config_file_1.baseEsLintFlatConfigFile : 'eslint.config.js');
106
+ const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? config_file_1.baseEsLintFlatConfigFile : (0, flat_config_1.flatConfigEslintFilename)(tree));
107
107
  const flatOverride = (0, ast_utils_1.generateFlatOverride)(override);
108
108
  let content = tree.read(fileName, 'utf8');
109
109
  // we will be using compat here so we need to make sure it's added
@@ -132,7 +132,7 @@ function overrideNeedsCompat(override) {
132
132
  }
133
133
  function updateOverrideInLintConfig(tree, root, lookup, update) {
134
134
  if ((0, flat_config_1.useFlatConfig)(tree)) {
135
- const fileName = (0, devkit_1.joinPathFragments)(root, 'eslint.config.js');
135
+ const fileName = (0, devkit_1.joinPathFragments)(root, (0, flat_config_1.flatConfigEslintFilename)(tree));
136
136
  let content = tree.read(fileName, 'utf8');
137
137
  content = (0, ast_utils_1.replaceOverride)(content, root, lookup, update);
138
138
  tree.write(fileName, content);
@@ -168,7 +168,7 @@ function lintConfigHasOverride(tree, root, lookup, checkBaseConfig = false) {
168
168
  }
169
169
  const isBase = checkBaseConfig && findEslintFile(tree, root).includes('.base');
170
170
  if ((0, flat_config_1.useFlatConfig)(tree)) {
171
- const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? config_file_1.baseEsLintFlatConfigFile : 'eslint.config.js');
171
+ const fileName = (0, devkit_1.joinPathFragments)(root, isBase ? config_file_1.baseEsLintFlatConfigFile : (0, flat_config_1.flatConfigEslintFilename)(tree));
172
172
  const content = tree.read(fileName, 'utf8');
173
173
  return (0, ast_utils_1.hasOverride)(content, lookup);
174
174
  }
@@ -180,7 +180,7 @@ function lintConfigHasOverride(tree, root, lookup, checkBaseConfig = false) {
180
180
  exports.lintConfigHasOverride = lintConfigHasOverride;
181
181
  function replaceOverridesInLintConfig(tree, root, overrides) {
182
182
  if ((0, flat_config_1.useFlatConfig)(tree)) {
183
- const fileName = (0, devkit_1.joinPathFragments)(root, 'eslint.config.js');
183
+ const fileName = (0, devkit_1.joinPathFragments)(root, (0, flat_config_1.flatConfigEslintFilename)(tree));
184
184
  let content = tree.read(fileName, 'utf8');
185
185
  // we will be using compat here so we need to make sure it's added
186
186
  if (overrides.some(overrideNeedsCompat)) {
@@ -205,7 +205,7 @@ exports.replaceOverridesInLintConfig = replaceOverridesInLintConfig;
205
205
  function addExtendsToLintConfig(tree, root, plugin) {
206
206
  const plugins = Array.isArray(plugin) ? plugin : [plugin];
207
207
  if ((0, flat_config_1.useFlatConfig)(tree)) {
208
- const fileName = (0, devkit_1.joinPathFragments)(root, 'eslint.config.js');
208
+ const fileName = (0, devkit_1.joinPathFragments)(root, (0, flat_config_1.flatConfigEslintFilename)(tree));
209
209
  const pluginExtends = (0, ast_utils_1.generatePluginExtendsElement)(plugins);
210
210
  let content = tree.read(fileName, 'utf8');
211
211
  content = (0, ast_utils_1.addCompatToFlatConfig)(content);
@@ -229,7 +229,7 @@ exports.addExtendsToLintConfig = addExtendsToLintConfig;
229
229
  function addPluginsToLintConfig(tree, root, plugin) {
230
230
  const plugins = Array.isArray(plugin) ? plugin : [plugin];
231
231
  if ((0, flat_config_1.useFlatConfig)(tree)) {
232
- const fileName = (0, devkit_1.joinPathFragments)(root, 'eslint.config.js');
232
+ const fileName = (0, devkit_1.joinPathFragments)(root, (0, flat_config_1.flatConfigEslintFilename)(tree));
233
233
  let content = tree.read(fileName, 'utf8');
234
234
  const mappedPlugins = [];
235
235
  plugins.forEach((name) => {
@@ -254,7 +254,7 @@ function addPluginsToLintConfig(tree, root, plugin) {
254
254
  exports.addPluginsToLintConfig = addPluginsToLintConfig;
255
255
  function addIgnoresToLintConfig(tree, root, ignorePatterns) {
256
256
  if ((0, flat_config_1.useFlatConfig)(tree)) {
257
- const fileName = (0, devkit_1.joinPathFragments)(root, 'eslint.config.js');
257
+ const fileName = (0, devkit_1.joinPathFragments)(root, (0, flat_config_1.flatConfigEslintFilename)(tree));
258
258
  const block = (0, ast_utils_1.generateAst)({
259
259
  ignores: ignorePatterns.map((path) => (0, path_utils_1.mapFilePath)(path)),
260
260
  });
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
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
4
  const fs_1 = require("fs");
5
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'];
6
+ const flat_config_1 = require("./flat-config");
7
+ exports.ESLINT_FLAT_CONFIG_FILENAMES = flat_config_1.eslintFlatConfigFilenames;
8
8
  exports.ESLINT_OLD_CONFIG_FILENAMES = [
9
9
  '.eslintrc',
10
10
  '.eslintrc.js',
@@ -30,6 +30,7 @@ function findFlatConfigFile(directory, workspaceRoot) {
30
30
  while (true) {
31
31
  const configFilePath = getConfigFileInDirectory(currentDir, exports.ESLINT_FLAT_CONFIG_FILENAMES);
32
32
  if (configFilePath) {
33
+ console.log(`Found eslint flat config file at: ${configFilePath}`);
33
34
  return configFilePath;
34
35
  }
35
36
  if (currentDir === workspaceRoot) {
@@ -1,2 +1,4 @@
1
1
  import { Tree } from '@nx/devkit';
2
+ export declare const eslintFlatConfigFilenames: string[];
3
+ export declare function flatConfigEslintFilename(tree: Tree): string;
2
4
  export declare function useFlatConfig(tree: Tree): boolean;
@@ -1,7 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useFlatConfig = void 0;
3
+ exports.useFlatConfig = exports.flatConfigEslintFilename = exports.eslintFlatConfigFilenames = void 0;
4
+ // todo: add support for eslint.config.mjs,
5
+ exports.eslintFlatConfigFilenames = [
6
+ 'eslint.config.js',
7
+ 'eslint.config.cjs',
8
+ ];
9
+ function flatConfigEslintFilename(tree) {
10
+ for (const file of exports.eslintFlatConfigFilenames) {
11
+ if (tree.exists(file)) {
12
+ return file;
13
+ }
14
+ }
15
+ throw new Error('Could not find flat config file');
16
+ }
17
+ exports.flatConfigEslintFilename = flatConfigEslintFilename;
4
18
  function useFlatConfig(tree) {
5
- return tree.exists('eslint.config.js');
19
+ try {
20
+ return !!flatConfigEslintFilename(tree);
21
+ }
22
+ catch {
23
+ return false;
24
+ }
6
25
  }
7
26
  exports.useFlatConfig = useFlatConfig;