@nx/eslint 17.0.0-beta.8

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 (69) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +61 -0
  3. package/executors.json +10 -0
  4. package/generators.json +22 -0
  5. package/index.d.ts +4 -0
  6. package/index.js +14 -0
  7. package/migrations.json +79 -0
  8. package/package.json +51 -0
  9. package/src/executors/lint/hasher.d.ts +9 -0
  10. package/src/executors/lint/hasher.js +43 -0
  11. package/src/executors/lint/lint.impl.d.ts +5 -0
  12. package/src/executors/lint/lint.impl.js +140 -0
  13. package/src/executors/lint/schema.d.ts +39 -0
  14. package/src/executors/lint/schema.json +144 -0
  15. package/src/executors/lint/utility/eslint-utils.d.ts +6 -0
  16. package/src/executors/lint/utility/eslint-utils.js +71 -0
  17. package/src/generators/convert-to-flat-config/converters/json-converter.d.ts +6 -0
  18. package/src/generators/convert-to-flat-config/converters/json-converter.js +180 -0
  19. package/src/generators/convert-to-flat-config/generator.d.ts +4 -0
  20. package/src/generators/convert-to-flat-config/generator.js +83 -0
  21. package/src/generators/convert-to-flat-config/schema.d.ts +3 -0
  22. package/src/generators/convert-to-flat-config/schema.json +17 -0
  23. package/src/generators/init/global-eslint-config.d.ts +29 -0
  24. package/src/generators/init/global-eslint-config.js +98 -0
  25. package/src/generators/init/init-migration.d.ts +3 -0
  26. package/src/generators/init/init-migration.js +103 -0
  27. package/src/generators/init/init.d.ts +9 -0
  28. package/src/generators/init/init.js +65 -0
  29. package/src/generators/lint-project/lint-project.d.ts +16 -0
  30. package/src/generators/lint-project/lint-project.js +191 -0
  31. package/src/generators/utils/eslint-file.d.ts +19 -0
  32. package/src/generators/utils/eslint-file.js +269 -0
  33. package/src/generators/utils/eslint-targets.d.ts +2 -0
  34. package/src/generators/utils/eslint-targets.js +18 -0
  35. package/src/generators/utils/flat-config/ast-utils.d.ts +61 -0
  36. package/src/generators/utils/flat-config/ast-utils.js +581 -0
  37. package/src/generators/utils/flat-config/path-utils.d.ts +2 -0
  38. package/src/generators/utils/flat-config/path-utils.js +31 -0
  39. package/src/generators/utils/linter.d.ts +4 -0
  40. package/src/generators/utils/linter.js +8 -0
  41. package/src/generators/workspace-rule/files/__name__.spec.ts__tmpl__ +11 -0
  42. package/src/generators/workspace-rule/files/__name__.ts__tmpl__ +37 -0
  43. package/src/generators/workspace-rule/schema.json +26 -0
  44. package/src/generators/workspace-rule/workspace-rule.d.ts +6 -0
  45. package/src/generators/workspace-rule/workspace-rule.js +73 -0
  46. package/src/generators/workspace-rules-project/files/index.ts__tmpl__ +27 -0
  47. package/src/generators/workspace-rules-project/files/tsconfig.json__tmpl__ +13 -0
  48. package/src/generators/workspace-rules-project/files/tsconfig.lint.json__tmpl__ +9 -0
  49. package/src/generators/workspace-rules-project/schema.json +23 -0
  50. package/src/generators/workspace-rules-project/workspace-rules-project.d.ts +7 -0
  51. package/src/generators/workspace-rules-project/workspace-rules-project.js +80 -0
  52. package/src/migrations/update-15-0-0/add-eslint-inputs.d.ts +2 -0
  53. package/src/migrations/update-15-0-0/add-eslint-inputs.js +27 -0
  54. package/src/migrations/update-15-7-1/add-eslint-ignore.d.ts +2 -0
  55. package/src/migrations/update-15-7-1/add-eslint-ignore.js +36 -0
  56. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
  57. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
  58. package/src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files.d.ts +2 -0
  59. package/src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files.js +44 -0
  60. package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.d.ts +2 -0
  61. package/src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint.js +45 -0
  62. package/src/utils/flat-config.d.ts +2 -0
  63. package/src/utils/flat-config.js +7 -0
  64. package/src/utils/rules-requiring-type-checking.d.ts +3 -0
  65. package/src/utils/rules-requiring-type-checking.js +84 -0
  66. package/src/utils/versions.d.ts +5 -0
  67. package/src/utils/versions.js +8 -0
  68. package/src/utils/workspace-lint-rules.d.ts +1 -0
  69. package/src/utils/workspace-lint-rules.js +5 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2017-2023 Narwhal Technologies Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ <p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx.png" width="600" alt="Nx - Smart, Fast and Extensible Build System"></p>
