@angular-eslint/schematics 18.2.1-alpha.6 → 18.2.1-alpha.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.
- package/dist/add-eslint-to-project/index.d.ts +3 -2
- package/dist/add-eslint-to-project/index.d.ts.map +1 -1
- package/dist/add-eslint-to-project/index.js +18 -13
- package/dist/application/index.d.ts +3 -2
- package/dist/application/index.d.ts.map +1 -1
- package/dist/application/index.js +21 -12
- package/dist/library/index.d.ts +3 -2
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js +21 -12
- package/dist/migrations/update-12-0-0/update-12-0-0.d.ts.map +1 -1
- package/dist/migrations/update-12-0-0/update-12-0-0.js +1 -1
- package/dist/migrations/update-2-0-0/update-2-0-0.d.ts.map +1 -1
- package/dist/migrations/update-3-0-0/update-3-0-0.d.ts.map +1 -1
- package/dist/utils.d.ts +4 -5
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +94 -71
- package/package.json +3 -5
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { Rule } from '@angular-devkit/schematics';
|
|
1
2
|
interface Schema {
|
|
2
3
|
project?: string;
|
|
3
4
|
setParserOptionsProject?: boolean;
|
|
4
5
|
}
|
|
5
|
-
|
|
6
|
-
export
|
|
6
|
+
export default function addESLintToProject(schema: Schema): Rule;
|
|
7
|
+
export {};
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/add-eslint-to-project/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/add-eslint-to-project/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAQ,MAAM,4BAA4B,CAAC;AAQ7D,UAAU,MAAM;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;AAED,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAuB/D"}
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
exports.default = addESLintToProject;
|
|
4
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
4
5
|
const utils_1 = require("../utils");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
function addESLintToProject(schema) {
|
|
7
|
+
return (tree) => {
|
|
8
|
+
const projectName = (0, utils_1.determineTargetProjectName)(tree, schema.project);
|
|
9
|
+
if (!projectName) {
|
|
10
|
+
throw new Error('\n' +
|
|
11
|
+
`
|
|
10
12
|
Error: You must specify a project to add ESLint to because you have multiple projects in your angular.json
|
|
11
13
|
|
|
12
14
|
E.g. npx ng g @angular-eslint/schematics:add-eslint-to-project {{YOUR_PROJECT_NAME_GOES_HERE}}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
`.trim());
|
|
16
|
+
}
|
|
17
|
+
return (0, schematics_1.chain)([
|
|
18
|
+
// Create the ESLint config file for the project
|
|
19
|
+
(0, utils_1.createESLintConfigForProject)(projectName, schema.setParserOptionsProject ?? false),
|
|
20
|
+
// Set the lint builder and config in angular.json
|
|
21
|
+
(0, utils_1.addESLintTargetToProject)(projectName, 'lint'),
|
|
22
|
+
]);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Rule } from '@angular-devkit/schematics';
|
|
1
2
|
/**
|
|
2
3
|
* We are able to use the full, unaltered Schema directly from @schematics/angular
|
|
3
4
|
* The applicable json file is copied from node_modules as a prebuiid step to ensure
|
|
@@ -7,6 +8,6 @@ import type { Schema as AngularSchema } from '@schematics/angular/application/sc
|
|
|
7
8
|
interface Schema extends AngularSchema {
|
|
8
9
|
setParserOptionsProject?: boolean;
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
export
|
|
11
|
+
export default function (options: Schema): Rule;
|
|
12
|
+
export {};
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/application/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/application/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAA0B,MAAM,4BAA4B,CAAC;AAE/E;;;;GAIG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAMtF,UAAU,MAAO,SAAQ,aAAa;IACpC,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;AAcD,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,MAAM,GAAG,IAAI,CAW9C"}
|
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
exports.default = default_1;
|
|
4
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
4
5
|
const utils_1 = require("../utils");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
(
|
|
15
|
-
|
|
6
|
+
function eslintRelatedChanges(options) {
|
|
7
|
+
return (0, schematics_1.chain)([
|
|
8
|
+
// Create the ESLint config file for the project
|
|
9
|
+
(0, utils_1.createESLintConfigForProject)(options.name, options.setParserOptionsProject ?? false),
|
|
10
|
+
// Update the lint builder and config in angular.json
|
|
11
|
+
(0, utils_1.addESLintTargetToProject)(options.name, 'lint'),
|
|
12
|
+
]);
|
|
13
|
+
}
|
|
14
|
+
function default_1(options) {
|
|
15
|
+
return (host, context) => {
|
|
16
|
+
// Remove angular-eslint specific options before passing to the Angular schematic
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18
|
+
const { setParserOptionsProject, ...angularOptions } = options;
|
|
19
|
+
return (0, schematics_1.chain)([
|
|
20
|
+
(0, schematics_1.externalSchematic)('@schematics/angular', 'application', angularOptions),
|
|
21
|
+
eslintRelatedChanges(options),
|
|
22
|
+
])(host, context);
|
|
23
|
+
};
|
|
24
|
+
}
|
package/dist/library/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Rule } from '@angular-devkit/schematics';
|
|
1
2
|
/**
|
|
2
3
|
* We are able to use the full, unaltered Schema directly from @schematics/angular
|
|
3
4
|
* The applicable json file is copied from node_modules as a prebuiid step to ensure
|
|
@@ -7,6 +8,6 @@ import type { Schema as AngularSchema } from '@schematics/angular/library/schema
|
|
|
7
8
|
interface Schema extends AngularSchema {
|
|
8
9
|
setParserOptionsProject?: boolean;
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
export
|
|
11
|
+
export default function (options: Schema): Rule;
|
|
12
|
+
export {};
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/library/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/library/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAA0B,MAAM,4BAA4B,CAAC;AAE/E;;;;GAIG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAMlF,UAAU,MAAO,SAAQ,aAAa;IACpC,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;AAcD,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,MAAM,GAAG,IAAI,CAW9C"}
|
package/dist/library/index.js
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
exports.default = default_1;
|
|
4
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
4
5
|
const utils_1 = require("../utils");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
(
|
|
15
|
-
|
|
6
|
+
function eslintRelatedChanges(options) {
|
|
7
|
+
return (0, schematics_1.chain)([
|
|
8
|
+
// Create the ESLint config file for the project
|
|
9
|
+
(0, utils_1.createESLintConfigForProject)(options.name, options.setParserOptionsProject ?? false),
|
|
10
|
+
// Update the lint builder and config in angular.json
|
|
11
|
+
(0, utils_1.addESLintTargetToProject)(options.name, 'lint'),
|
|
12
|
+
]);
|
|
13
|
+
}
|
|
14
|
+
function default_1(options) {
|
|
15
|
+
return (host, context) => {
|
|
16
|
+
// Remove angular-eslint specific options before passing to the Angular schematic
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18
|
+
const { setParserOptionsProject, ...angularOptions } = options;
|
|
19
|
+
return (0, schematics_1.chain)([
|
|
20
|
+
(0, schematics_1.externalSchematic)('@schematics/angular', 'library', angularOptions),
|
|
21
|
+
eslintRelatedChanges(options),
|
|
22
|
+
])(host, context);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-12-0-0.d.ts","sourceRoot":"","sources":["../../../src/migrations/update-12-0-0/update-12-0-0.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"update-12-0-0.d.ts","sourceRoot":"","sources":["../../../src/migrations/update-12-0-0/update-12-0-0.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AA6FvD,MAAM,CAAC,OAAO,UAAU,SAAS,IAAI,IAAI,CAuCxC"}
|
|
@@ -18,7 +18,7 @@ function migrateToAccessibilityLabelHasAssociatedControlSchema(rule) {
|
|
|
18
18
|
}),
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
function migrateFromAccessibilityLabelFor({ overrides, rules }) {
|
|
21
|
+
function migrateFromAccessibilityLabelFor({ overrides, rules, }) {
|
|
22
22
|
migrateToAccessibilityLabelHasAssociatedControlSchema(rules?.['@angular-eslint/template/accessibility-label-for']);
|
|
23
23
|
migrateToAccessibilityLabelHasAssociatedControlName(rules);
|
|
24
24
|
for (const override of overrides ?? []) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-2-0-0.d.ts","sourceRoot":"","sources":["../../../src/migrations/update-2-0-0/update-2-0-0.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAA0B,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"update-2-0-0.d.ts","sourceRoot":"","sources":["../../../src/migrations/update-2-0-0/update-2-0-0.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAA0B,MAAM,4BAA4B,CAAC;AAgG/E,MAAM,CAAC,OAAO,cAAc,IAAI,CAE/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-3-0-0.d.ts","sourceRoot":"","sources":["../../../src/migrations/update-3-0-0/update-3-0-0.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAA0B,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"update-3-0-0.d.ts","sourceRoot":"","sources":["../../../src/migrations/update-3-0-0/update-3-0-0.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAA0B,MAAM,4BAA4B,CAAC;AA2I/E,MAAM,CAAC,OAAO,cAAc,IAAI,CAM/B"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Path } from '@angular-devkit/core';
|
|
2
2
|
import type { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
|
|
3
|
-
import type { Tree as NxTree } from './devkit-imports';
|
|
4
3
|
/**
|
|
5
4
|
* This method is specifically for reading JSON files in a Tree
|
|
6
5
|
* @param host The host tree
|
|
@@ -24,7 +23,7 @@ export declare function getTargetsConfigFromProject(projectConfig: {
|
|
|
24
23
|
} & {
|
|
25
24
|
targets?: TargetsConfig;
|
|
26
25
|
}): TargetsConfig | null;
|
|
27
|
-
export declare function addESLintTargetToProject(
|
|
26
|
+
export declare function addESLintTargetToProject(projectName: string, targetName: 'eslint' | 'lint'): Rule;
|
|
28
27
|
/**
|
|
29
28
|
* Utility to act on all files in a tree that are not ignored by git.
|
|
30
29
|
*/
|
|
@@ -53,13 +52,13 @@ export declare function createRootESLintConfig(prefix: string | null): {
|
|
|
53
52
|
}[];
|
|
54
53
|
};
|
|
55
54
|
export declare function createStringifiedRootESLintConfig(prefix: string | null): string;
|
|
56
|
-
export declare function createESLintConfigForProject(
|
|
55
|
+
export declare function createESLintConfigForProject(projectName: string, setParserOptionsProject: boolean): Rule;
|
|
57
56
|
export declare function sortObjectByKeys(obj: Record<string, unknown>): Record<string, unknown>;
|
|
58
57
|
/**
|
|
59
58
|
* To make certain schematic usage conversion more ergonomic, if the user does not specify a project
|
|
60
59
|
* and only has a single project in their angular.json we will just go ahead and use that one.
|
|
61
60
|
*/
|
|
62
|
-
export declare function determineTargetProjectName(tree:
|
|
61
|
+
export declare function determineTargetProjectName(tree: Tree, maybeProject?: string): string | null;
|
|
63
62
|
/**
|
|
64
63
|
* See `schematicCollections` docs here:
|
|
65
64
|
* https://github.com/angular/angular-cli/blob/8431b3f0769b5f95b9e13807a09293d820c4b017/docs/specifications/schematic-collections-config.md
|
|
@@ -72,6 +71,6 @@ export declare function updateSchematicDefaults(angularJson: Record<string, any>
|
|
|
72
71
|
* - their existing files
|
|
73
72
|
* - their eslint version
|
|
74
73
|
*/
|
|
75
|
-
export declare function shouldUseFlatConfig(tree:
|
|
74
|
+
export declare function shouldUseFlatConfig(tree: Tree, existingJson?: Record<string, unknown>): boolean;
|
|
76
75
|
export {};
|
|
77
76
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAS/E;;;;;GAKG;AAEH,wBAAgB,cAAc,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CAcnE;AAED;;;;;GAKG;AAEH,wBAAgB,gBAAgB,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,EAC7C,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,gBAAgB,KAAK,CAAC,GAClD,IAAI,CAYN;AAED,KAAK,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAE3E,wBAAgB,2BAA2B,CACzC,aAAa,EAAE;IAAE,SAAS,CAAC,EAAE,aAAa,CAAA;CAAE,GAAG;IAAE,OAAO,CAAC,EAAE,aAAa,CAAA;CAAE,GACzE,aAAa,GAAG,IAAI,CAYtB;AA6BD,wBAAgB,wBAAwB,CACtC,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,QAAQ,GAAG,MAAM,GAC5B,IAAI,CA2CN;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,gBAAgB,KAAK,IAAI,GAAG,IAAI,EAC3E,GAAG,GAAE,IAAoB,GACxB,IAAI,CA8BN;AA0BD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;;;;;;;;;;;;;;;;;;;;;;EAyC3D;AAGD,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,MAAM,CAiDR;AAiGD,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,MAAM,EACnB,uBAAuB,EAAE,OAAO,GAC/B,IAAI,CA+DN;AAoBD,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASzB;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,IAAI,EACV,YAAY,CAAC,EAAE,MAAM,GACpB,MAAM,GAAG,IAAI,CAUf;AAcD;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,uBAS1E;AAED,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAChC,iBAAiB,EAAE,MAAM,EACzB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,uBAUvC;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,IAAI,EACV,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACrC,OAAO,CA4BT"}
|
package/dist/utils.js
CHANGED
|
@@ -21,7 +21,6 @@ const schematics_1 = require("@angular-devkit/schematics");
|
|
|
21
21
|
const ignore_1 = __importDefault(require("ignore"));
|
|
22
22
|
const semver_1 = __importDefault(require("semver"));
|
|
23
23
|
const strip_json_comments_1 = __importDefault(require("strip-json-comments"));
|
|
24
|
-
const devkit_imports_1 = require("./devkit-imports");
|
|
25
24
|
const DEFAULT_PREFIX = 'app';
|
|
26
25
|
/**
|
|
27
26
|
* This method is specifically for reading JSON files in a Tree
|
|
@@ -72,48 +71,58 @@ function getTargetsConfigFromProject(projectConfig) {
|
|
|
72
71
|
}
|
|
73
72
|
return null;
|
|
74
73
|
}
|
|
74
|
+
function offsetFromRoot(fullPathToSourceDir) {
|
|
75
|
+
const parts = (0, core_1.normalize)(fullPathToSourceDir).split('/');
|
|
76
|
+
let offset = '';
|
|
77
|
+
for (let i = 0; i < parts.length; ++i) {
|
|
78
|
+
offset += '../';
|
|
79
|
+
}
|
|
80
|
+
return offset;
|
|
81
|
+
}
|
|
75
82
|
function serializeJson(json) {
|
|
76
83
|
return `${JSON.stringify(json, null, 2)}\n`;
|
|
77
84
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
angularJSON.projects[projectName] = projectConfig;
|
|
85
|
-
(0, devkit_imports_1.writeJson)(tree, 'angular.json', angularJSON);
|
|
86
|
-
}
|
|
87
|
-
function addESLintTargetToProject(tree, projectName, targetName) {
|
|
88
|
-
const existingProjectConfig = readProjectConfiguration(tree, projectName);
|
|
89
|
-
let lintFilePatternsRoot = '';
|
|
90
|
-
// Default Angular CLI project at the root of the workspace
|
|
91
|
-
if (existingProjectConfig.root === '') {
|
|
92
|
-
lintFilePatternsRoot = existingProjectConfig.sourceRoot || 'src';
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
lintFilePatternsRoot = existingProjectConfig.root;
|
|
96
|
-
}
|
|
97
|
-
const eslintTargetConfig = {
|
|
98
|
-
builder: '@angular-eslint/builder:lint',
|
|
99
|
-
options: {
|
|
100
|
-
lintFilePatterns: [
|
|
101
|
-
`${lintFilePatternsRoot}/**/*.ts`,
|
|
102
|
-
`${lintFilePatternsRoot}/**/*.html`,
|
|
103
|
-
],
|
|
104
|
-
},
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
|
+
function updateWorkspaceInTree(callback) {
|
|
87
|
+
return (host, context) => {
|
|
88
|
+
const path = 'angular.json';
|
|
89
|
+
host.overwrite(path, serializeJson(callback(readJsonInTree(host, path), context, host)));
|
|
90
|
+
return host;
|
|
105
91
|
};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
92
|
+
}
|
|
93
|
+
function addESLintTargetToProject(projectName, targetName) {
|
|
94
|
+
return updateWorkspaceInTree((workspaceJson, _, tree) => {
|
|
95
|
+
const existingProjectConfig = workspaceJson.projects[projectName];
|
|
96
|
+
let lintFilePatternsRoot = '';
|
|
97
|
+
// Default Angular CLI project at the root of the workspace
|
|
98
|
+
if (existingProjectConfig.root === '') {
|
|
99
|
+
lintFilePatternsRoot = existingProjectConfig.sourceRoot || 'src';
|
|
111
100
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
101
|
+
else {
|
|
102
|
+
lintFilePatternsRoot = existingProjectConfig.root;
|
|
103
|
+
}
|
|
104
|
+
const eslintTargetConfig = {
|
|
105
|
+
builder: '@angular-eslint/builder:lint',
|
|
106
|
+
options: {
|
|
107
|
+
lintFilePatterns: [
|
|
108
|
+
`${lintFilePatternsRoot}/**/*.ts`,
|
|
109
|
+
`${lintFilePatternsRoot}/**/*.html`,
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
let eslintConfig;
|
|
114
|
+
if (existingProjectConfig.root !== '') {
|
|
115
|
+
const flatConfigPath = (0, core_1.join)(existingProjectConfig.root, 'eslint.config.js');
|
|
116
|
+
if (tree.exists(flatConfigPath)) {
|
|
117
|
+
eslintConfig = flatConfigPath;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// TODO: fix
|
|
121
|
+
eslintTargetConfig.options.eslintConfig = eslintConfig;
|
|
122
|
+
existingProjectConfig.architect = existingProjectConfig.architect || {};
|
|
123
|
+
existingProjectConfig.architect[targetName] = eslintTargetConfig;
|
|
124
|
+
return workspaceJson;
|
|
125
|
+
});
|
|
117
126
|
}
|
|
118
127
|
/**
|
|
119
128
|
* Utility to act on all files in a tree that are not ignored by git.
|
|
@@ -255,7 +264,7 @@ module.exports = tseslint.config(
|
|
|
255
264
|
}
|
|
256
265
|
function createProjectESLintConfig(projectRoot, projectType, prefix, setParserOptionsProject, hasE2e) {
|
|
257
266
|
return {
|
|
258
|
-
extends: `${
|
|
267
|
+
extends: `${offsetFromRoot(projectRoot)}.eslintrc.json`,
|
|
259
268
|
ignorePatterns: ['!**/*'],
|
|
260
269
|
overrides: [
|
|
261
270
|
{
|
|
@@ -288,7 +297,7 @@ function createProjectESLintConfig(projectRoot, projectType, prefix, setParserOp
|
|
|
288
297
|
function createStringifiedProjectESLintConfig(projectRoot, projectType, prefix, setParserOptionsProject, hasE2e) {
|
|
289
298
|
return `// @ts-check
|
|
290
299
|
const tseslint = require("typescript-eslint");
|
|
291
|
-
const rootConfig = require("${
|
|
300
|
+
const rootConfig = require("${offsetFromRoot(projectRoot)}eslint.config.js");
|
|
292
301
|
|
|
293
302
|
module.exports = tseslint.config(
|
|
294
303
|
...rootConfig,
|
|
@@ -327,37 +336,42 @@ module.exports = tseslint.config(
|
|
|
327
336
|
);
|
|
328
337
|
`;
|
|
329
338
|
}
|
|
330
|
-
function createESLintConfigForProject(
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
339
|
+
function createESLintConfigForProject(projectName, setParserOptionsProject) {
|
|
340
|
+
return (tree) => {
|
|
341
|
+
const angularJSON = readJsonInTree(tree, 'angular.json');
|
|
342
|
+
const { root: projectRoot, projectType, prefix, } = angularJSON.projects[projectName];
|
|
343
|
+
const hasE2e = determineTargetProjectHasE2E(angularJSON, projectName);
|
|
344
|
+
const useFlatConfig = shouldUseFlatConfig(tree);
|
|
345
|
+
const alreadyHasRootFlatConfig = tree.exists('eslint.config.js');
|
|
346
|
+
const alreadyHasRootESLintRC = tree.exists('.eslintrc.json');
|
|
347
|
+
/**
|
|
348
|
+
* If the root is an empty string it must be the initial project created at the
|
|
349
|
+
* root by the Angular CLI's workspace schematic
|
|
350
|
+
*/
|
|
351
|
+
if (projectRoot === '') {
|
|
352
|
+
return createRootESLintConfigFile(prefix || DEFAULT_PREFIX, useFlatConfig);
|
|
353
|
+
}
|
|
354
|
+
const rules = [];
|
|
355
|
+
// If, for whatever reason, the root eslint.config.js/.eslintrc.json doesn't exist yet, create it
|
|
356
|
+
if (!alreadyHasRootESLintRC && !alreadyHasRootFlatConfig) {
|
|
357
|
+
rules.push(createRootESLintConfigFile(prefix || DEFAULT_PREFIX, useFlatConfig));
|
|
358
|
+
}
|
|
359
|
+
if (useFlatConfig) {
|
|
360
|
+
rules.push((tree) => tree.create((0, core_1.join)((0, core_1.normalize)(projectRoot), 'eslint.config.js'), createStringifiedProjectESLintConfig(projectRoot, projectType || 'library', prefix || DEFAULT_PREFIX, setParserOptionsProject, hasE2e)));
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
rules.push(updateJsonInTree((0, core_1.join)((0, core_1.normalize)(projectRoot), '.eslintrc.json'), () => createProjectESLintConfig(projectRoot, projectType || 'library', prefix || DEFAULT_PREFIX, setParserOptionsProject, hasE2e)));
|
|
364
|
+
}
|
|
365
|
+
return (0, schematics_1.chain)(rules);
|
|
366
|
+
};
|
|
355
367
|
}
|
|
356
|
-
function createRootESLintConfigFile(
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
368
|
+
function createRootESLintConfigFile(prefix, useFlatConfig) {
|
|
369
|
+
return (tree) => {
|
|
370
|
+
if (useFlatConfig) {
|
|
371
|
+
return tree.create('eslint.config.js', createStringifiedRootESLintConfig(prefix));
|
|
372
|
+
}
|
|
373
|
+
return updateJsonInTree('.eslintrc.json', () => createRootESLintConfig(prefix));
|
|
374
|
+
};
|
|
361
375
|
}
|
|
362
376
|
function sortObjectByKeys(obj) {
|
|
363
377
|
return Object.keys(obj)
|
|
@@ -377,13 +391,22 @@ function determineTargetProjectName(tree, maybeProject) {
|
|
|
377
391
|
if (maybeProject) {
|
|
378
392
|
return maybeProject;
|
|
379
393
|
}
|
|
380
|
-
const workspaceJson = (
|
|
394
|
+
const workspaceJson = readJsonInTree(tree, 'angular.json');
|
|
381
395
|
const projects = Object.keys(workspaceJson.projects);
|
|
382
396
|
if (projects.length === 1) {
|
|
383
397
|
return projects[0];
|
|
384
398
|
}
|
|
385
399
|
return null;
|
|
386
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* Checking if the target project has e2e setup
|
|
403
|
+
* Method will check if angular project architect has e2e configuration to determine if e2e setup
|
|
404
|
+
*/
|
|
405
|
+
function determineTargetProjectHasE2E(
|
|
406
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
|
|
407
|
+
angularJSON, projectName) {
|
|
408
|
+
return !!getTargetsConfigFromProject(angularJSON.projects[projectName])?.e2e;
|
|
409
|
+
}
|
|
387
410
|
/**
|
|
388
411
|
* See `schematicCollections` docs here:
|
|
389
412
|
* https://github.com/angular/angular-cli/blob/8431b3f0769b5f95b9e13807a09293d820c4b017/docs/specifications/schematic-collections-config.md
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-eslint/schematics",
|
|
3
|
-
"version": "18.2.1-alpha.
|
|
3
|
+
"version": "18.2.1-alpha.8",
|
|
4
4
|
"description": "Angular Schematics for angular-eslint",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,11 +36,9 @@
|
|
|
36
36
|
"save": "devDependencies"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@angular-eslint/eslint-plugin": "18.2.1-alpha.
|
|
40
|
-
"@angular-eslint/eslint-plugin-template": "18.2.1-alpha.
|
|
41
|
-
"@nx/devkit": ">= 19.5.4 < 20.0.0",
|
|
39
|
+
"@angular-eslint/eslint-plugin": "18.2.1-alpha.8",
|
|
40
|
+
"@angular-eslint/eslint-plugin-template": "18.2.1-alpha.8",
|
|
42
41
|
"ignore": "5.3.2",
|
|
43
|
-
"nx": "^19.0.6",
|
|
44
42
|
"semver": "7.6.3",
|
|
45
43
|
"strip-json-comments": "3.1.1"
|
|
46
44
|
},
|