@angular-eslint/eslint-plugin-template 19.8.1-alpha.0 → 19.8.1-alpha.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":"conditional-complexity.d.ts","sourceRoot":"","sources":["../../src/rules/conditional-complexity.ts"],"names":[],"mappings":"AAgBA,MAAM,MAAM,OAAO,GAAG,CAAC;IAAE,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAClD,MAAM,MAAM,UAAU,GAAG,uBAAuB,CAAC;AACjD,eAAO,MAAM,SAAS,2BAA2B,CAAC;;AAIlD,wBAkFG"}
1
+ {"version":3,"file":"conditional-complexity.d.ts","sourceRoot":"","sources":["../../src/rules/conditional-complexity.ts"],"names":[],"mappings":"AAiBA,MAAM,MAAM,OAAO,GAAG,CAAC;IAAE,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAClD,MAAM,MAAM,UAAU,GAAG,uBAAuB,CAAC;AACjD,eAAO,MAAM,SAAS,2BAA2B,CAAC;;AAIlD,wBAkFG"}
@@ -4,6 +4,7 @@ exports.RULE_NAME = void 0;
4
4
  const bundled_angular_compiler_1 = require("@angular-eslint/bundled-angular-compiler");
5
5
  const utils_1 = require("@angular-eslint/utils");
6
6
  const create_eslint_rule_1 = require("../utils/create-eslint-rule");
7
+ const unwrap_parenthesized_expression_1 = require("../utils/unwrap-parenthesized-expression");
7
8
  exports.RULE_NAME = 'conditional-complexity';
8
9
  const DEFAULT_MAX_COMPLEXITY = 5;
9
10
  exports.default = (0, create_eslint_rule_1.createESLintRule)({
@@ -74,7 +75,8 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
74
75
  },
75
76
  });
76
77
  function extractPossibleBinaryOrConditionalFrom(node) {
77
- return node instanceof bundled_angular_compiler_1.BindingPipe ? node.exp : node;
78
+ const unwrapped = (0, unwrap_parenthesized_expression_1.unwrapParenthesizedExpression)(node);
79
+ return unwrapped instanceof bundled_angular_compiler_1.BindingPipe ? unwrapped.exp : unwrapped;
78
80
  }
79
81
  let parser = null;
80
82
  // Instantiate the `Parser` class lazily only when this rule is applied.
@@ -89,10 +91,14 @@ function getTotalComplexity(ast) {
89
91
  }
90
92
  let total = 1;
