@nx/eslint 0.0.0-pr-22179-271588f

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 (86) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +66 -0
  3. package/executors.json +10 -0
  4. package/generators.json +28 -0
  5. package/index.d.ts +4 -0
  6. package/index.js +14 -0
  7. package/migrations.json +138 -0
  8. package/package.json +52 -0
  9. package/plugin.d.ts +1 -0
  10. package/plugin.js +5 -0
  11. package/src/executors/lint/hasher.d.ts +9 -0
  12. package/src/executors/lint/hasher.js +43 -0
  13. package/src/executors/lint/lint.impl.d.ts +5 -0
  14. package/src/executors/lint/lint.impl.js +174 -0
  15. package/src/executors/lint/schema.d.ts +40 -0
  16. package/src/executors/lint/schema.json +148 -0
  17. package/src/executors/lint/utility/eslint-utils.d.ts +6 -0
  18. package/src/executors/lint/utility/eslint-utils.js +75 -0
  19. package/src/generators/convert-to-flat-config/converters/json-converter.d.ts +11 -0
  20. package/src/generators/convert-to-flat-config/converters/json-converter.js +175 -0
  21. package/src/generators/convert-to-flat-config/generator.d.ts +4 -0
  22. package/src/generators/convert-to-flat-config/generator.js +139 -0
  23. package/src/generators/convert-to-flat-config/schema.d.ts +3 -0
  24. package/src/generators/convert-to-flat-config/schema.json +17 -0
  25. package/src/generators/init/global-eslint-config.d.ts +29 -0
  26. package/src/generators/init/global-eslint-config.js +102 -0
  27. package/src/generators/init/init-migration.d.ts +3 -0
  28. package/src/generators/init/init-migration.js +137 -0
  29. package/src/generators/init/init.d.ts +9 -0
  30. package/src/generators/init/init.js +93 -0
  31. package/src/generators/init/schema.json +28 -0
  32. package/src/generators/lint-project/lint-project.d.ts +22 -0
  33. package/src/generators/lint-project/lint-project.js +227 -0
  34. package/src/generators/lint-project/setup-root-eslint.d.ts +7 -0
  35. package/src/generators/lint-project/setup-root-eslint.js +33 -0
  36. package/src/generators/utils/eslint-file.d.ts +16 -0
  37. package/src/generators/utils/eslint-file.js +287 -0
  38. package/src/generators/utils/eslint-targets.d.ts +2 -0
  39. package/src/generators/utils/eslint-targets.js +18 -0
  40. package/src/generators/utils/flat-config/ast-utils.d.ts +60 -0
  41. package/src/generators/utils/flat-config/ast-utils.js +573 -0
  42. package/src/generators/utils/flat-config/path-utils.d.ts +3 -0
  43. package/src/generators/utils/flat-config/path-utils.js +28 -0
  44. package/src/generators/utils/linter.d.ts +4 -0
  45. package/src/generators/utils/linter.js +8 -0
  46. package/src/generators/utils/plugin.d.ts +2 -0
  47. package/src/generators/utils/plugin.js +11 -0
  48. package/src/generators/workspace-rule/files/__name__.spec.ts__tmpl__ +11 -0
  49. package/src/generators/workspace-rule/files/__name__.ts__tmpl__ +37 -0
  50. package/src/generators/workspace-rule/schema.json +26 -0
  51. package/src/generators/workspace-rule/workspace-rule.d.ts +6 -0
  52. package/src/generators/workspace-rule/workspace-rule.js +78 -0
  53. package/src/generators/workspace-rules-project/files/index.ts__tmpl__ +27 -0
  54. package/src/generators/workspace-rules-project/files/tsconfig.json__tmpl__ +14 -0
  55. package/src/generators/workspace-rules-project/files/tsconfig.lint.json__tmpl__ +9 -0
  56. package/src/generators/workspace-rules-project/schema.json +23 -0
  57. package/src/generators/workspace-rules-project/workspace-rules-project.d.ts +8 -0
  58. package/src/generators/workspace-rules-project/workspace-rules-project.js +82 -0
  59. package/src/migrations/update-15-0-0/add-eslint-inputs.d.ts +2 -0
  60. package/src/migrations/update-15-0-0/add-eslint-inputs.js +27 -0
  61. package/src/migrations/update-15-7-1/add-eslint-ignore.d.ts +2 -0
  62. package/src/migrations/update-15-7-1/add-eslint-ignore.js +36 -0
  63. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
  64. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
  65. package/src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files.d.ts +2 -0
  66. package/src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files.js +44 -0
  67. package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.d.ts +2 -0
  68. package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.js +47 -0
  69. package/src/migrations/update-17-1-0/update-typescript-eslint.d.ts +2 -0
  70. package/src/migrations/update-17-1-0/update-typescript-eslint.js +74 -0
  71. package/src/migrations/update-17-2-0/simplify-eslint-patterns.d.ts +2 -0
  72. package/src/migrations/update-17-2-0/simplify-eslint-patterns.js +46 -0
  73. package/src/migrations/update-17-2-9/move-options-to-target-defaults.d.ts +2 -0
  74. package/src/migrations/update-17-2-9/move-options-to-target-defaults.js +107 -0
  75. package/src/plugins/plugin.d.ts +5 -0
  76. package/src/plugins/plugin.js +92 -0
  77. package/src/utils/config-file.d.ts +5 -0
  78. package/src/utils/config-file.js +35 -0
  79. package/src/utils/flat-config.d.ts +2 -0
  80. package/src/utils/flat-config.js +7 -0
  81. package/src/utils/rules-requiring-type-checking.d.ts +3 -0
  82. package/src/utils/rules-requiring-type-checking.js +84 -0
  83. package/src/utils/versions.d.ts +5 -0
  84. package/src/utils/versions.js +8 -0
  85. package/src/utils/workspace-lint-rules.d.ts +1 -0
  86. package/src/utils/workspace-lint-rules.js +5 -0
