@angular-eslint/schematics 15.0.0-alpha.0 → 15.0.0-alpha.2

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.
@@ -4,6 +4,7 @@ const schematics_1 = require("@angular-devkit/schematics");
4
4
  const utils_1 = require("../utils");
5
5
  function addESLintToProject(schema) {
6
6
  return (tree) => {
7
+ var _a;
7
8
  const projectName = (0, utils_1.determineTargetProjectName)(tree, schema.project);
8
9
  if (!projectName) {
9
10
  throw new Error('\n' +
@@ -17,7 +18,7 @@ E.g. npx ng g @angular-eslint/schematics:add-eslint-to-project {{YOUR_PROJECT_NA
17
18
  // Set the lint builder and config in angular.json
18
19
  (0, utils_1.addESLintTargetToProject)(projectName, 'lint'),
19
20
  // Create the ESLint config file for the project
20
- (0, utils_1.createESLintConfigForProject)(projectName),
21
+ (0, utils_1.createESLintConfigForProject)(projectName, (_a = schema.setParserOptionsProject) !== null && _a !== void 0 ? _a : false),
21
22
  ]);
22
23
  };
23
24
  }
@@ -11,6 +11,11 @@
11
11
  "$source": "argv",
12
12
  "index": 0
13
13
  }
14
+ },
15
+ "setParserOptionsProject": {
16
+ "type": "boolean",
17
+ "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
18
+ "default": false
14
19
  }
15
20
  },
16
21
  "required": []
@@ -1,21 +1,36 @@
1
1
  "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  const schematics_1 = require("@angular-devkit/schematics");
4
15
  const utils_1 = require("../utils");
5
16
  function eslintRelatedChanges(options) {
17
+ var _a;
6
18
  return (0, schematics_1.chain)([
7
19
  // Update the lint builder and config in angular.json
8
20
  (0, utils_1.addESLintTargetToProject)(options.name, 'lint'),
9
21
  // Create the ESLint config file for the project
10
- (0, utils_1.createESLintConfigForProject)(options.name),
22
+ (0, utils_1.createESLintConfigForProject)(options.name, (_a = options.setParserOptionsProject) !== null && _a !== void 0 ? _a : false),
11
23
  // Delete the TSLint config file for the project
12
24
  (0, utils_1.removeTSLintJSONForProject)(options.name),
13
25
  ]);
14
26
  }
