@angular-eslint/eslint-plugin-template 21.0.1-alpha.2 → 21.0.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"prefer-contextual-for-variables.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-contextual-for-variables.ts"],"names":[],"mappings":"AAoBA,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,QAAQ,CAAC,cAAc,CAAC,EAAE;YACxB,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;YAC3B,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;YAC3B,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;YAC3B,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;YAC1B,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;YAC1B,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;SAC1B,CAAC;KACH;CACF,CAAC;AACF,MAAM,MAAM,UAAU,GAClB,0BAA0B,GAC1B,aAAa,GACb,aAAa,GACb,YAAY,GACZ,YAAY,GACZ,WAAW,CAAC;AAChB,eAAO,MAAM,SAAS,oCAAoC,CAAC;;AAc3D,wBAkaG;AAyOH,eAAO,MAAM,mBAAmB;;CAG/B,CAAC"}
1
+ {"version":3,"file":"prefer-contextual-for-variables.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-contextual-for-variables.ts"],"names":[],"mappings":"AAoBA,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,QAAQ,CAAC,cAAc,CAAC,EAAE;YACxB,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;YAC3B,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;YAC3B,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;YAC3B,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;YAC1B,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;YAC1B,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;SAC1B,CAAC;KACH;CACF,CAAC;AACF,MAAM,MAAM,UAAU,GAClB,0BAA0B,GAC1B,aAAa,GACb,aAAa,GACb,YAAY,GACZ,YAAY,GACZ,WAAW,CAAC;AAChB,eAAO,MAAM,SAAS,oCAAoC,CAAC;;AAc3D,wBAkaG;AAmRH,eAAO,MAAM,mBAAmB;;CAG/B,CAAC"}
@@ -406,17 +406,21 @@ function getAllowedAliases(allowedAliases, variableName) {
406
406
  function getVariableRangeToRemove(problem, sourceCode, variableCount) {
407
407
  let start = problem.variable.sourceSpan.start.offset;
408
408
  let end = problem.variable.sourceSpan.end.offset;
409
- if (variableCount === 1) {
410
- // There's only one variable defined, so we
411
- // want to remove the `let` keyword as well.
412
- const letIndex = getStartOfPreviousToken('let', start, sourceCode);
409
+ // Check if this variable has its own `let` keyword (semicolon-separated)
410
+ // vs being part of a comma-separated list after a single `let`.
411
+ const letIndex = getStartOfPreviousToken('let', start, sourceCode);
412
+ const hasOwnLet = letIndex !== undefined &&
413
+ hasOwnLetKeyword(letIndex, start, end, sourceCode);
414
+ if (variableCount === 1 || hasOwnLet) {
415
+ // Either there's only one variable, or this variable has its own
416
+ // `let` keyword (semicolon-separated), so remove the `let` as well.
413
417
  if (letIndex !== undefined) {
414
418
  // We also want to remove the preceding semicolon.
415
419
  start = getStartOfPreviousToken(';', letIndex, sourceCode) ?? letIndex;
416
420
  }
417
421
  }
418
422
  else if (problem.index === 0) {
419
- // There are multiple variables, but we're removing
423
+ // There are multiple comma-separated variables, and we're removing
420
424
  // the first one. We need to keep the `let` keyword, but
421
425
  // remove the trailing comma and any whitespace after it.
422
426
  const commaIndex = getStartOfNextToken(',', end, sourceCode);
@@ -427,12 +431,40 @@ function getVariableRangeToRemove(problem, sourceCode, variableCount) {
427
431
  }
428
432
  }
429
433
  else {
430
- // There is a variable before this one, so we
434
+ // There is a comma-separated variable before this one, so we
431
435
  // need to remove the preceding comma as well.
432
436
  start = getStartOfPreviousToken(',', start, sourceCode) ?? start;
433
437
  }
434
438
  return [start, end];
435
439
  }
440
+ /**
441
+ * Checks if the `let` keyword at `letIndex` belongs solely to this variable
442
+ * (i.e., this is a semicolon-separated declaration where this variable
443
+ * has its own `let` keyword that isn't shared with other variables).
444
+ *
445
+ * A variable has its own `let` if:
446
+ * 1. It's the first variable after the `let` (no comma before it), AND
447
+ * 2. There are no comma-separated variables after it (next char after
448
+ * the variable is `;` or `)`, not `,`)
449
+ */
450
+ function hasOwnLetKeyword(letIndex, variableStart, variableEnd, sourceCode) {
451
+ const text = sourceCode.text;
452
+ // Check if there's a comma between `let` and the variable start.
453
+ // If there is, this variable is not the first after `let`.
454
+ const betweenLetAndVar = text.slice(letIndex + 3, variableStart);
455
+ if (betweenLetAndVar.includes(',')) {
456
+ return false;
457
+ }
458
+ // This variable is the first after `let`. Now check if there are more
459
+ // comma-separated variables after it. If so, this `let` is shared.
460
+ // Find the next non-whitespace character after the variable.
461
+ let nextIndex = variableEnd;
462
+ while (nextIndex < text.length && /\s/.test(text[nextIndex])) {
463
+ nextIndex++;
464
+ }
465
+ // If the next character is a comma, there are more variables sharing this `let`.
466
+ return text[nextIndex] !== ',';
467
+ }
436
468
  function getStartOfPreviousToken(tokenToFind, startIndex, sourceCode) {
437
469
  const text = sourceCode.text;
438
470
  for (let i = startIndex - tokenToFind.length; i >= 0; i--) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-eslint/eslint-plugin-template",
3
- "version": "21.0.1-alpha.2",
3
+ "version": "21.0.1",
4
4
  "description": "ESLint plugin for Angular Templates",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -20,19 +20,19 @@
20
20
  "dependencies": {
21
21
  "aria-query": "5.3.2",
22
22
  "axobject-query": "4.1.0",
23
- "@angular-eslint/bundled-angular-compiler": "21.0.1-alpha.2",
24
- "@angular-eslint/utils": "21.0.1-alpha.2"
23
+ "@angular-eslint/bundled-angular-compiler": "21.0.1",
24
+ "@angular-eslint/utils": "21.0.1"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/aria-query": "5.0.4",
28
- "@angular-eslint/test-utils": "21.0.1-alpha.2"
28
+ "@angular-eslint/test-utils": "21.0.1"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@typescript-eslint/types": "^7.11.0 || ^8.0.0",
32
32
  "@typescript-eslint/utils": "^7.11.0 || ^8.0.0",
33
33
  "eslint": "^8.57.0 || ^9.0.0",
34
34
  "typescript": "*",
35
- "@angular-eslint/template-parser": "21.0.1-alpha.2"
35
+ "@angular-eslint/template-parser": "21.0.1"
36
36
  },
37
37
  "gitHead": "e2006e5e9c99e5a943d1a999e0efa5247d29ec24"
38
38
  }