@@ -0,0 +1,37 @@
1
+ /**
2
+ * This file sets you up with structure needed for an ESLint rule.
3
+ *
4
+ * It leverages utilities from @typescript-eslint to allow TypeScript to
5
+ * provide autocompletions etc for the configuration.
6
+ *
7
+ * Your rule's custom logic will live within the create() method below
8
+ * and you can learn more about writing ESLint rules on the official guide:
9
+ *
10
+ * https://eslint.org/docs/developer-guide/working-with-rules
11
+ *
12
+ * You can also view many examples of existing rules here:
13
+ *
14
+ * https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin/src/rules
15
+ */
16
+
17
+ import { ESLintUtils } from '@typescript-eslint/utils';
18
+
19
+ // NOTE: The rule will be available in ESLint configs as "@nx/workspace-<%= name %>"
20
+ export const RULE_NAME = '<%= name %>';
21
+
22
+ export const rule = ESLintUtils.RuleCreator(() => __filename)({
23
+ name: RULE_NAME,
24
+ meta: {
25
+ type: 'problem',
26
+ docs: {
27
+ description: ``,
28
+ recommended: 'recommended',
29
+ },
30
+ schema: [],
31
+ messages: {},
32
+ },
33
+ defaultOptions: [],
34
+ create(context) {
35
+ return {};
36
+ },
37
+ });
@@ -0,0 +1,26 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NxWorkspaceRule",
4
+ "cli": "nx",
5
+ "title": "Create a new Workspace Lint Rule",
6
+ "description": "Create a new Workspace Lint Rule.",
7
+ "type": "object",
8
+ "properties": {
9
+ "name": {
10
+ "type": "string",
11
+ "description": "The name of the new rule.",
12
+ "$default": {
13
+ "$source": "argv",
14
+ "index": 0
15
+ }
16
+ },
17
+ "directory": {
18
+ "type": "string",
19
+ "description": "Create the rule under this directory within `tools/eslint-rules/` (can be nested).",
20
+ "alias": "dir",
21
+ "default": "rules"
22
+ }
23
+ },
24
+ "required": ["name", "directory"],
25
+ "examplesFile": "../../../docs/workspace-rule-examples.md"
26
+ }
@@ -0,0 +1,6 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export interface LintWorkspaceRuleGeneratorOptions {
3
+ name: string;
4
+ directory: string;
5
+ }
6
+ export declare function lintWorkspaceRuleGenerator(tree: Tree, options: LintWorkspaceRuleGeneratorOptions): Promise<import("@nx/devkit").GeneratorCallback>;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lintWorkspaceRuleGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const string_utils_1 = require("@nx/devkit/src/utils/string-utils");
6
+ const path_1 = require("path");
7
+ const ts = require("typescript");
8
+ const workspace_lint_rules_1 = require("../../utils/workspace-lint-rules");
9
+ const workspace_rules_project_1 = require("../workspace-rules-project/workspace-rules-project");
10
+ async function lintWorkspaceRuleGenerator(tree, options) {
11
+ const nxJson = (0, devkit_1.readNxJson)(tree);
12
+ // Ensure that the workspace rules project has been created
13
+ const projectGeneratorCallback = await (0, workspace_rules_project_1.lintWorkspaceRulesProjectGenerator)(tree, {
14
+ skipFormat: true,
15
+ addPlugin: process.env.NX_ADD_PLUGINS !== 'false' &&
16
+ nxJson.useInferencePlugins !== false,
17
+ });
18
+ const ruleDir = (0, devkit_1.joinPathFragments)(workspace_lint_rules_1.workspaceLintPluginDir, options.directory ?? '');
19
+ // Generate the required files for the new rule
20
+ (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files'), ruleDir, {
21
+ tmpl: '',
22
+ name: options.name,
23
+ });
24
+ const nameCamelCase = (0, string_utils_1.camelize)(options.name);
25
+ /**
26
+ * Import the new rule into the workspace plugin index.ts and
27
+ * register it ready for use in lint configs.
28
+ */
29
+ const pluginIndexPath = (0, devkit_1.joinPathFragments)(workspace_lint_rules_1.workspaceLintPluginDir, 'index.ts');
30
+ const existingPluginIndexContents = tree.read(pluginIndexPath, 'utf-8');
31
+ const pluginIndexSourceFile = ts.createSourceFile(pluginIndexPath, existingPluginIndexContents, ts.ScriptTarget.Latest, true);
32
+ function findRulesObject(node) {
33
+ if (ts.isPropertyAssignment(node) &&
34
+ ts.isIdentifier(node.name) &&
35
+ node.name.text === 'rules' &&
36
+ ts.isObjectLiteralExpression(node.initializer)) {
37
+ return node.initializer;
38
+ }
39
+ return node.forEachChild(findRulesObject);
40
+ }
41
+ const rulesObject = pluginIndexSourceFile.forEachChild((node) => findRulesObject(node));
42
+ if (rulesObject) {
43
+ const ruleNameSymbol = `${nameCamelCase}Name`;
44
+ const ruleConfigSymbol = nameCamelCase;
45
+ /**
46
+ * If the rules object already has entries, we need to make sure our insertion
47
+ * takes commas into account.
48
+ */
49
+ let leadingComma = '';
50
+ if (rulesObject.properties.length > 0) {
51
+ if (!rulesObject.properties.hasTrailingComma) {
52
+ leadingComma = ',';
53
+ }
54
+ }
55
+ const newContents = (0, devkit_1.applyChangesToString)(existingPluginIndexContents, [
56
+ {
57
+ type: devkit_1.ChangeType.Insert,
58
+ index: 0,
59
+ text: `import { RULE_NAME as ${ruleNameSymbol}, rule as ${ruleConfigSymbol} } from './${options.directory ? `${options.directory}/` : ''}${options.name}';\n`,
60
+ },
61
+ {
62
+ type: devkit_1.ChangeType.Insert,
63
+ index: rulesObject.getEnd() - 1,
64
+ text: `${leadingComma}[${ruleNameSymbol}]: ${ruleConfigSymbol}\n`,
65
+ },
66
+ ]);
67
+ tree.write(pluginIndexPath, newContents);
68
+ }
69
+ await (0, devkit_1.formatFiles)(tree);
70
+ devkit_1.logger.info(`NX Reminder: Once you have finished writing your rule logic, you need to actually enable the rule within an appropriate ESLint config in your workspace, for example:
71
+
72
+ "rules": {
73
+ "@nx/workspace-${options.name}": "error"
74
+ }
75
+ `);
76
+ return projectGeneratorCallback;
77
+ }
78
+ exports.lintWorkspaceRuleGenerator = lintWorkspaceRuleGenerator;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Import your custom workspace rules at the top of this file.
3
+ *
4
+ * For example:
5
+ *
6
+ * import { RULE_NAME as myCustomRuleName, rule as myCustomRule } from './rules/my-custom-rule';
7
+ *
8
+ * In order to quickly get started with writing rules you can use the
9
+ * following generator command and provide your desired rule name:
10
+ *
11
+ * ```sh
12
+ * npx nx g @nx/eslint:workspace-rule {{ NEW_RULE_NAME }}
13
+ * ```
14
+ */
15
+
16
+ module.exports = {
17
+ /**
18
+ * Apply the imported custom rules here.
19
+ *
20
+ * For example (using the example import above):
21
+ *
22
+ * rules: {
23
+ * [myCustomRuleName]: myCustomRule
24
+ * }
25
+ */
26
+ rules: {}
27
+ };
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "<%= rootTsConfigPath %>",
3
+ "compilerOptions": {
4
+ "moduleResolution": "node16",
5
+ "module": "node16"
6
+ },
7
+ "files": [],
8
+ "include": [],
9
+ "references": [
10
+ {
11
+ "path": "./tsconfig.lint.json"
12
+ }
13
+ ]
14
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "<%= offsetFromRoot %>dist/out-tsc",
5
+ "types": ["node"]
6
+ },
7
+ "exclude": ["**/*.spec.ts"],
8
+ "include": ["**/*.ts"]
9
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NxWorkspaceRulesProject",
4
+ "cli": "nx",
5
+ "title": "Create the Workspace Lint Rules Project",
6
+ "description": "Create the Workspace Lint Rules Project.",
7
+ "type": "object",
8
+ "examples": [
9
+ {
10
+ "command": "nx g @nx/eslint:workspace-rules-project",
11
+ "description": "Create the Workspace Lint Rules Project"
12
+ }
13
+ ],
14
+ "properties": {
15
+ "skipFormat": {
16
+ "description": "Skip formatting files.",
17
+ "type": "boolean",
18
+ "default": false,
19
+ "x-priority": "internal"
20
+ }
21
+ },
22
+ "required": []
23
+ }
@@ -0,0 +1,8 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ export declare const WORKSPACE_RULES_PROJECT_NAME = "eslint-rules";
3
+ export declare const WORKSPACE_PLUGIN_DIR = "tools/eslint-rules";
4
+ export interface LintWorkspaceRulesProjectGeneratorOptions {
5
+ skipFormat?: boolean;
6
+ addPlugin?: boolean;
7
+ }
8
+ export declare function lintWorkspaceRulesProjectGenerator(tree: Tree, options?: LintWorkspaceRulesProjectGeneratorOptions): Promise<GeneratorCallback>;
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lintWorkspaceRulesProjectGenerator = exports.WORKSPACE_PLUGIN_DIR = exports.WORKSPACE_RULES_PROJECT_NAME = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const js_1 = require("@nx/js");
6
+ const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
7
+ const path_1 = require("path");
8
+ const versions_1 = require("../../utils/versions");
9
+ const workspace_lint_rules_1 = require("../../utils/workspace-lint-rules");
10
+ exports.WORKSPACE_RULES_PROJECT_NAME = 'eslint-rules';
11
+ exports.WORKSPACE_PLUGIN_DIR = 'tools/eslint-rules';
12
+ async function lintWorkspaceRulesProjectGenerator(tree, options = {}) {
13
+ const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
14
+ const tasks = [];
15
+ // Noop if the workspace rules project already exists
16
+ try {
17
+ (0, devkit_1.readProjectConfiguration)(tree, exports.WORKSPACE_RULES_PROJECT_NAME);
18
+ return;
19
+ }
20
+ catch { }
21
+ // Create the project, the test target is added below by the jest generator
22
+ (0, devkit_1.addProjectConfiguration)(tree, exports.WORKSPACE_RULES_PROJECT_NAME, {
23
+ root: exports.WORKSPACE_PLUGIN_DIR,
24
+ sourceRoot: exports.WORKSPACE_PLUGIN_DIR,
25
+ targets: {},
26
+ });
27
+ // Generate the required files
28
+ (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files'), workspace_lint_rules_1.workspaceLintPluginDir, {
29
+ tmpl: '',
30
+ offsetFromRoot: (0, devkit_1.offsetFromRoot)(exports.WORKSPACE_PLUGIN_DIR),
31
+ rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(tree, exports.WORKSPACE_PLUGIN_DIR),
32
+ });
33
+ /**
34
+ * Ensure that when workspace rules are updated they cause all projects to be affected for now.
35
+ * TODO: Explore writing a ProjectGraph plugin to make this more surgical.
36
+ */
37
+ const nxJson = (0, devkit_1.readNxJson)(tree);
38
+ if (nxJson.targetDefaults?.lint?.inputs) {
39
+ nxJson.targetDefaults.lint.inputs.push(`{workspaceRoot}/${exports.WORKSPACE_PLUGIN_DIR}/**/*`);
40
+ (0, devkit_1.updateNxJson)(tree, nxJson);
41
+ }
42
+ // Add jest to the project and return installation task
43
+ tasks.push(await configurationGenerator(tree, {
44
+ ...options,
45
+ project: exports.WORKSPACE_RULES_PROJECT_NAME,
46
+ supportTsx: false,
47
+ skipSerializers: true,
48
+ setupFile: 'none',
49
+ compiler: 'tsc',
50
+ skipFormat: true,
51
+ }));
52
+ (0, devkit_1.updateJson)(tree, (0, path_1.join)(workspace_lint_rules_1.workspaceLintPluginDir, 'tsconfig.spec.json'), (json) => {
53
+ delete json.compilerOptions?.module;
54
+ if (json.include) {
55
+ json.include = json.include.map((v) => {
56
+ if (v.startsWith('src/**')) {
57
+ return v.replace('src/', '');
58
+ }
59
+ return v;
60
+ });
61
+ }
62
+ if (json.exclude) {
63
+ json.exclude = json.exclude.map((v) => {
64
+ if (v.startsWith('src/**')) {
65
+ return v.replace('src/', '');
66
+ }
67
+ return v;
68
+ });
69
+ }
70
+ return json;
71
+ });
72
+ // Add swc dependencies
73
+ tasks.push((0, add_swc_dependencies_1.addSwcRegisterDependencies)(tree));
74
+ tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
75
+ '@typescript-eslint/utils': versions_1.typescriptESLintVersion,
76
+ }));
77
+ if (!options.skipFormat) {
78
+ await (0, devkit_1.formatFiles)(tree);
79
+ }
80
+ return (0, devkit_1.runTasksInSerial)(...tasks);
81
+ }
82
+ exports.lintWorkspaceRulesProjectGenerator = lintWorkspaceRulesProjectGenerator;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function addEslintInputs(tree: Tree): Promise<void>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const eslint_targets_1 = require("../../generators/utils/eslint-targets");
5
+ const config_file_1 = require("../../utils/config-file");
6
+ async function addEslintInputs(tree) {
7
+ const nxJson = (0, devkit_1.readNxJson)(tree);
8
+ const globalEslintFile = config_file_1.ESLINT_CONFIG_FILENAMES.find((file) => tree.exists(file));
9
+ if (globalEslintFile && nxJson.namedInputs?.production) {
10
+ const productionFileset = new Set(nxJson.namedInputs.production);
11
+ productionFileset.add(`!{projectRoot}/${globalEslintFile}`);
12
+ nxJson.namedInputs.production = Array.from(productionFileset);
13
+ }
14
+ for (const targetName of (0, eslint_targets_1.getEslintTargets)(tree)) {
15
+ nxJson.targetDefaults ??= {};
16
+ const lintTargetDefaults = (nxJson.targetDefaults[targetName] ??= {});
17
+ lintTargetDefaults.inputs ??= [
18
+ 'default',
19
+ ...(globalEslintFile
20
+ ? [(0, devkit_1.joinPathFragments)('{workspaceRoot}', globalEslintFile)]
21
+ : []),
22
+ ];
23
+ }
24
+ (0, devkit_1.updateNxJson)(tree, nxJson);
25
+ await (0, devkit_1.formatFiles)(tree);
26
+ }
27
+ exports.default = addEslintInputs;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function addEslintIgnore(tree: Tree): Promise<void>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const eslint_targets_1 = require("../../generators/utils/eslint-targets");
5
+ const config_file_1 = require("../../utils/config-file");
6
+ async function addEslintIgnore(tree) {
7
+ const nxJson = (0, devkit_1.readJson)(tree, 'nx.json');
8
+ const globalEslintFile = config_file_1.ESLINT_CONFIG_FILENAMES.find((file) => tree.exists(file));
9
+ if (globalEslintFile) {
10
+ if (tree.exists('.eslintignore')) {
11
+ const content = tree.read('.eslintignore', 'utf-8');
12
+ if (!content.includes('node_modules')) {
13
+ tree.write('.eslintignore', `node_modules\n${content}`);
14
+ }
15
+ }
16
+ else {
17
+ tree.write('.eslintignore', 'node_modules\n');
18
+ }
19
+ for (const targetName of (0, eslint_targets_1.getEslintTargets)(tree)) {
20
+ nxJson.targetDefaults ??= {};
21
+ const lintTargetDefaults = (nxJson.targetDefaults[targetName] ??= {});
22
+ const lintIgnorePath = (0, devkit_1.joinPathFragments)('{workspaceRoot}', globalEslintFile);
23
+ if (lintTargetDefaults.inputs) {
24
+ if (!lintTargetDefaults.inputs.includes(lintIgnorePath)) {
25
+ lintTargetDefaults.inputs.push(lintIgnorePath);
26
+ }
27
+ }
28
+ else {
29
+ lintTargetDefaults.inputs = ['default', lintIgnorePath];
30
+ }
31
+ }
32
+ (0, devkit_1.updateNxJson)(tree, nxJson);
33
+ await (0, devkit_1.formatFiles)(tree);
34
+ }
35
+ }
36
+ exports.default = addEslintIgnore;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function replacePackage(tree: Tree): Promise<void>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
5
+ async function replacePackage(tree) {
6
+ await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/linter', '@nx/linter');
7
+ await (0, devkit_1.formatFiles)(tree);
8
+ }
9
+ exports.default = replacePackage;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function update(tree: Tree): void;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
5
+ const eslint_file_1 = require("../../generators/utils/eslint-file");
6
+ // Add `ignoredFiles` pattern to projects using vite, esbuild, and rollup.
7
+ // This is needed because the @nx/dependency-checks lint rule will complain
8
+ // about dependencies used in build config files, even though they are not
9
+ // production dependencies.
10
+ function update(tree) {
11
+ const projects = (0, devkit_1.getProjects)(tree);
12
+ const addIgnorePattern = (ignorePattern) => (_options, projectName) => {
13
+ const project = projects.get(projectName);
14
+ if (!(0, eslint_file_1.findEslintFile)(tree, project.root) ||
15
+ !(0, eslint_file_1.isEslintConfigSupported)(tree)) {
16
+ return;
17
+ }
18
+ if ((0, eslint_file_1.lintConfigHasOverride)(tree, project.root, (o) => Array.isArray(o.files)
19
+ ? o.files.some((f) => f.match(/\.json$/))
20
+ : !!o.files?.match(/\.json$/), true)) {
21
+ (0, eslint_file_1.updateOverrideInLintConfig)(tree, project.root, (o) => !!o.rules?.['@nx/dependency-checks'], (o) => {
22
+ const value = o.rules['@nx/dependency-checks'];
23
+ let ruleSeverity;
24
+ let ruleOptions;
25
+ if (Array.isArray(value)) {
26
+ ruleSeverity = value[0];
27
+ ruleOptions = value[1];
28
+ }
29
+ else {
30
+ ruleSeverity = value;
31
+ ruleOptions = {};
32
+ }
33
+ ruleOptions.ignoredFiles = [ignorePattern];
34
+ o.rules['@nx/dependency-checks'] = [ruleSeverity, ruleOptions];
35
+ return o;
36
+ });
37
+ }
38
+ };
39
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/vite:build', addIgnorePattern('{projectRoot}/vite.config.{js,ts,mjs,mts}'));
40
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/vite:test', addIgnorePattern('{projectRoot}/vite.config.{js,ts,mjs,mts}'));
41
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/esbuild:esbuild', addIgnorePattern('{projectRoot}/esbuild.config.{js,ts,mjs,mts}'));
42
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/rollup:rollup', addIgnorePattern('{projectRoot}/rollup.config.{js,ts,mjs,mts}'));
43
+ }
44
+ exports.default = update;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function replacePackage(tree: Tree): Promise<void>;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
5
+ async function replacePackage(tree) {
6
+ await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nx/linter', '@nx/eslint');
7
+ // executor name change from :eslint to :lint
8
+ updateNxJsonExecutor(tree);
9
+ updateProjectExecutor(tree);
10
+ await (0, devkit_1.formatFiles)(tree);
11
+ }
12
+ exports.default = replacePackage;
13
+ function updateNxJsonExecutor(tree) {
14
+ if (!tree.exists('nx.json')) {
15
+ return;
16
+ }
17
+ const nxJson = (0, devkit_1.readNxJson)(tree);
18
+ let needsUpdate = false;
19
+ for (const [targetName, targetConfig] of Object.entries(nxJson.targetDefaults ?? {})) {
20
+ // this will be in a broken state after the package is globally renamed
21
+ if (targetConfig.executor !== '@nx/eslint:eslint') {
22
+ continue;
23
+ }
24
+ needsUpdate = true;
25
+ nxJson.targetDefaults[targetName].executor = '@nx/eslint:lint';
26
+ }
27
+ if (needsUpdate) {
28
+ (0, devkit_1.updateNxJson)(tree, nxJson);
29
+ }
30
+ }
31
+ function updateProjectExecutor(tree) {
32
+ const projects = (0, devkit_1.getProjects)(tree);
33
+ for (const [projectName, projectConfiguration] of projects) {
34
+ let needsUpdate = false;
35
+ for (const [targetName, targetConfig] of Object.entries(projectConfiguration.targets ?? {})) {
36
+ // this will be in a broken state after the package is globally renamed
37
+ if (targetConfig.executor !== '@nx/eslint:eslint') {
38
+ continue;
39
+ }
40
+ needsUpdate = true;
41
+ projectConfiguration.targets[targetName].executor = '@nx/eslint:lint';
42
+ }
43
+ if (needsUpdate) {
44
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function update(tree: Tree): Promise<void>;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const versions_1 = require("../../utils/versions");
5
+ const path_1 = require("path");
6
+ const typescript_1 = require("typescript");
7
+ function updateJestConfig(tree) {
8
+ const jestConfigPath = 'tools/eslint-rules/jest.config.ts';
9
+ if (tree.exists(jestConfigPath)) {
10
+ const { removePropertyFromJestConfig } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
11
+ removePropertyFromJestConfig(tree, jestConfigPath, [
12
+ 'moduleNameMapper',
13
+ '@eslint/eslintrc',
14
+ ]);
15
+ }
16
+ }
17
+ function updateTsConfigs(tree) {
18
+ const tsConfigPath = 'tools/eslint-rules/tsconfig.json';
19
+ if (tree.exists(tsConfigPath)) {
20
+ (0, devkit_1.updateJson)(tree, tsConfigPath, (tsConfig) => {
21
+ tsConfig.compilerOptions ??= {};
22
+ tsConfig.compilerOptions.moduleResolution = 'node16';
23
+ tsConfig.compilerOptions.module = 'node16';
24
+ return tsConfig;
25
+ });
26
+ }
27
+ const tsConfigSpec = 'tools/eslint-rules/tsconfig.spec.json';
28
+ if (tree.exists(tsConfigSpec)) {
29
+ (0, devkit_1.updateJson)(tree, tsConfigSpec, (tsConfigSpec) => {
30
+ delete tsConfigSpec.compilerOptions?.module;
31
+ delete tsConfigSpec.compilerOptions?.moduleResolution;
32
+ return tsConfigSpec;
33
+ });
34
+ }
35
+ }
36
+ function updateRecommended(tree) {
37
+ (0, devkit_1.visitNotIgnoredFiles)(tree, 'tools/eslint-rules', (path) => {
38
+ if ((0, path_1.extname)(path) !== '.ts') {
39
+ return;
40
+ }
41
+ const contents = tree.read(path, 'utf-8');
42
+ const sourceFile = (0, typescript_1.createSourceFile)(path, contents, typescript_1.ScriptTarget.ESNext, true);
43
+ const changes = [];
44
+ const visit = (node) => {
45
+ if ((0, typescript_1.isPropertyAssignment)(node) &&
46
+ (0, typescript_1.isIdentifier)(node.name) &&
47
+ node.name.text === 'recommended' &&
48
+ (0, typescript_1.isStringLiteral)(node.initializer)) {
49
+ changes.push({
50
+ type: devkit_1.ChangeType.Delete,
51
+ start: node.initializer.getStart(sourceFile),
52
+ length: node.initializer.getWidth(sourceFile),
53
+ });
54
+ changes.push({
55
+ type: devkit_1.ChangeType.Insert,
56
+ index: node.initializer.getStart(sourceFile),
57
+ text: "'recommended'",
58
+ });
59
+ }
60
+ else {
61
+ (0, typescript_1.forEachChild)(node, visit);
62
+ }
63
+ };
64
+ (0, typescript_1.forEachChild)(sourceFile, visit);
65
+ tree.write(path, (0, devkit_1.applyChangesToString)(contents, changes));
66
+ });
67
+ }
68
+ async function update(tree) {
69
+ updateJestConfig(tree);
70
+ updateTsConfigs(tree);
71
+ updateRecommended(tree);
72
+ await (0, devkit_1.formatFiles)(tree);
73
+ }
74
+ exports.default = update;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function update(tree: Tree): Promise<void>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ async function update(tree) {
5
+ const projects = (0, devkit_1.getProjects)(tree);
6
+ for (const [projectName, projectConfiguration] of projects) {
7
+ let needsUpdate = false;
8
+ for (const [targetName, targetConfig] of Object.entries(projectConfiguration.targets ?? {})) {
9
+ if (targetConfig.executor !== '@nx/eslint:lint') {
10
+ continue;
11
+ }
12
+ needsUpdate = true;
13
+ if (projectConfiguration.targets[targetName].options?.lintFilePatterns) {
14
+ const rootPattern = getLintRoot(projectConfiguration);
15
+ const nonRootPatterns = projectConfiguration.targets[targetName].options.lintFilePatterns.filter((p) => !p.startsWith(rootPattern) && !p.startsWith('{projectRoot}'));
16
+ if (nonRootPatterns.length === 0 &&
17
+ rootPattern === projectConfiguration.root) {
18
+ // delete the lintFilePatterns option if it's the only option and matches the root of the project
19
+ delete projectConfiguration.targets[targetName].options
20
+ .lintFilePatterns;
21
+ if (Object.keys(projectConfiguration.targets[targetName].options)
22
+ .length === 0) {
23
+ delete projectConfiguration.targets[targetName].options;
24
+ }
25
+ }
26
+ else {
27
+ projectConfiguration.targets[targetName].options.lintFilePatterns = [
28
+ rootPattern,
29
+ ...nonRootPatterns,
30
+ ];
31
+ }
32
+ }
33
+ }
34
+ if (needsUpdate) {
35
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
36
+ }
37
+ }
38
+ await (0, devkit_1.formatFiles)(tree);
39
+ }
40
+ exports.default = update;
41
+ function getLintRoot({ root, sourceRoot }) {
42
+ if (root === '' || root === '.') {
43
+ return sourceRoot || './src';
44
+ }
45
+ return root;
46
+ }
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function update(tree: Tree): Promise<void>;