Skip to content

Commit 6c77dd9

Browse files
reducktedJamesHenry
authored andcommitted
feat(template-parser)!: do not suppress parse errors by default (#2255)
1 parent 752cc66 commit 6c77dd9

File tree

10 files changed

+33
-27
lines changed

10 files changed

+33
-27
lines changed

packages/eslint-plugin-template/docs/rules/eqeqeq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ interface Options {
182182
#### ❌ Invalid Code
183183

184184
```html
185-
<div [prop]="condition1 === 'value1' ? true : (condition2 != 'value2' ? true : false)}"></div>
185+
<div [prop]="condition1 === 'value1' ? true : (condition2 != 'value2' ? true : false)"></div>
186186
~~~~~~~~~~~~~~~~~~~~~~
187187
```
188188

packages/eslint-plugin-template/docs/rules/no-call-expression.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ interface Options {
794794
#### ✅ Valid Code
795795

796796
```html
797-
@for (item of list; track item.id)) {
797+
@for (item of list; track item.id) {
798798
<div></div>
799799
} @empty {
800800
<div></div>

packages/eslint-plugin-template/docs/rules/prefer-ngsrc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ The rule does not have any configuration options.
164164
#### ✅ Valid Code
165165

166166
```html
167-
<img [ngSrc]="'http://localhost'>
167+
<img [ngSrc]="'http://localhost'">
168168
```
169169

170170
<br>

packages/eslint-plugin-template/tests/rules/eqeqeq/cases.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const invalid: readonly InvalidTestCase<MessageIds, Options>[] = [
9595
description:
9696
'it should fail if the operation is not strict within attribute directive with nested ternary',
9797
annotatedSource: `
98-
<div [prop]="condition1 === 'value1' ? true : (condition2 != 'value2' ? true : false)}"></div>
98+
<div [prop]="condition1 === 'value1' ? true : (condition2 != 'value2' ? true : false)"></div>
9999
~~~~~~~~~~~~~~~~~~~~~~
100100
`,
101101
messageId,
@@ -104,7 +104,7 @@ export const invalid: readonly InvalidTestCase<MessageIds, Options>[] = [
104104
expectedOperation: '!==',
105105
},
106106
annotatedOutput: `
107-
<div [prop]="condition1 === 'value1' ? true : (condition2 !== 'value2' ? true : false)}"></div>
107+
<div [prop]="condition1 === 'value1' ? true : (condition2 !== 'value2' ? true : false)"></div>
108108
~~~~~~~~~~~~~~~~~~~~~~~
109109
`,
110110
}),

packages/eslint-plugin-template/tests/rules/i18n/cases.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ export const invalid: readonly InvalidTestCase<MessageIds, Options>[] = [
502502
<p>Lorem ipsum <em i18n="@@dolor">dolor</em> sit amet.</p>
503503
~~~~~~~~~~~~ ^^^^^^^^^
504504
`,
505+
languageOptions: { parserOptions: { suppressParseErrors: true } },
505506
messages: [
506507
{
507508
char: '~',
@@ -876,6 +877,7 @@ export const invalid: readonly InvalidTestCase<MessageIds, Options>[] = [
876877
<ng-template>Lorem ipsum <ng-template i18n="@@dolor">dolor</ng-template> sit amet.</ng-template>
877878
~~~~~~~~~~~~ ^^^^^^^^^
878879
`,
880+
languageOptions: { parserOptions: { suppressParseErrors: true } },
879881
messages: [
880882
{
881883
char: '~',
@@ -1176,5 +1178,6 @@ export const invalid: readonly InvalidTestCase<MessageIds, Options>[] = [
11761178
`,
11771179
messageId: i18nMarkupInContent,
11781180
options: [{ allowMarkupInContent: false, checkId: false }],
1181+
languageOptions: { parserOptions: { suppressParseErrors: true } },
11791182
}),
11801183
];

packages/eslint-plugin-template/tests/rules/no-call-expression/cases.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const valid: readonly (string | ValidTestCase<Options>)[] = [
5050
}
5151
}`,
5252
`
53-
@for (item of list; track item.id)) {
53+
@for (item of list; track item.id) {
5454
<div></div>
5555
} @empty {
5656
<div></div>

packages/eslint-plugin-template/tests/rules/prefer-ngsrc/cases.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const invalidDoubleSource: MessageIds = 'invalidDoubleSource';
1010

1111
export const valid: readonly (string | ValidTestCase<Options>)[] = [
1212
'<img ngSrc="http://localhost">',
13-
"<img [ngSrc]=\"'http://localhost'>",
13+
'<img [ngSrc]="\'http://localhost\'">',
1414
'<img [ngSrc]="value">',
1515
'<img src="data:image/jpeg;base64">',
1616
];

packages/template-parser/src/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,7 @@ function parseForESLint(
297297
};
298298
}
299299

300-
// TODO: Investigate no longer suppressing parse errors by default in v19
301-
const suppressParseErrors = options.suppressParseErrors ?? true;
302-
303-
if (!suppressParseErrors && angularCompilerResult.errors?.length) {
300+
if (!options.suppressParseErrors && angularCompilerResult.errors?.length) {
304301
throw createTemplateParseError(angularCompilerResult.errors[0]);
305302
}
306303

packages/template-parser/tests/index.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -511,20 +511,7 @@ describe('parseForESLint()', () => {
511511
});
512512

513513
describe('parse errors', () => {
514-
it('should not throw if the Angular compiler produced parse errors by default', () => {
515-
expect.assertions(1);
516-
517-
const { ast } = parseForESLint(
518-
'<p>consumed resources are at {{ ${percent} | formatPercentLocale }}</p>',
519-
{
520-
filePath:
521-
'./inline-template-source-using-template-literal-interpolation.html',
522-
},
523-
);
524-
expect(ast).toBeDefined();
525-
});
526-
527-
it('should appropriately throw if the Angular compiler produced parse errors and `parserOptions.suppressParseErrors` is set to false', () => {
514+
it('should throw if the Angular compiler produced parse errors by default', () => {
528515
expect.assertions(2);
529516

530517
let error: TemplateParseError;
@@ -533,7 +520,6 @@ describe('parseForESLint()', () => {
533520
'<p i18n>Lorem ipsum <em i18n="@@dolor">dolor</em> sit amet.</p>',
534521
{
535522
filePath: './invalid-nested-i18ns.html',
536-
suppressParseErrors: false,
537523
},
538524
);
539525
} catch (err: any) {
@@ -551,6 +537,20 @@ describe('parseForESLint()', () => {
551537
`);
552538
}
553539
});
540+
541+
it('should not throw if the Angular compiler produced parse errors and `parserOptions.suppressParseErrors` is set to true', () => {
542+
expect.assertions(1);
543+
544+
const { ast } = parseForESLint(
545+
'<p>consumed resources are at {{ ${percent} | formatPercentLocale }}</p>',
546+
{
547+
filePath:
548+
'./inline-template-source-using-template-literal-interpolation.html',
549+
suppressParseErrors: true,
550+
},
551+
);
552+
expect(ast).toBeDefined();
553+
});
554554
});
555555

556556
describe('@defer', () => {

packages/test-utils/src/convert-annotated-source-to-failure-case.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type {
22
InvalidTestCase,
33
SuggestionOutput,
44
TestCaseError,
5+
TestLanguageOptions,
56
} from '@typescript-eslint/rule-tester';
67

78
/**
@@ -28,6 +29,7 @@ type MultipleErrorOptions<
2829
TMessageIds extends string,
2930
Options extends readonly unknown[],
3031
> = BaseErrorOptions<Options> & {
32+
readonly languageOptions?: TestLanguageOptions;
3133
readonly messages: readonly (Message<TMessageIds> & {
3234
readonly char: (typeof SPECIAL_UNDERLINE_CHARS)[number];
3335
})[];
@@ -52,7 +54,10 @@ type Message<TMessageIds extends string> = {
5254
type SingleErrorOptions<
5355
TMessageIds extends string,
5456
Options extends readonly unknown[],
55-
> = BaseErrorOptions<Options> & Message<TMessageIds>;
57+
> = BaseErrorOptions<Options> &
58+
Message<TMessageIds> & {
59+
readonly languageOptions?: TestLanguageOptions;
60+
};
5661

5762
/**
5863
* convertAnnotatedSourceToFailureCase() provides an ergonomic way to easily write
@@ -156,6 +161,7 @@ export function convertAnnotatedSourceToFailureCase<
156161
: parsedSource,
157162
filename: errorOptions.filename,
158163
options: errorOptions.options ?? ([] as any),
164+
languageOptions: errorOptions.languageOptions,
159165
errors,
160166
only: errorOptions.only ?? false,
161167
output: errorOptions.annotatedOutputs

0 commit comments

Comments
 (0)