15
27
  function default_1(options) {
16
28
  return (host, context) => {
29
+ // Remove angular-eslint specific options before passing to the Angular schematic
30
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
31
+ const { setParserOptionsProject } = options, angularOptions = __rest(options, ["setParserOptionsProject"]);
17
32
  return (0, schematics_1.chain)([
18
- (0, schematics_1.externalSchematic)('@schematics/angular', 'application', options),
33
+ (0, schematics_1.externalSchematic)('@schematics/angular', 'application', angularOptions),
19
34
  eslintRelatedChanges(options),
20
35
  ])(host, context);
21
36
  };
@@ -60,7 +60,10 @@
60
60
  "message": "Which stylesheet format would you like to use?",
61
61
  "type": "list",
62
62
  "items": [
63
- { "value": "css", "label": "CSS" },
63
+ {
64
+ "value": "css",
65
+ "label": "CSS"
66
+ },
64
67
  {
65
68
  "value": "scss",
66
69
  "label": "SCSS [ https://sass-lang.com/documentation/syntax#scss ]"
@@ -102,6 +105,11 @@
102
105
  "description": "Creates an application with stricter bundle budgets settings.",
103
106
  "type": "boolean",
104
107
  "default": true
108
+ },
109
+ "setParserOptionsProject": {
110
+ "type": "boolean",
111
+ "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
112
+ "default": false
105
113
  }
106
114
  },
107
115
  "required": ["name"]
@@ -47,7 +47,7 @@ E.g. npx ng g @angular-eslint/schematics:convert-tslint-to-eslint {{YOUR_PROJECT
47
47
  : schema.ignoreExistingTslintConfig
48
48
  ? (0, schematics_1.chain)([
49
49
  // Create the latest recommended ESLint config file for the project
50
- (0, utils_1.createESLintConfigForProject)(projectName),
50
+ (0, utils_1.createESLintConfigForProject)(projectName, true),
51
51
  // Delete the TSLint config file for the project
52
52
  (0, utils_1.removeTSLintJSONForProject)(projectName),
53
53
  ])
@@ -1,26 +1,36 @@
1
1
  "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  const schematics_1 = require("@angular-devkit/schematics");
4
15
  const utils_1 = require("../utils");
5
16
  function eslintRelatedChanges(options) {
6
- /**
7
- * The types coming from the @schematics/angular schema seem to be wrong, if name isn't
8
- * provided the interactive CLI prompt will throw
9
- */
10
- const projectName = options.name;
17
+ var _a;
11
18
  return (0, schematics_1.chain)([
12
19
  // Update the lint builder and config in angular.json
13
- (0, utils_1.addESLintTargetToProject)(projectName, 'lint'),
20
+ (0, utils_1.addESLintTargetToProject)(options.name, 'lint'),
14
21
  // Create the ESLint config file for the project
15
- (0, utils_1.createESLintConfigForProject)(projectName),
22
+ (0, utils_1.createESLintConfigForProject)(options.name, (_a = options.setParserOptionsProject) !== null && _a !== void 0 ? _a : false),
16
23
  // Delete the TSLint config file for the project
17
- (0, utils_1.removeTSLintJSONForProject)(projectName),
24
+ (0, utils_1.removeTSLintJSONForProject)(options.name),
18
25
  ]);
19
26
  }
20
27
  function default_1(options) {
21
28
  return (host, context) => {
29
+ // Remove angular-eslint specific options before passing to the Angular schematic
30
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
31
+ const { setParserOptionsProject } = options, angularOptions = __rest(options, ["setParserOptionsProject"]);
22
32
  return (0, schematics_1.chain)([
23
- (0, schematics_1.externalSchematic)('@schematics/angular', 'library', options),
33
+ (0, schematics_1.externalSchematic)('@schematics/angular', 'library', angularOptions),
24
34
  eslintRelatedChanges(options),
25
35
  ])(host, context);
26
36
  };
@@ -47,6 +47,11 @@
47
47
  "projectRoot": {
48
48
  "type": "string",
49
49
  "description": "The root directory of the new library."
50
+ },
51
+ "setParserOptionsProject": {
52
+ "type": "boolean",
53
+ "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
54
+ "default": false
50
55
  }
51
56
  },
52
57
  "required": ["name"]
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const schematics_1 = require("@angular-devkit/schematics");
4
+ const utils_1 = require("../../utils");
5
+ const dependencies_1 = require("../utils/dependencies");
6
+ const updatedTypeScriptESLintVersion = '5.43.0';
7
+ const updatedESLintVersion = '8.28.0';
8
+ function migration() {
9
+ return (0, schematics_1.chain)([
10
+ (0, dependencies_1.updateDependencies)([
11
+ {
12
+ packageName: '@typescript-eslint/eslint-plugin',
13
+ version: `^${updatedTypeScriptESLintVersion}`,
14
+ },
15
+ {
16
+ packageName: '@typescript-eslint/utils',
17
+ version: `^${updatedTypeScriptESLintVersion}`,
18
+ },
19
+ {
20
+ packageName: '@typescript-eslint/parser',
21
+ version: `^${updatedTypeScriptESLintVersion}`,
22
+ },
23
+ {
24
+ packageName: 'eslint',
25
+ version: `^${updatedESLintVersion}`,
26
+ },
27
+ ]),
28
+ (0, utils_1.updateJsonInTree)('angular.json', (json) => {
29
+ return (0, utils_1.updateSchematicDefaults)(json, '@angular-eslint/schematics:application', {
30
+ setParserOptionsProject: true,
31
+ });
32
+ }),
33
+ (0, utils_1.updateJsonInTree)('angular.json', (json) => {
34
+ return (0, utils_1.updateSchematicDefaults)(json, '@angular-eslint/schematics:library', {
35
+ setParserOptionsProject: true,
36
+ });
37
+ }),
38
+ ]);
39
+ }
40
+ exports.default = migration;
@@ -30,6 +30,11 @@
30
30
  "version": "14.0.0-alpha.0",
31
31
  "description": "Updates @angular-eslint to v14",
32
32
  "factory": "./migrations/update-14-0-0/update-14-0-0"
33
+ },
34
+ "update-15-0-0": {
35
+ "version": "15.0.0-alpha.1",
36
+ "description": "Updates @angular-eslint to v15",
37
+ "factory": "./migrations/update-15-0-0/update-15-0-0"
33
38
  }
34
39
  }
35
40
  }
