@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.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/migrations.json +69 -112
- package/package.json +6 -7
- package/src/executors/lint/utility/eslint-utils.js +6 -0
- package/src/generators/convert-to-flat-config/converters/json-converter.d.ts +1 -1
- package/src/generators/convert-to-flat-config/converters/json-converter.js +10 -18
- package/src/generators/convert-to-flat-config/generator.js +18 -17
- package/src/generators/convert-to-flat-config/schema.d.ts +2 -0
- package/src/generators/convert-to-inferred/convert-to-inferred.js +2 -1
- package/src/generators/init/global-eslint-config.d.ts +1 -1
- package/src/generators/init/global-eslint-config.js +17 -6
- package/src/generators/init/init-migration.d.ts +1 -1
- package/src/generators/init/init-migration.js +18 -13
- package/src/generators/init/init.d.ts +1 -0
- package/src/generators/init/init.js +31 -6
- package/src/generators/lint-project/lint-project.d.ts +1 -0
- package/src/generators/lint-project/lint-project.js +37 -15
- package/src/generators/lint-project/setup-root-eslint.d.ts +1 -0
- package/src/generators/lint-project/setup-root-eslint.js +2 -1
- package/src/generators/utils/eslint-file.d.ts +3 -2
- package/src/generators/utils/eslint-file.js +160 -28
- package/src/generators/utils/flat-config/ast-utils.d.ts +12 -4
- package/src/generators/utils/flat-config/ast-utils.js +412 -63
- package/src/generators/utils/linter.d.ts +3 -0
- package/src/generators/utils/linter.js +2 -2
- package/src/generators/workspace-rule/files/__name__.spec.ts__tmpl__ +11 -2
- package/src/generators/workspace-rule/workspace-rule.d.ts +2 -2
- package/src/generators/workspace-rule/workspace-rule.js +11 -3
- package/src/generators/workspace-rules-project/workspace-rules-project.js +4 -1
- package/src/migrations/update-20-2-0/update-typescript-eslint-v8-13-0.d.ts +2 -0
- package/src/migrations/update-20-2-0/update-typescript-eslint-v8-13-0.js +23 -0
- package/src/migrations/update-20-3-0/add-file-extensions-to-overrides.d.ts +2 -0
- package/src/migrations/update-20-3-0/add-file-extensions-to-overrides.js +49 -0
- package/src/plugins/plugin.js +21 -10
- package/src/utils/config-file.d.ts +3 -1
- package/src/utils/config-file.js +5 -2
- package/src/utils/flat-config.d.ts +1 -0
- package/src/utils/flat-config.js +9 -3
- package/src/utils/version-utils.d.ts +1 -0
- package/src/utils/version-utils.js +13 -9
- package/src/utils/versions.d.ts +3 -2
- package/src/utils/versions.js +4 -3
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +0 -2
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +0 -9
- package/src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files.d.ts +0 -2
- package/src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files.js +0 -44
- package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.d.ts +0 -2
- package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.js +0 -47
- package/src/migrations/update-17-1-0/update-typescript-eslint.d.ts +0 -2
- package/src/migrations/update-17-1-0/update-typescript-eslint.js +0 -74
- package/src/migrations/update-17-2-0/simplify-eslint-patterns.d.ts +0 -2
- package/src/migrations/update-17-2-0/simplify-eslint-patterns.js +0 -46
- package/src/migrations/update-17-2-9/move-options-to-target-defaults.d.ts +0 -2
- 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,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
|
-
}
|