91
93
  if (possibleBinaryOrConditional instanceof bundled_angular_compiler_1.Binary) {
92
- if (possibleBinaryOrConditional.left instanceof bundled_angular_compiler_1.Binary) {
94
+ const leftUnwrapped = (0, unwrap_parenthesized_expression_1.unwrapParenthesizedExpression)(possibleBinaryOrConditional.left);
95
+ const rightUnwrapped = (0, unwrap_parenthesized_expression_1.unwrapParenthesizedExpression)(possibleBinaryOrConditional.right);
96
+ if (leftUnwrapped instanceof bundled_angular_compiler_1.Binary ||
97
+ leftUnwrapped instanceof bundled_angular_compiler_1.Conditional) {
93
98
  total += getTotalComplexity(possibleBinaryOrConditional.left);
94
99
  }
95
- if (possibleBinaryOrConditional.right instanceof bundled_angular_compiler_1.Binary) {
100
+ if (rightUnwrapped instanceof bundled_angular_compiler_1.Binary ||
101
+ rightUnwrapped instanceof bundled_angular_compiler_1.Conditional) {
96
102
  total += getTotalComplexity(possibleBinaryOrConditional.right);
97
103
  }
98
104
  }
@@ -1 +1 @@
1
- {"version":3,"file":"no-negated-async.d.ts","sourceRoot":"","sources":["../../src/rules/no-negated-async.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,OAAO,GAAG,EAAE,CAAC;AACzB,MAAM,MAAM,UAAU,GAClB,gBAAgB,GAChB,wBAAwB,GACxB,wBAAwB,GACxB,uBAAuB,GACvB,4BAA4B,GAC5B,6BAA6B,CAAC;AAClC,eAAO,MAAM,SAAS,qBAAqB,CAAC;;AAE5C,wBA2EG;AAEH,eAAO,MAAM,mBAAmB;;CAE/B,CAAC"}
1
+ {"version":3,"file":"no-negated-async.d.ts","sourceRoot":"","sources":["../../src/rules/no-negated-async.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,OAAO,GAAG,EAAE,CAAC;AACzB,MAAM,MAAM,UAAU,GAClB,gBAAgB,GAChB,wBAAwB,GACxB,wBAAwB,GACxB,uBAAuB,GACvB,4BAA4B,GAC5B,6BAA6B,CAAC;AAClC,eAAO,MAAM,SAAS,qBAAqB,CAAC;;AAE5C,wBAmFG;AAEH,eAAO,MAAM,mBAAmB;;CAE/B,CAAC"}
@@ -28,6 +28,23 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
28
28
  create(context) {
29
29
  (0, utils_1.ensureTemplateParser)(context);
30
30
  const sourceCode = context.sourceCode;
31
+ function reportNegatedAsync(prefixNotNode) {
32
+ const { start, end } = prefixNotNode.sourceSpan;
33
+ context.report({
34
+ messageId: 'noNegatedAsync',
35
+ loc: {
36
+ start: sourceCode.getLocFromIndex(start),
37
+ end: sourceCode.getLocFromIndex(end),
38
+ },
39
+ suggest: getSuggestionsSchema().map(({ messageId, textToInsert }) => ({
40
+ messageId,
41
+ fix: (fixer) => [
42
+ fixer.removeRange([start, start + 1]),
43
+ fixer.insertTextAfterRange([end, end], textToInsert),
44
+ ],
45
+ })),
46
+ });
47
+ }
31
48
  return {
32
49
  'BindingPipe[name="async"]'(bindingPipe) {
33
50
  if (bindingPipe.exp instanceof bundled_angular_compiler_1.PrefixNot) {
@@ -48,21 +65,11 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
48
65
  });
49
66
  }
50
67
  },
51
- ':not(PrefixNot) > PrefixNot > BindingPipe[name="async"]'({ parent: { sourceSpan: { end, start }, }, }) {
52
- context.report({
53
- messageId: 'noNegatedAsync',
54
- loc: {
55
- start: sourceCode.getLocFromIndex(start),
56
- end: sourceCode.getLocFromIndex(end),
57
- },
58
- suggest: getSuggestionsSchema().map(({ messageId, textToInsert }) => ({
59
- messageId,
60
- fix: (fixer) => [
61
- fixer.removeRange([start, start + 1]),
62
- fixer.insertTextAfterRange([end, end], textToInsert),
63
- ],
64
- })),
65
- });
68
+ ':not(PrefixNot) > PrefixNot > BindingPipe[name="async"]'({ parent, }) {
69
+ reportNegatedAsync(parent);
70
+ },
71
+ ':not(PrefixNot) > PrefixNot > ParenthesizedExpression > BindingPipe[name="async"]'({ parent: { parent }, }) {
72
+ reportNegatedAsync(parent);
66
73
  },
67
74
  };
68
75
  },
@@ -1 +1 @@
1
- {"version":3,"file":"prefer-contextual-for-variables.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-contextual-for-variables.ts"],"names":[],"mappings":"AAmBA,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,wBAiaG"}
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,wBAiaG"}
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RULE_NAME = void 0;
4
4
  const bundled_angular_compiler_1 = require("@angular-eslint/bundled-angular-compiler");
5
5
  const utils_1 = require("@angular-eslint/utils");
6
- const create_eslint_rule_1 = require("../utils/create-eslint-rule");
7
6
  const are_equivalent_asts_1 = require("../utils/are-equivalent-asts");
7
+ const create_eslint_rule_1 = require("../utils/create-eslint-rule");
8
+ const unwrap_parenthesized_expression_1 = require("../utils/unwrap-parenthesized-expression");
8
9
  exports.RULE_NAME = 'prefer-contextual-for-variables';
9
10
  const DEFAULT_OPTIONS = {
10
11
  allowedAliases: {
@@ -482,35 +483,38 @@ function isIndex(node) {
482
483
  return isContextualVariable(node, '$index');
483
484
  }
484
485
  function isIndexPlusOne(node) {
485
- if (node instanceof bundled_angular_compiler_1.Binary) {
486
- if (node.operation === '+') {
487
- if (isIndex(node.left)) {
488
- return isOne(node.right);
486
+ const unwrapped = (0, unwrap_parenthesized_expression_1.unwrapParenthesizedExpression)(node);
487
+ if (unwrapped instanceof bundled_angular_compiler_1.Binary) {
488
+ if (unwrapped.operation === '+') {
489
+ if (isIndex(unwrapped.left)) {
490
+ return isOne(unwrapped.right);
489
491
  }
490
492
  else {
491
- return isIndex(node.right) && isOne(node.left);
493
+ return isIndex(unwrapped.right) && isOne(unwrapped.left);
492
494
  }
493
495
  }
494
496
  }
495
497
  return false;
496
498
  }
497
499
  function isIndexModTwo(node) {
498
- return (node instanceof bundled_angular_compiler_1.Binary &&
499
- node.operation === '%' &&
500
- isIndex(node.left) &&
501
- isTwo(node.right));
500
+ const unwrapped = (0, unwrap_parenthesized_expression_1.unwrapParenthesizedExpression)(node);
501
+ return (unwrapped instanceof bundled_angular_compiler_1.Binary &&
502
+ unwrapped.operation === '%' &&
503
+ isIndex(unwrapped.left) &&
504
+ isTwo(unwrapped.right));
502
505
  }
503
506
  function isCount(node) {
504
507
  return isContextualVariable(node, '$count');
505
508
  }
506
509
  function isCountMinusOne(node) {
507
- if (node instanceof bundled_angular_compiler_1.Binary) {
508
- if (node.operation === '-') {
509
- if (isCount(node.left)) {
510
- return isOne(node.right);
510
+ const unwrapped = (0, unwrap_parenthesized_expression_1.unwrapParenthesizedExpression)(node);
511
+ if (unwrapped instanceof bundled_angular_compiler_1.Binary) {
512
+ if (unwrapped.operation === '-') {
513
+ if (isCount(unwrapped.left)) {
514
+ return isOne(unwrapped.right);
511
515
  }
512
516
  else {
513
- return isCount(node.right) && isOne(node.left);
517
+ return isCount(unwrapped.right) && isOne(unwrapped.left);
514
518
  }
515
519
  }
516
520
  }
@@ -1 +1 @@
1
- {"version":3,"file":"prefer-template-literal.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-template-literal.ts"],"names":[],"mappings":"AAgBA,QAAA,MAAM,SAAS,0BAA0B,CAAC;AAE1C,MAAM,MAAM,OAAO,GAAG,EAAE,CAAC;AACzB,MAAM,MAAM,UAAU,GAAG,OAAO,SAAS,CAAC;AAC1C,eAAO,MAAM,SAAS,4BAA4B,CAAC;;AAEnD,wBA+PG"}
1
+ {"version":3,"file":"prefer-template-literal.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-template-literal.ts"],"names":[],"mappings":"AAkBA,QAAA,MAAM,SAAS,0BAA0B,CAAC;AAE1C,MAAM,MAAM,OAAO,GAAG,EAAE,CAAC;AACzB,MAAM,MAAM,UAAU,GAAG,OAAO,SAAS,CAAC;AAC1C,eAAO,MAAM,SAAS,4BAA4B,CAAC;;AAEnD,wBAsKG"}
@@ -5,6 +5,7 @@ const bundled_angular_compiler_1 = require("@angular-eslint/bundled-angular-comp
5
5
  const utils_1 = require("@angular-eslint/utils");
6
6
  const create_eslint_rule_1 = require("../utils/create-eslint-rule");
7
7
  const literal_primitive_1 = require("../utils/literal-primitive");
8
+ const unwrap_parenthesized_expression_1 = require("../utils/unwrap-parenthesized-expression");
8
9
  const messageId = 'preferTemplateLiteral';
9
10
  exports.RULE_NAME = 'prefer-template-literal';
10
11
  exports.default = (0, create_eslint_rule_1.createESLintRule)({
@@ -26,7 +27,10 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
26
27
  const { sourceCode } = context;
27
28
  return {
28
29
  'Binary[operation="+"]'(node) {
29
- const { left, right } = node;
30
+ const originalLeft = node.left;
31
+ const originalRight = node.right;
32
+ const left = (0, unwrap_parenthesized_expression_1.unwrapParenthesizedExpression)(originalLeft);
33
+ const right = (0, unwrap_parenthesized_expression_1.unwrapParenthesizedExpression)(originalRight);
30
34
  const isLeftString = (0, literal_primitive_1.isStringLiteralPrimitive)(left) || left instanceof bundled_angular_compiler_1.TemplateLiteral;
31
35
  const isRightString = (0, literal_primitive_1.isStringLiteralPrimitive)(right) || right instanceof bundled_angular_compiler_1.TemplateLiteral;
32
36
  // If both sides are not strings, we don't report anything
@@ -39,6 +43,10 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
39
43
  if (parentIsTemplateLiteral) {
40
44
  return '';
41
45
  }
46
+ // If either side is not a literal primitive, we need to use backticks for interpolation
47
+ if (!(0, literal_primitive_1.isLiteralPrimitive)(left) || !(0, literal_primitive_1.isLiteralPrimitive)(right)) {
48
+ return '`';
49
+ }
42
50
  if (left instanceof bundled_angular_compiler_1.LiteralPrimitive &&
43
51
  right instanceof bundled_angular_compiler_1.LiteralPrimitive) {
44
52
  const leftValue = sourceCode.text.at(left.sourceSpan.start);
@@ -52,57 +60,6 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
52
60
  }
53
61
  return '`';
54
62
  }
55
- function getLeftSideFixes(fixer, quote) {
56
- const { start, end } = left.sourceSpan;
57
- if (left instanceof bundled_angular_compiler_1.TemplateLiteral) {
58
- // Remove the end ` sign from the left side
59
- return [
60
- fixer.replaceTextRange([start, start + 1], quote),
61
- fixer.removeRange([end - 1, end]),
62
- ];
63
- }
64
- if ((0, literal_primitive_1.isLiteralPrimitive)(left)) {
65
- // Transform left side to template literal
66
- return [
67
- fixer.replaceTextRange([start, end], parentIsTemplateLiteral
68
- ? `${(0, literal_primitive_1.getLiteralPrimitiveStringValue)(left, '`')}`
69
- : `${quote}${(0, literal_primitive_1.getLiteralPrimitiveStringValue)(left, quote)}`),
70
- ];
71
- }
72
- // Transform left side to template literal
73
- return [
74
- fixer.insertTextBeforeRange([start, end], `${quote}\${`),
75
- fixer.insertTextAfterRange([start, end], '}'),
76
- ];
77
- }
78
- function getRightSideFixes(fixer, quote) {
79
- const { start, end } = right.sourceSpan;
80
- if (right instanceof bundled_angular_compiler_1.TemplateLiteral) {
81
- // Remove the start ` sign from the right side
82
- return [
83
- fixer.removeRange([start, start + 1]),
84
- fixer.replaceTextRange([end - 1, end], quote),
85
- ];
86
- }
87
- if ((0, literal_primitive_1.isLiteralPrimitive)(right)) {
88
- // Transform right side to template literal if it's a string
89
- return [
90
- fixer.replaceTextRange([start, end], parentIsTemplateLiteral
91
- ? `${(0, literal_primitive_1.getLiteralPrimitiveStringValue)(right, '`')}`
92
- : `${(0, literal_primitive_1.getLiteralPrimitiveStringValue)(right, quote)}${quote}`),
93
- ];
94
- }
95
- // Transform right side to template literal
96
- return [
97
- fixer.insertTextBeforeRange([start, end], '${'),
98
- fixer.insertTextAfterRange([start, end], `}${quote}`),
99
- ];
100
- }
101
- function hasParentheses(node) {
102
- const { start, end } = node.sourceSpan;
103
- const text = sourceCode.text.slice(start - 1, end + 1);
104
- return text.startsWith('(') && text.endsWith(')');
105
- }
106
63
  context.report({
107
64
  loc: {
108
65
  start: sourceCode.getLocFromIndex(start),
@@ -128,48 +85,25 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
128
85
  : `${quote}${(0, literal_primitive_1.getLiteralPrimitiveStringValue)(left, quote)}${(0, literal_primitive_1.getLiteralPrimitiveStringValue)(right, quote)}${quote}`));
129
86
  }
130
87
  else {
131
- const leftHasParentheses = hasParentheses(left);
132
- const rightHasParentheses = hasParentheses(right);
133
- // Remove the left first parenthesis if it exists
134
- if (leftHasParentheses) {
135
- fixes.push(fixer.removeRange([
136
- left.sourceSpan.start - 1,
137
- left.sourceSpan.start,
138
- ]));
88
+ // Fix the left side - handle parenthesized expressions specially
89
+ if (originalLeft instanceof bundled_angular_compiler_1.ParenthesizedExpression) {
90
+ fixes.push(...getLeftSideFixesForParenthesized(fixer, left, originalLeft, quote));
139
91
  }
140
- // Fix the left side
141
- fixes.push(...getLeftSideFixes(fixer, quote));
142
- // Remove the left last parenthesis if it exists
143
- if (leftHasParentheses) {
144
- fixes.push(fixer.removeRange([
145
- left.sourceSpan.end,
146
- left.sourceSpan.end + 1,
147
- ]));
92
+ else {
93
+ fixes.push(...getLeftSideFixes(fixer, left, quote));
148
94
  }
149
- // Remove the `+` sign
95
+ // Remove the `+` sign (including surrounding whitespace)
150
96
  fixes.push(fixer.removeRange([
151
- leftHasParentheses
152
- ? left.sourceSpan.end + 1
153
- : left.sourceSpan.end,
154
- rightHasParentheses
155
- ? right.sourceSpan.start - 1
156
- : right.sourceSpan.start,
97
+ originalLeft.sourceSpan.end,
98
+ originalRight.sourceSpan.start,
157
99
  ]));
158
- // Remove the right first parenthesis if it exists
159
- if (rightHasParentheses) {
160
- fixes.push(fixer.removeRange([
161
- right.sourceSpan.start - 1,
162
- right.sourceSpan.start,
163
- ]));
100
+ // Fix the right side - handle parenthesized expressions specially
101
+ if (originalRight instanceof bundled_angular_compiler_1.ParenthesizedExpression) {
102
+ // For parenthesized expressions, we want to replace the whole thing including parens
103
+ fixes.push(...getRightSideFixesForParenthesized(fixer, right, originalRight, quote));
164
104
  }
165
- // Fix the right side
166
- fixes.push(...getRightSideFixes(fixer, quote));
167
- // Remove the right last parenthesis if it exists
168
- if (rightHasParentheses) {
169
- fixes.push(fixer.removeRange([
170
- right.sourceSpan.end,
171
- right.sourceSpan.end + 1,
172
- ]));
105
+ else {
106
+ fixes.push(...getRightSideFixes(fixer, right, quote));
173
107
  }
174
108
  }
175
109
  // If the parent is a template literal, remove the `}` sign
@@ -187,3 +121,101 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
187
121
  };
188
122
  },
189
123
  });
124
+ function getLeftSideFixes(fixer, left, quote) {
125
+ const { start, end } = left.sourceSpan;
126
+ if (left instanceof bundled_angular_compiler_1.TemplateLiteral) {
127
+ // Remove the end ` sign from the left side
128
+ return [
129
+ fixer.replaceTextRange([start, start + 1], quote),
130
+ fixer.removeRange([end - 1, end]),
131
+ ];
132
+ }
133
+ if ((0, literal_primitive_1.isLiteralPrimitive)(left)) {
134
+ // Transform left side to template literal
135
+ return [
136
+ fixer.replaceTextRange([start, end], quote === ''
137
+ ? `${(0, literal_primitive_1.getLiteralPrimitiveStringValue)(left, '`')}`
138
+ : `${quote}${(0, literal_primitive_1.getLiteralPrimitiveStringValue)(left, quote)}`),
139
+ ];
140
+ }
141
+ // Transform left side to template literal
142
+ return [
143
+ fixer.insertTextBeforeRange([start, end], `${quote}\${`),
144
+ fixer.insertTextAfterRange([start, end], '}'),
145
+ ];
146
+ }
147
+ function getLeftSideFixesForParenthesized(fixer, innerExpression, parenthesizedExpression, quote) {
148
+ const parenthesizedStart = parenthesizedExpression.sourceSpan.start;
149
+ const parenthesizedEnd = parenthesizedExpression.sourceSpan.end;
150
+ const innerStart = innerExpression.sourceSpan.start;
151
+ const innerEnd = innerExpression.sourceSpan.end;
152
+ if (innerExpression instanceof bundled_angular_compiler_1.TemplateLiteral) {
153
+ // Remove the end ` sign from the inner expression and remove the parentheses
154
+ return [
155
+ fixer.replaceTextRange([parenthesizedStart, innerStart + 1], quote), // Replace opening paren and backtick with quote
156
+ fixer.removeRange([innerEnd - 1, parenthesizedEnd]), // Remove closing backtick and paren
157
+ ];
158
+ }
159
+ if ((0, literal_primitive_1.isLiteralPrimitive)(innerExpression)) {
160
+ // Transform to template literal and remove parentheses
161
+ return [
162
+ fixer.replaceTextRange([parenthesizedStart, parenthesizedEnd], quote === ''
163
+ ? `${(0, literal_primitive_1.getLiteralPrimitiveStringValue)(innerExpression, '`')}`
164
+ : `${quote}${(0, literal_primitive_1.getLiteralPrimitiveStringValue)(innerExpression, quote)}`),
165
+ ];
166
+ }
167
+ // Transform parenthesized expression to template literal by removing parens and wrapping in ${}
168
+ return [
169
+ fixer.replaceTextRange([parenthesizedStart, innerStart], `${quote}\${`), // Replace opening paren with quote${
170
+ fixer.replaceTextRange([innerEnd, parenthesizedEnd], '}'), // Replace closing paren with }
171
+ ];
172
+ }
173
+ function getRightSideFixes(fixer, right, quote) {
174
+ const { start, end } = right.sourceSpan;
175
+ if (right instanceof bundled_angular_compiler_1.TemplateLiteral) {
176
+ // Remove the start ` sign from the right side
177
+ return [
178
+ fixer.removeRange([start, start + 1]),
179
+ fixer.replaceTextRange([end - 1, end], quote),
180
+ ];
181
+ }
182
+ if ((0, literal_primitive_1.isLiteralPrimitive)(right)) {
183
+ // Transform right side to template literal if it's a string
184
+ return [
185
+ fixer.replaceTextRange([start, end], quote === ''
186
+ ? `${(0, literal_primitive_1.getLiteralPrimitiveStringValue)(right, '`')}`
187
+ : `${(0, literal_primitive_1.getLiteralPrimitiveStringValue)(right, quote)}${quote}`),
188
+ ];
189
+ }
190
+ // Transform right side to template literal
191
+ return [
192
+ fixer.insertTextBeforeRange([start, end], '${'),
193
+ fixer.insertTextAfterRange([start, end], `}${quote}`),
194
+ ];
195
+ }
196
+ function getRightSideFixesForParenthesized(fixer, innerExpression, parenthesizedExpression, quote) {
197
+ const parenthesizedStart = parenthesizedExpression.sourceSpan.start;
198
+ const parenthesizedEnd = parenthesizedExpression.sourceSpan.end;
199
+ const innerStart = innerExpression.sourceSpan.start;
200
+ const innerEnd = innerExpression.sourceSpan.end;
201
+ if (innerExpression instanceof bundled_angular_compiler_1.TemplateLiteral) {
202
+ // Remove the start ` sign from the inner expression and remove the parentheses
203
+ return [
204
+ fixer.removeRange([parenthesizedStart, innerStart + 1]), // Remove opening paren and backtick
205
+ fixer.replaceTextRange([innerEnd - 1, parenthesizedEnd], quote), // Replace closing backtick and paren with quote
206
+ ];
207
+ }
208
+ if ((0, literal_primitive_1.isLiteralPrimitive)(innerExpression)) {
209
+ // Transform to template literal and remove parentheses
210
+ return [
211
+ fixer.replaceTextRange([parenthesizedStart, parenthesizedEnd], quote === ''
212
+ ? `${(0, literal_primitive_1.getLiteralPrimitiveStringValue)(innerExpression, '`')}`
213
+ : `${(0, literal_primitive_1.getLiteralPrimitiveStringValue)(innerExpression, quote)}${quote}`),
214
+ ];
215
+ }
216
+ // Transform parenthesized expression to template literal by removing parens and wrapping in ${}
217
+ return [
218
+ fixer.replaceTextRange([parenthesizedStart, innerStart], '${'), // Replace opening paren with ${
219
+ fixer.replaceTextRange([innerEnd, parenthesizedEnd], `}${quote}`), // Replace closing paren with }quote
220
+ ];
221
+ }
@@ -0,0 +1,3 @@
1
+ import { type AST } from '@angular-eslint/bundled-angular-compiler';
2
+ export declare function unwrapParenthesizedExpression(node: AST): AST;
3
+ //# sourceMappingURL=unwrap-parenthesized-expression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unwrap-parenthesized-expression.d.ts","sourceRoot":"","sources":["../../src/utils/unwrap-parenthesized-expression.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,GAAG,EAET,MAAM,0CAA0C,CAAC;AAElD,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,CAE5D"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unwrapParenthesizedExpression = unwrapParenthesizedExpression;
4
+ const bundled_angular_compiler_1 = require("@angular-eslint/bundled-angular-compiler");
5
+ function unwrapParenthesizedExpression(node) {
6
+ return node instanceof bundled_angular_compiler_1.ParenthesizedExpression ? node.expression : node;
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-eslint/eslint-plugin-template",
3
- "version": "19.8.1-alpha.0",
3
+ "version": "19.8.1-alpha.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": "19.8.1-alpha.0",
24
- "@angular-eslint/utils": "19.8.1-alpha.0"
23
+ "@angular-eslint/bundled-angular-compiler": "19.8.1-alpha.1",
24
+ "@angular-eslint/utils": "19.8.1-alpha.1"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/aria-query": "5.0.4",
28
- "@angular-eslint/test-utils": "19.8.1-alpha.0"
28
+ "@angular-eslint/test-utils": "19.8.1-alpha.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": "19.8.1-alpha.0"
35
+ "@angular-eslint/template-parser": "19.8.1-alpha.1"
36
36
  },
37
37
  "gitHead": "e2006e5e9c99e5a943d1a999e0efa5247d29ec24"
38
38
  }