@@ -73,7 +73,7 @@ function applyESLintConfigIfSingleProjectWithNoExistingTSLint() {
73
73
  const projectNames = Object.keys(angularJson.projects);
74
74
  if (projectNames.length === 0) {
75
75
  return (0, schematics_1.chain)([
76
- (0, utils_1.updateJsonInTree)('.eslintrc.json', () => (0, utils_1.createRootESLintConfig)(null, false)),
76
+ (0, utils_1.updateJsonInTree)('.eslintrc.json', () => (0, utils_1.createRootESLintConfig)(null)),
77
77
  (0, utils_1.updateJsonInTree)('angular.json', (json) => (0, utils_1.updateSchematicCollections)(json)),
78
78
  ]);
79
79
  }
package/dist/utils.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.updateSchematicCollections = exports.determineTargetProjectHasE2E = exports.determineTargetProjectName = exports.sortObjectByKeys = exports.removeTSLintJSONForProject = exports.createESLintConfigForProject = exports.createRootESLintConfig = exports.setESLintProjectBasedOnProjectType = exports.visitNotIgnoredFiles = exports.addESLintTargetToProject = exports.updateWorkspaceInTree = exports.offsetFromRoot = exports.getProjectConfig = exports.isTSLintUsedInWorkspace = exports.getTargetsConfigFromProject = exports.getWorkspacePath = exports.updateJsonInTree = exports.readJsonInTree = void 0;
6
+ exports.updateSchematicDefaults = exports.updateSchematicCollections = exports.determineTargetProjectHasE2E = exports.determineTargetProjectName = exports.sortObjectByKeys = exports.removeTSLintJSONForProject = exports.createESLintConfigForProject = exports.createRootESLintConfig = exports.setESLintProjectBasedOnProjectType = exports.visitNotIgnoredFiles = exports.addESLintTargetToProject = exports.updateWorkspaceInTree = exports.offsetFromRoot = exports.getProjectConfig = exports.isTSLintUsedInWorkspace = exports.getTargetsConfigFromProject = exports.getWorkspacePath = exports.updateJsonInTree = exports.readJsonInTree = void 0;
7
7
  const core_1 = require("@angular-devkit/core");
8
8
  const schematics_1 = require("@angular-devkit/schematics");
9
9
  const ignore_1 = __importDefault(require("ignore"));
@@ -184,26 +184,20 @@ exports.visitNotIgnoredFiles = visitNotIgnoredFiles;
184
184
  function setESLintProjectBasedOnProjectType(projectRoot, projectType, hasE2e) {
185
185
  let project;
186
186
  if (projectType === 'application') {
187
- project = [
188
- `${projectRoot}/tsconfig.app.json`,
189
- `${projectRoot}/tsconfig.spec.json`,
190
- ];
187
+ project = [`${projectRoot}/tsconfig.(app|spec).json`];
191
188
  if (hasE2e) {
192
189
  project.push(`${projectRoot}/e2e/tsconfig.json`);
193
190
  }
194
191
  }
195
192
  // Libraries don't have an e2e directory
196
193
  if (projectType === 'library') {
197
- project = [
198
- `${projectRoot}/tsconfig.lib.json`,
199
- `${projectRoot}/tsconfig.spec.json`,
200
- ];
194
+ project = [`${projectRoot}/tsconfig.(lib|spec).json`];
201
195
  }
202
196
  return project;
203
197
  }
204
198
  exports.setESLintProjectBasedOnProjectType = setESLintProjectBasedOnProjectType;
205
199
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
206
- function createRootESLintConfig(prefix, hasE2e) {
200
+ function createRootESLintConfig(prefix) {
207
201
  let codeRules;
208
202
  if (prefix) {
209
203
  codeRules = {
@@ -226,13 +220,9 @@ function createRootESLintConfig(prefix, hasE2e) {
226
220
  overrides: [
227
221
  {
228
222
  files: ['*.ts'],
229
- parserOptions: {
230
- project: hasE2e
231
- ? ['tsconfig.json', 'e2e/tsconfig.json']
232
- : ['tsconfig.json'],
233
- createDefaultProgram: true,
234
- },
235
223
  extends: [
224
+ 'eslint:recommended',
225
+ 'plugin:@typescript-eslint/recommended',
236
226
  'plugin:@angular-eslint/recommended',
237
227
  'plugin:@angular-eslint/template/process-inline-templates',
238
228
  ],
@@ -247,18 +237,18 @@ function createRootESLintConfig(prefix, hasE2e) {
247
237
  };
248
238
  }
249
239
  exports.createRootESLintConfig = createRootESLintConfig;
250
- function createProjectESLintConfig(rootPath, projectRoot, projectType, prefix, hasE2e) {
240
+ function createProjectESLintConfig(rootPath, projectRoot, projectType, prefix, setParserOptionsProject, hasE2e) {
251
241
  return {
252
242
  extends: `${offsetFromRoot(rootPath)}.eslintrc.json`,
253
243
  ignorePatterns: ['!**/*'],
254
244
  overrides: [
255
- {
256
- files: ['*.ts'],
257
- parserOptions: {
258
- project: setESLintProjectBasedOnProjectType(projectRoot, projectType, hasE2e),
259
- createDefaultProgram: true,
260
- },
261
- rules: {
245
+ Object.assign(Object.assign({ files: ['*.ts'] }, (setParserOptionsProject
246
+ ? {
247
+ parserOptions: {
248
+ project: setESLintProjectBasedOnProjectType(projectRoot, projectType, hasE2e),
249
+ },
250
+ }
251
+ : null)), { rules: {
262
252
  '@angular-eslint/directive-selector': [
263
253
  'error',
264
254
  { type: 'attribute', prefix, style: 'camelCase' },
@@ -267,8 +257,7 @@ function createProjectESLintConfig(rootPath, projectRoot, projectType, prefix, h
267
257
  'error',
268
258
  { type: 'element', prefix, style: 'kebab-case' },
269
259
  ],
270
- },
271
- },
260
+ } }),
272
261
  {
273
262
  files: ['*.html'],
274
263
  rules: {},
@@ -276,7 +265,7 @@ function createProjectESLintConfig(rootPath, projectRoot, projectType, prefix, h
276
265
  ],
277
266
  };
278
267
  }
279
- function createESLintConfigForProject(projectName) {
268
+ function createESLintConfigForProject(projectName, setParserOptionsProject) {
280
269
  return (tree) => {
281
270
  const angularJSON = readJsonInTree(tree, 'angular.json');
282
271
  const { root: projectRoot, projectType, prefix, } = angularJSON.projects[projectName];
@@ -293,7 +282,7 @@ function createESLintConfigForProject(projectName) {
293
282
  tree.exists('.eslintrc.json')
294
283
  ? () => undefined
295
284
  : createRootESLintConfigFile(projectName),
296
- updateJsonInTree((0, core_1.join)((0, core_1.normalize)(projectRoot), '.eslintrc.json'), () => createProjectESLintConfig(tree.root.path, projectRoot, projectType, prefix, hasE2e)),
285
+ updateJsonInTree((0, core_1.join)((0, core_1.normalize)(projectRoot), '.eslintrc.json'), () => createProjectESLintConfig(tree.root.path, projectRoot, projectType, prefix, setParserOptionsProject, hasE2e)),
297
286
  ]);
298
287
  };
299
288
  }
@@ -314,12 +303,11 @@ function createRootESLintConfigFile(projectName) {
314
303
  var _a;
315
304
  const angularJSON = readJsonInTree(tree, getWorkspacePath(tree));
316
305
  let lintPrefix = null;
317
- const hasE2e = determineTargetProjectHasE2E(angularJSON, projectName);
318
306
  if ((_a = angularJSON.projects) === null || _a === void 0 ? void 0 : _a[projectName]) {
319
307
  const { prefix } = angularJSON.projects[projectName];
320
308
  lintPrefix = prefix;
321
309
  }
322
- return updateJsonInTree('.eslintrc.json', () => createRootESLintConfig(lintPrefix, hasE2e));
310
+ return updateJsonInTree('.eslintrc.json', () => createRootESLintConfig(lintPrefix));
323
311
  };
324
312
  }
325
313
  function sortObjectByKeys(obj) {
@@ -372,3 +360,11 @@ function updateSchematicCollections(angularJson) {
372
360
  return angularJson;
373
361
  }
374
362
  exports.updateSchematicCollections = updateSchematicCollections;
363
+ function updateSchematicDefaults(angularJson, schematicFullName, defaultValues) {
364
+ angularJson.schematics = angularJson.schematics || {};
365
+ angularJson.schematics[schematicFullName] =
366
+ angularJson.schematics[schematicFullName] || {};
367
+ angularJson.schematics[schematicFullName] = Object.assign(Object.assign({}, angularJson.schematics[schematicFullName]), defaultValues);
368
+ return angularJson;
369
+ }
370
+ exports.updateSchematicDefaults = updateSchematicDefaults;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-eslint/schematics",
3
- "version": "15.0.0-alpha.0",
3
+ "version": "15.0.0-alpha.2",
4
4
  "description": "Angular Schematics for angular-eslint",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -33,8 +33,8 @@
33
33
  "save": "devDependencies"
34
34
  },
35
35
  "dependencies": {
36
- "@angular-eslint/eslint-plugin": "15.0.0-alpha.0",
37
- "@angular-eslint/eslint-plugin-template": "15.0.0-alpha.0",
36
+ "@angular-eslint/eslint-plugin": "15.0.0-alpha.2",
37
+ "@angular-eslint/eslint-plugin-template": "15.0.0-alpha.2",
38
38
  "ignore": "5.2.0",
39
39
  "strip-json-comments": "3.1.1",
40
40
  "tmp": "0.2.1"
@@ -48,5 +48,5 @@
48
48
  "peerDependencies": {
49
49
  "@angular/cli": ">= 15.0.0 < 16.0.0"
50
50
  },
51
- "gitHead": "333fe1b4c189a5f4ecee216bd5360f428853f50d"
51
+ "gitHead": "ad7d7eaded8cffc89105dde9fc3a4c70020de4a7"
52
52
  }