2
+
3
+ <div style="text-align: center;">
4
+
5
+ [![CircleCI](https://circleci.com/gh/nrwl/nx.svg?style=svg)](https://circleci.com/gh/nrwl/nx)
6
+ [![License](https://img.shields.io/npm/l/@nx/workspace.svg?style=flat-square)]()
7
+ [![NPM Version](https://badge.fury.io/js/%40nrwl%2Fworkspace.svg)](https://www.npmjs.com/@nx/workspace)
8
+ [![Semantic Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)]()
9
+ [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
10
+ [![Join the chat at https://gitter.im/nrwl-nx/community](https://badges.gitter.im/nrwl-nx/community.svg)](https://gitter.im/nrwl-nx/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
11
+ [![Join us on the Official Nx Discord Server](https://img.shields.io/discord/1143497901675401286?label=discord)](https://go.nx.dev/community)
12
+
13
+ </div>
14
+
15
+
16
+ <hr>
17
+
18
+ # Nx: Smart, Fast and Extensible Build System
19
+
20
+ Nx is a next generation build system with first class monorepo support and powerful integrations.
21
+
22
+ ## Getting Started
23
+
24
+ ### Creating an Nx Workspace
25
+
26
+ **Using `npx`**
27
+
28
+ ```bash
29
+ npx create-nx-workspace
30
+ ```
31
+
32
+ **Using `npm init`**
33
+
34
+ ```bash
35
+ npm init nx-workspace
36
+ ```
37
+
38
+ **Using `yarn create`**
39
+
40
+ ```bash
41
+ yarn create nx-workspace
42
+ ```
43
+
44
+ ### Adding Nx to an Existing Repository
45
+
46
+ Run:
47
+
48
+ ```bash
49
+ npx nx@latest init
50
+ ```
51
+
52
+ ## Documentation & Resources
53
+
54
+ - [Nx.Dev: Documentation, Guides, Tutorials](https://nx.dev)
55
+ - [Intro to Nx](https://nx.dev/getting-started/intro)
56
+ - [Official Nx YouTube Channel](https://www.youtube.com/@NxDevtools)
57
+ - [Blog Posts About Nx](https://blog.nrwl.io/nx/home)
58
+
59
+ <p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
60
+ width="100%" alt="Nx - Smart, Fast and Extensible Build System"></a></p>
61
+
package/executors.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "executors": {
3
+ "lint": {
4
+ "implementation": "./src/executors/lint/lint.impl",
5
+ "schema": "./src/executors/lint/schema.json",
6
+ "hasher": "./src/executors/lint/hasher",
7
+ "description": "Run ESLint on a project."
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "nx/eslint",
3
+ "version": "0.1",
4
+ "generators": {
5
+ "workspace-rules-project": {
6
+ "factory": "./src/generators/workspace-rules-project/workspace-rules-project#lintWorkspaceRulesProjectGenerator",
7
+ "schema": "./src/generators/workspace-rules-project/schema.json",
8
+ "description": "Create the Workspace Lint Rules Project.",
9
+ "hidden": true
10
+ },
11
+ "workspace-rule": {
12
+ "factory": "./src/generators/workspace-rule/workspace-rule#lintWorkspaceRuleGenerator",
13
+ "schema": "./src/generators/workspace-rule/schema.json",
14
+ "description": "Create a new Workspace ESLint rule."
15
+ },
16
+ "convert-to-flat-config": {
17
+ "factory": "./src/generators/convert-to-flat-config/generator",
18
+ "schema": "./src/generators/convert-to-flat-config/schema.json",
19
+ "description": "Convert an Nx workspace's ESLint configs to use Flat Config."
20
+ }
21
+ }
22
+ }
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { lintProjectGenerator } from './src/generators/lint-project/lint-project';
2
+ export { lintInitGenerator } from './src/generators/init/init';
3
+ export { Linter } from './src/generators/utils/linter';
4
+ export { hasRulesRequiringTypeChecking } from './src/utils/rules-requiring-type-checking';
package/index.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasRulesRequiringTypeChecking = exports.Linter = exports.lintInitGenerator = exports.lintProjectGenerator = void 0;
4
+ var lint_project_1 = require("./src/generators/lint-project/lint-project");
5
+ Object.defineProperty(exports, "lintProjectGenerator", { enumerable: true, get: function () { return lint_project_1.lintProjectGenerator; } });
6
+ var init_1 = require("./src/generators/init/init");
7
+ Object.defineProperty(exports, "lintInitGenerator", { enumerable: true, get: function () { return init_1.lintInitGenerator; } });
8
+ var linter_1 = require("./src/generators/utils/linter");
9
+ Object.defineProperty(exports, "Linter", { enumerable: true, get: function () { return linter_1.Linter; } });
10
+ // @nx/angular needs it for the Angular CLI workspace migration to Nx to
11
+ // infer whether a config is using type aware rules and set the
12
+ // `hasTypeAwareRules` option of the `@nx/eslint:lint` executor.
13
+ var rules_requiring_type_checking_1 = require("./src/utils/rules-requiring-type-checking");
14
+ Object.defineProperty(exports, "hasRulesRequiringTypeChecking", { enumerable: true, get: function () { return rules_requiring_type_checking_1.hasRulesRequiringTypeChecking; } });
@@ -0,0 +1,79 @@
1
+ {
2
+ "generators": {
3
+ "add-eslint-inputs": {
4
+ "cli": "nx",
5
+ "version": "15.0.0-beta.0",
6
+ "description": "Stop hashing eslint config files for build targets and dependent tasks",
7
+ "factory": "./src/migrations/update-15-0-0/add-eslint-inputs"
8
+ },
9
+ "add-eslint-ignore": {
10
+ "cli": "nx",
11
+ "version": "15.7.1-beta.0",
12
+ "description": "Add node_modules to root eslint ignore",
13
+ "factory": "./src/migrations/update-15-7-1/add-eslint-ignore"
14
+ },
15
+ "update-16-0-0-add-nx-packages": {
16
+ "cli": "nx",
17
+ "version": "16.0.0-beta.1",
18
+ "description": "Replace @nrwl/linter with @nx/linter",
19
+ "implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
20
+ },
21
+ "update-16-8-0-add-ignored-files": {
22
+ "version": "16.8.0",
23
+ "description": "update-16-8-0-add-ignored-files",
24
+ "implementation": "./src/migrations/update-16-8-0-add-ignored-files/update-16-8-0-add-ignored-files"
25
+ },
26
+ "update-17-0-0-rename-to-eslint": {
27
+ "version": "17.0.0-beta.7",
28
+ "description": "update-17-0-0-rename-to-eslint",
29
+ "implementation": "./src/migrations/update-17-0-0-rename-to-eslint/update-17-0-0-rename-to-eslint"
30
+ }
31
+ },
32
+ "packageJsonUpdates": {
33
+ "16.0.0": {
34
+ "version": "16.0.0-beta.0",
35
+ "packages": {
36
+ "@typescript-eslint/parser": {
37
+ "version": "^5.58.0"
38
+ },
39
+ "@typescript-eslint/eslint-plugin": {
40
+ "version": "^5.58.0"
41
+ },
42
+ "@typescript-eslint/utils": {
43
+ "version": "^5.58.0"
44
+ }
45
+ }
46
+ },
47
+ "16.5.0": {
48
+ "version": "16.5.0-beta.2",
49
+ "packages": {
50
+ "@typescript-eslint/parser": {
51
+ "version": "^5.60.1"
52
+ },
53
+ "@typescript-eslint/eslint-plugin": {
54
+ "version": "^5.60.1"
55
+ },
56
+ "@typescript-eslint/utils": {
57
+ "version": "^5.60.1"
58
+ }
59
+ }
60
+ },
61
+ "16.7.0": {
62
+ "version": "16.7.0-beta.2",
63
+ "packages": {
64
+ "eslint": {
65
+ "version": "~8.46.0"
66
+ },
67
+ "@typescript-eslint/parser": {
68
+ "version": "^5.60.1"
69
+ },
70
+ "@typescript-eslint/eslint-plugin": {
71
+ "version": "^5.60.1"
72
+ },
73
+ "@typescript-eslint/utils": {
74
+ "version": "^5.60.1"
75
+ }
76
+ }
77
+ }
78
+ }
79
+ }
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@nx/eslint",
3
+ "version": "17.0.0-beta.8",
4
+ "private": false,
5
+ "description": "The ESLint plugin for Nx contains executors, generators and utilities used for linting JavaScript/TypeScript projects within an Nx workspace.",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/nrwl/nx.git",
9
+ "directory": "packages/eslint"
10
+ },
11
+ "keywords": [
12
+ "Monorepo",
13
+ "Web",
14
+ "Lint",
15
+ "ESLint",
16
+ "CLI"
17
+ ],
18
+ "main": "./index.js",
19
+ "typings": "./index.d.ts",
20
+ "author": "Victor Savkin",
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/nrwl/nx/issues"
24
+ },
25
+ "homepage": "https://nx.dev",
26
+ "ng-update": {
27
+ "requirements": {},
28
+ "migrations": "./migrations.json"
29
+ },
30
+ "executors": "./executors.json",
31
+ "generators": "./generators.json",
32
+ "peerDependencies": {
33
+ "eslint": "^8.0.0"
34
+ },
35
+ "dependencies": {
36
+ "tslib": "^2.3.0",
37
+ "@nx/devkit": "17.0.0-beta.8",
38
+ "@nx/js": "17.0.0-beta.8",
39
+ "typescript": "~5.1.3",
40
+ "@nx/linter": "17.0.0-beta.8"
41
+ },
42
+ "peerDependenciesMeta": {
43
+ "eslint": {
44
+ "optional": true
45
+ }
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "type": "commonjs"
51
+ }
@@ -0,0 +1,9 @@
1
+ /// <reference types="node" />
2
+ import { Hash, ProjectGraph, ProjectsConfigurations, Task, TaskGraph, TaskHasher } from '@nx/devkit';
3
+ export default function run(task: Task, context: {
4
+ hasher: TaskHasher;
5
+ projectGraph: ProjectGraph;
6
+ taskGraph: TaskGraph;
7
+ projectsConfigurations: ProjectsConfigurations;
8
+ env: NodeJS.ProcessEnv;
9
+ }): Promise<Hash>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ async function run(task, context) {
5
+ const res = await context.hasher.hashTask(task, context.taskGraph, context.env);
6
+ if (task.overrides['hasTypeAwareRules'] === true) {
7
+ return res;
8
+ }
9
+ const deps = allDeps(task.id, context.taskGraph, context.projectGraph);
10
+ const tags = (0, devkit_1.hashArray)(deps.map((d) => (context.projectsConfigurations.projects[d].tags || []).join('|')));
11
+ const command = res.details['command'];
12
+ let selfSource = '';
13
+ for (let n of Object.keys(res.details)) {
14
+ if (n.startsWith(`${task.target.project}:`)) {
15
+ selfSource = res.details.nodes[n];
16
+ }
17
+ }
18
+ const nodes = {};
19
+ const hashes = [];
20
+ for (const d of Object.keys(res.details.nodes)) {
21
+ if (d.indexOf('$fileset') === -1) {
22
+ nodes[d] = res.details.nodes[d];
23
+ hashes.push(res.details.nodes[d]);
24
+ }
25
+ }
26
+ return {
27
+ value: (0, devkit_1.hashArray)([command, selfSource, ...hashes, tags]),
28
+ details: {
29
+ command,
30
+ nodes: { [task.target.project]: selfSource, tags, ...nodes },
31
+ },
32
+ };
33
+ }
34
+ exports.default = run;
35
+ function allDeps(taskId, taskGraph, projectGraph) {
36
+ if (!taskGraph.tasks) {
37
+ return [];
38
+ }
39
+ const project = taskGraph.tasks[taskId].target.project;
40
+ return projectGraph.dependencies[project]
41
+ .filter((d) => !!projectGraph.nodes[d.target])
42
+ .map((d) => d.target);
43
+ }
@@ -0,0 +1,5 @@
1
+ import { ExecutorContext } from '@nx/devkit';
2
+ import type { Schema } from './schema';
3
+ export default function run(options: Schema, context: ExecutorContext): Promise<{
4
+ success: boolean;
5
+ }>;
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ const eslint_utils_1 = require("./utility/eslint-utils");
7
+ async function run(options, context) {
8
+ // this is only used for the hasher
9
+ delete options.hasTypeAwareRules;
10
+ const systemRoot = context.root;
11
+ // eslint resolves files relative to the current working directory.
12
+ // We want these paths to always be resolved relative to the workspace
13
+ // root to be able to run the lint executor from any subfolder.
14
+ process.chdir(systemRoot);
15
+ const projectName = context.projectName || '<???>';
16
+ const printInfo = options.format && !options.silent;
17
+ if (printInfo) {
18
+ console.info(`\nLinting ${JSON.stringify(projectName)}...`);
19
+ }
20
+ /**
21
+ * We want users to have the option of not specifying the config path, and let
22
+ * eslint automatically resolve the `.eslintrc.json` files in each folder.
23
+ */
24
+ let eslintConfigPath = options.eslintConfig
25
+ ? (0, path_1.resolve)(systemRoot, options.eslintConfig)
26
+ : undefined;
27
+ options.cacheLocation = options.cacheLocation
28
+ ? (0, devkit_1.joinPathFragments)(options.cacheLocation, projectName)
29
+ : undefined;
30
+ const { printConfig, ...normalizedOptions } = options;
31
+ /**
32
+ * Until ESLint v9 is released and the new so called flat config is the default
33
+ * we only want to support it if the user has explicitly opted into it by converting
34
+ * their root ESLint config to use eslint.config.js
35
+ */
36
+ const hasFlatConfig = (0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, 'eslint.config.js'));
37
+ if (!eslintConfigPath && hasFlatConfig) {
38
+ const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
39
+ eslintConfigPath = (0, devkit_1.joinPathFragments)(projectRoot, 'eslint.config.js');
40
+ }
41
+ const { eslint, ESLint } = await (0, eslint_utils_1.resolveAndInstantiateESLint)(eslintConfigPath, normalizedOptions, hasFlatConfig);
42
+ const version = ESLint.version?.split('.');
43
+ if (!version ||
44
+ version.length < 2 ||
45
+ Number(version[0]) < 7 ||
46
+ (Number(version[0]) === 7 && Number(version[1]) < 6)) {
47
+ throw new Error('ESLint must be version 7.6 or higher.');
48
+ }
49
+ if (printConfig) {
50
+ try {
51
+ const fileConfig = await eslint.calculateConfigForFile(printConfig);
52
+ console.log(JSON.stringify(fileConfig, null, ' '));
53
+ return {
54
+ success: true,
55
+ };
56
+ }
57
+ catch (err) {
58
+ console.error(err);
59
+ return {
60
+ success: false,
61
+ };
62
+ }
63
+ }
64
+ let lintResults = [];
65
+ try {
66
+ lintResults = await eslint.lintFiles(normalizedOptions.lintFilePatterns);
67
+ }
68
+ catch (err) {
69
+ if (err.message.includes('You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser')) {
70
+ let eslintConfigPathForError = `for ${projectName}`;
71
+ if (context.projectsConfigurations?.projects?.[projectName]?.root) {
72
+ const { root } = context.projectsConfigurations.projects[projectName];
73
+ eslintConfigPathForError = `\`${root}/.eslintrc.json\``;
74
+ }
75
+ console.error(`
76
+ Error: You have attempted to use a lint rule which requires the full TypeScript type-checker to be available, but you do not have \`parserOptions.project\` configured to point at your project tsconfig.json files in the relevant TypeScript file "overrides" block of your project ESLint config ${eslintConfigPath || eslintConfigPathForError}
77
+
78
+ Please see https://nx.dev/guides/eslint for full guidance on how to resolve this issue.
79
+ `);
80
+ return {
81
+ success: false,
82
+ };
83
+ }
84
+ // If some unexpected error, rethrow
85
+ throw err;
86
+ }
87
+ if (lintResults.length === 0) {
88
+ const ignoredPatterns = (await Promise.all(normalizedOptions.lintFilePatterns.map(async (pattern) => (await eslint.isPathIgnored(pattern)) ? pattern : null)))
89
+ .filter((pattern) => !!pattern)
90
+ .map((pattern) => `- '${pattern}'`);
91
+ if (ignoredPatterns.length) {
92
+ const ignoreSection = hasFlatConfig
93
+ ? `'ignores' configuration`
94
+ : `'.eslintignore' file`;
95
+ throw new Error(`All files matching the following patterns are ignored:\n${ignoredPatterns.join('\n')}\n\nPlease check your ${ignoreSection}.`);
96
+ }
97
+ throw new Error('Invalid lint configuration. Nothing to lint. Please check your lint target pattern(s).');
98
+ }
99
+ // output fixes to disk, if applicable based on the options
100
+ await ESLint.outputFixes(lintResults);
101
+ // if quiet, only show errors
102
+ if (normalizedOptions.quiet) {
103
+ console.debug('Quiet mode enabled - filtering out warnings\n');
104
+ lintResults = ESLint.getErrorResults(lintResults);
105
+ }
106
+ const formatter = await eslint.loadFormatter(normalizedOptions.format);
107
+ let totalErrors = 0;
108
+ let totalWarnings = 0;
109
+ for (const result of lintResults) {
110
+ if (result.errorCount || result.warningCount) {
111
+ totalErrors += result.errorCount;
112
+ totalWarnings += result.warningCount;
113
+ }
114
+ }
115
+ const formattedResults = await formatter.format(lintResults);
116
+ if (normalizedOptions.outputFile) {
117
+ const pathToOutputFile = (0, devkit_1.joinPathFragments)(context.root, normalizedOptions.outputFile);
118
+ (0, fs_1.mkdirSync)((0, path_1.dirname)(pathToOutputFile), { recursive: true });
119
+ (0, fs_1.writeFileSync)(pathToOutputFile, formattedResults);
120
+ }
121
+ else {
122
+ console.info(formattedResults);
123
+ }
124
+ if (totalWarnings > 0 && printInfo) {
125
+ console.warn('Lint warnings found in the listed files.\n');
126
+ }
127
+ if (totalErrors > 0 && printInfo) {
128
+ console.error('Lint errors found in the listed files.\n');
129
+ }
130
+ if (totalWarnings === 0 && totalErrors === 0 && printInfo) {
131
+ console.info('All files pass linting.\n');
132
+ }
133
+ return {
134
+ success: normalizedOptions.force ||
135
+ (totalErrors === 0 &&
136
+ (normalizedOptions.maxWarnings === -1 ||
137
+ totalWarnings <= normalizedOptions.maxWarnings)),
138
+ };
139
+ }
140
+ exports.default = run;
@@ -0,0 +1,39 @@
1
+ import type { JsonObject } from '@angular-devkit/core';
2
+ import type { Linter } from 'eslint';
3
+
4
+ export interface Schema extends JsonObject {
5
+ eslintConfig: string | null;
6
+ lintFilePatterns: string[];
7
+ format: Formatter;
8
+ force: boolean;
9
+ silent: boolean;
10
+ fix: boolean;
11
+ cache: boolean;
12
+ noEslintrc: boolean;
13
+ outputFile: string | null;
14
+ cacheLocation: string | null;
15
+ maxWarnings: number;
16
+ quiet: boolean;
17
+ ignorePath: string | null;
18
+ hasTypeAwareRules: boolean;
19
+ cacheStrategy: 'content' | 'metadata' | null;
20
+ rulesdir: string[];
21
+ resolvePluginsRelativeTo: string | null;
22
+ reportUnusedDisableDirectives: Linter.StringSeverity | null;
23
+ printConfig?: string | null;
24
+ }
25
+
26
+ type Formatter =
27
+ | 'stylish'
28
+ | 'compact'
29
+ | 'codeframe'
30
+ | 'unix'
31
+ | 'visualstudio'
32
+ | 'table'
33
+ | 'checkstyle'
34
+ | 'html'
35
+ | 'jslint-xml'
36
+ | 'json'
37
+ | 'json-with-metadata'
38
+ | 'junit'
39
+ | 'tap';
@@ -0,0 +1,144 @@
1
+ {
2
+ "version": 2,
3
+ "outputCapture": "direct-nodejs",
4
+ "$schema": "http://json-schema.org/schema",
5
+ "title": "ESLint Lint Target",
6
+ "description": "ESLint Lint Target.",
7
+ "cli": "nx",
8
+ "type": "object",
9
+ "properties": {
10
+ "eslintConfig": {
11
+ "type": "string",
12
+ "description": "The name of the ESLint configuration file.",
13
+ "x-completion-type": "file",
14
+ "x-completion-glob": ".eslintrc?(.json)",
15
+ "x-priority": "important"
16
+ },
17
+ "lintFilePatterns": {
18
+ "type": "array",
19
+ "description": "One or more files/dirs/globs to pass directly to ESLint's `lintFiles()` method.",
20
+ "default": [],
21
+ "items": {
22
+ "type": "string"
23
+ }
24
+ },
25
+ "format": {
26
+ "type": "string",
27
+ "description": "ESLint Output formatter (https://eslint.org/docs/user-guide/formatters).",
28
+ "default": "stylish",
29
+ "anyOf": [
30
+ {
31
+ "enum": [
32
+ "stylish",
33
+ "compact",
34
+ "codeframe",
35
+ "unix",
36
+ "visualstudio",
37
+ "table",
38
+ "checkstyle",
39
+ "html",
40
+ "jslint-xml",
41
+ "json",
42
+ "json-with-metadata",
43
+ "junit",
44
+ "tap"
45
+ ]
46
+ },
47
+ {
48
+ "minLength": 1
49
+ }
50
+ ],
51
+ "x-priority": "important"
52
+ },
53
+ "force": {
54
+ "type": "boolean",
55
+ "description": "Succeeds even if there was linting errors.",
56
+ "default": false
57
+ },
58
+ "silent": {
59
+ "type": "boolean",
60
+ "description": "Hide output text.",
61
+ "default": false
62
+ },
63
+ "fix": {
64
+ "type": "boolean",
65
+ "description": "Fixes linting errors (may overwrite linted files).",
66
+ "default": false,
67
+ "x-priority": "important"
68
+ },
69
+ "cache": {
70
+ "type": "boolean",
71
+ "description": "Only check changed files.",
72
+ "default": false
73
+ },
74
+ "cacheLocation": {
75
+ "type": "string",
76
+ "description": "Path to the cache file or directory.",
77
+ "x-completion-type": "directory",
78
+ "x-completion-glob": "tsconfig.*.json"
79
+ },
80
+ "outputFile": {
81
+ "type": "string",
82
+ "description": "File to write report to.",
83
+ "x-completion-type": "file"
84
+ },
85
+ "maxWarnings": {
86
+ "type": "number",
87
+ "description": "Number of warnings to trigger nonzero exit code - default: `-1`.",
88
+ "default": -1
89
+ },
90
+ "quiet": {
91
+ "type": "boolean",
92
+ "description": "Report errors only - default: `false`.",
93
+ "default": false,
94
+ "x-priority": "important"
95
+ },
96
+ "ignorePath": {
97
+ "type": "string",
98
+ "description": "The path of the `.eslintignore` file. Not supported for Flat Config.",
99
+ "x-completion-type": "file",
100
+ "x-completion-glob": ".eslintignore"
101
+ },
102
+ "noEslintrc": {
103
+ "type": "boolean",
104
+ "description": "The equivalent of the `--no-eslintrc` flag on the ESLint CLI, it is `false` by default.",
105
+ "default": false
106
+ },
107
+ "hasTypeAwareRules": {
108
+ "type": "boolean",
109
+ "description": "When set to `true`, the linter will invalidate its cache when any of its dependencies changes."
110
+ },
111
+ "cacheStrategy": {
112
+ "type": "string",
113
+ "description": "Strategy to use for detecting changed files in the cache.",
114
+ "default": "metadata",
115
+ "enum": ["metadata", "content"]
116
+ },
117
+ "rulesdir": {
118
+ "type": "array",
119
+ "description": "The equivalent of the `--rulesdir` flag on the ESLint CLI.",
120
+ "default": [],
121
+ "items": {
122
+ "type": "string",
123
+ "x-completion-type": "directory"
124
+ }
125
+ },
126
+ "resolvePluginsRelativeTo": {
127
+ "type": "string",
128
+ "description": "The equivalent of the `--resolve-plugins-relative-to` flag on the ESLint CLI. Not supported for Flat Config.",
129
+ "x-completion-type": "directory"
130
+ },
131
+ "reportUnusedDisableDirectives": {
132
+ "type": "string",
133
+ "enum": ["off", "warn", "error"],
134
+ "description": "The equivalent of the `--report-unused-disable-directives` flag on the ESLint CLI."
135
+ },
136
+ "printConfig": {
137
+ "type": "string",
138
+ "description": "The equivalent of the `--print-config` flag on the ESLint CLI.",
139
+ "x-completion-type": "file"
140
+ }
141
+ },
142
+ "required": ["lintFilePatterns"],
143
+ "examplesFile": "../../../docs/eslint-examples.md"
144
+ }
@@ -0,0 +1,6 @@
1
+ import type { ESLint } from 'eslint';
2
+ import type { Schema } from '../schema';
3
+ export declare function resolveAndInstantiateESLint(eslintConfigPath: string | undefined, options: Schema, useFlatConfig?: boolean): Promise<{
4
+ ESLint: typeof import("eslint").ESLint;
5
+ eslint: ESLint;
6
+ }>;