@nx/eslint 0.0.0-pr-31222-862e973 → 0.0.0-pr-31313-387cdca

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.
Files changed (55) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/migrations.json +69 -112
  4. package/package.json +6 -7
  5. package/src/executors/lint/utility/eslint-utils.js +6 -0
  6. package/src/generators/convert-to-flat-config/converters/json-converter.d.ts +1 -1
  7. package/src/generators/convert-to-flat-config/converters/json-converter.js +10 -18
  8. package/src/generators/convert-to-flat-config/generator.js +18 -17
  9. package/src/generators/convert-to-flat-config/schema.d.ts +2 -0
  10. package/src/generators/convert-to-inferred/convert-to-inferred.js +2 -1
  11. package/src/generators/init/global-eslint-config.d.ts +1 -1
  12. package/src/generators/init/global-eslint-config.js +17 -6
  13. package/src/generators/init/init-migration.d.ts +1 -1
  14. package/src/generators/init/init-migration.js +18 -13
  15. package/src/generators/init/init.d.ts +1 -0
  16. package/src/generators/init/init.js +31 -6
  17. package/src/generators/lint-project/lint-project.d.ts +1 -0
  18. package/src/generators/lint-project/lint-project.js +37 -15
  19. package/src/generators/lint-project/setup-root-eslint.d.ts +1 -0
  20. package/src/generators/lint-project/setup-root-eslint.js +2 -1
  21. package/src/generators/utils/eslint-file.d.ts +3 -2
  22. package/src/generators/utils/eslint-file.js +160 -28
  23. package/src/generators/utils/flat-config/ast-utils.d.ts +12 -4
  24. package/src/generators/utils/flat-config/ast-utils.js +412 -63
  25. package/src/generators/utils/linter.d.ts +3 -0
  26. package/src/generators/utils/linter.js +2 -2
  27. package/src/generators/workspace-rule/files/__name__.spec.ts__tmpl__ +11 -2
  28. package/src/generators/workspace-rule/workspace-rule.d.ts +2 -2
  29. package/src/generators/workspace-rule/workspace-rule.js +11 -3
  30. package/src/generators/workspace-rules-project/workspace-rules-project.js +4 -1
  31. package/src/migrations/update-20-2-0/update-typescript-eslint-v8-13-0.d.ts +2 -0
  32. package/src/migrations/update-20-2-0/update-typescript-eslint-v8-13-0.js +23 -0
  33. package/src/migrations/update-20-3-0/add-file-extensions-to-overrides.d.ts +2 -0
  34. package/src/migrations/update-20-3-0/add-file-extensions-to-overrides.js +49 -0
  35. package/src/plugins/plugin.js +21 -10
  36. package/src/utils/config-file.d.ts +3 -1
  37. package/src/utils/config-file.js +5 -2
  38. package/src/utils/flat-config.d.ts +1 -0
  39. package/src/utils/flat-config.js +9 -3
  40. package/src/utils/version-utils.d.ts +1 -0
  41. package/src/utils/version-utils.js +13 -9
  42. package/src/utils/versions.d.ts +3 -2
  43. package/src/utils/versions.js +4 -3
  44. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +0 -2
  45. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +0 -9
  46. package/src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files.d.ts +0 -2
  47. package/src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files.js +0 -44
  48. package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.d.ts +0 -2
  49. package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.js +0 -47
  50. package/src/migrations/update-17-1-0/update-typescript-eslint.d.ts +0 -2
  51. package/src/migrations/update-17-1-0/update-typescript-eslint.js +0 -74
  52. package/src/migrations/update-17-2-0/simplify-eslint-patterns.d.ts +0 -2
  53. package/src/migrations/update-17-2-0/simplify-eslint-patterns.js +0 -46
  54. package/src/migrations/update-17-2-9/move-options-to-target-defaults.d.ts +0 -2
  55. package/src/migrations/update-17-2-9/move-options-to-target-defaults.js +0 -107
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = update;
4
- const devkit_1 = require("@nx/devkit");
5
- async function update(tree) {
6
- const projects = (0, devkit_1.getProjects)(tree);
7
- for (const [projectName, projectConfiguration] of projects) {
8
- let needsUpdate = false;
9
- for (const [targetName, targetConfig] of Object.entries(projectConfiguration.targets ?? {})) {
10
- if (targetConfig.executor !== '@nx/eslint:lint') {
11
- continue;
12
- }
13
- needsUpdate = true;
14
- if (projectConfiguration.targets[targetName].options?.lintFilePatterns) {
15
- const rootPattern = getLintRoot(projectConfiguration);
16
- const nonRootPatterns = projectConfiguration.targets[targetName].options.lintFilePatterns.filter((p) => !p.startsWith(rootPattern) && !p.startsWith('{projectRoot}'));
17
- if (nonRootPatterns.length === 0 &&
18
- rootPattern === projectConfiguration.root) {
19
- // delete the lintFilePatterns option if it's the only option and matches the root of the project
20
- delete projectConfiguration.targets[targetName].options
21
- .lintFilePatterns;
22
- if (Object.keys(projectConfiguration.targets[targetName].options)
23
- .length === 0) {
24
- delete projectConfiguration.targets[targetName].options;
25
- }
26
- }
27
- else {
28
- projectConfiguration.targets[targetName].options.lintFilePatterns = [
29
- rootPattern,
30
- ...nonRootPatterns,
31
- ];
32
- }
33
- }
34
- }
35
- if (needsUpdate) {
36
- (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
37
- }
38
- }
39
- await (0, devkit_1.formatFiles)(tree);
40
- }
41
- function getLintRoot({ root, sourceRoot }) {
42
- if (root === '' || root === '.') {
43
- return sourceRoot || './src';
44
- }
45
- return root;
46
- }
@@ -1,2 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export default function update(tree: Tree): Promise<void>;
@@ -1,107 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = update;
4
- const devkit_1 = require("@nx/devkit");
5
- const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
6
- const eslint_file_1 = require("../../generators/utils/eslint-file");
7
- const project_configuration_utils_1 = require("nx/src/project-graph/utils/project-configuration-utils");
8
- async function update(tree) {
9
- const nxJson = (0, devkit_1.readNxJson)(tree);
10
- // Don't override anything if there are already target defaults for eslint
11
- if (nxJson.targetDefaults?.['@nx/eslint:lint']) {
12
- return;
13
- }
14
- nxJson.targetDefaults ??= {};
15
- const graph = await (0, devkit_1.createProjectGraphAsync)();
16
- const lintTargets = new Set();
17
- (0, executor_options_utils_1.forEachExecutorOptionsInGraph)(graph, '@nx/eslint:lint', (value, proj, targetName) => {
18
- lintTargets.add(targetName);
19
- });
20
- // Workspace does not use eslint?
21
- if (lintTargets.size === 0) {
22
- return;
23
- }
24
- const lintDefaults = (nxJson.targetDefaults['@nx/eslint:lint'] = {});
25
- // All eslint targets have the same name
26
- if (lintTargets.size === 1) {
27
- const targetName = Array.from(lintTargets)[0];
28
- if (nxJson.targetDefaults[targetName]) {
29
- Object.assign(lintDefaults, nxJson.targetDefaults[targetName]);
30
- }
31
- }
32
- lintDefaults.cache ??= true;
33
- if (!lintDefaults.inputs) {
34
- const eslintConfig = (0, eslint_file_1.findEslintFile)(tree);
35
- lintDefaults.inputs = [
36
- 'default',
37
- ...(eslintConfig ? [`{workspaceRoot}/${eslintConfig}`] : []),
38
- '{workspaceRoot}/tools/eslint-rules/**/*',
39
- ];
40
- }
41
- // Cleanup old target defaults
42
- const projects = graph.nodes;
43
- const projectMap = (0, devkit_1.getProjects)(tree);
44
- for (const [targetDefaultKey, targetDefault] of Object.entries(nxJson.targetDefaults)) {
45
- if (!isTargetDefaultUsed(targetDefault, nxJson.targetDefaults, projects, projectMap)) {
46
- delete nxJson.targetDefaults[targetDefaultKey];
47
- }
48
- }
49
- let addOutputs = false;
50
- (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/eslint:lint', (options, proj, targetName, configuration) => {
51
- const projConfig = projectMap.get(proj);
52
- // modify lint file patterns
53
- if (options.lintFilePatterns) {
54
- const projectRootRegex = new RegExp(`^${projConfig.root}/`);
55
- projConfig.targets[targetName].options.lintFilePatterns =
56
- options.lintFilePatterns
57
- .filter((filePattern) => filePattern !== '{projectRoot}' &&
58
- filePattern !== projConfig.root)
59
- .map((filePattern) => filePattern.replace(projectRootRegex, '{projectRoot}/'));
60
- // remove lintFilePatterns if empty
61
- if (projConfig.targets[targetName].options.lintFilePatterns.length === 0) {
62
- delete projConfig.targets[targetName].options.lintFilePatterns;
63
- }
64
- }
65
- // remove inputs if they are not bringing any new inputs
66
- if (projConfig.targets[targetName].inputs &&
67
- projConfig.targets[targetName].inputs.every((i) => lintDefaults.inputs.includes(i))) {
68
- delete projConfig.targets[targetName].inputs;
69
- }
70
- // remove obsolete eslint config definition, unless it's a custom one
71
- const projectEslintConfig = (0, eslint_file_1.findEslintFile)(tree, projConfig.root);
72
- if (options.eslintConfig === `${projConfig.root}/${projectEslintConfig}` ||
73
- options.eslintConfig === `{projectRoot}/${projectEslintConfig}`) {
74
- delete projConfig.targets[targetName].options.eslintConfig;
75
- }
76
- // remove options if empty
77
- if (Object.keys(projConfig.targets[targetName]?.options ?? {}).length === 0) {
78
- delete projConfig.targets[targetName].options;
79
- }
80
- // track output
81
- if (options.outputFile) {
82
- addOutputs = true;
83
- }
84
- if (projConfig.targets[targetName].outputs?.length === 1 &&
85
- projConfig.targets[targetName].outputs[0] === '{options.outputFile}') {
86
- delete projConfig.targets[targetName].outputs;
87
- }
88
- (0, devkit_1.updateProjectConfiguration)(tree, proj, projConfig);
89
- });
90
- if (addOutputs) {
91
- lintDefaults.outputs = ['{options.outputFile}'];
92
- }
93
- (0, devkit_1.updateNxJson)(tree, nxJson);
94
- await (0, devkit_1.formatFiles)(tree);
95
- }
96
- function isTargetDefaultUsed(targetDefault, targetDefaults, projects, projectMap) {
97
- for (const p of Object.values(projects)) {
98
- for (const targetName in p.data?.targets ?? {}) {
99
- if ((0, project_configuration_utils_1.readTargetDefaultsForTarget)(targetName, targetDefaults,
100
- // It might seem like we should use the graph here too but we don't want to pass an executor which was processed in the graph
101
- projectMap.get(p.name)?.targets?.[targetName]?.executor) === targetDefault) {
102
- return true;
103
- }
104
- }
105
- }
106
- return false;
107
- }