/
cases.ts
99 lines (96 loc) · 3.05 KB
/
cases.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { convertAnnotatedSourceToFailureCase } from '@angular-eslint/utils';
import type { MessageIds } from '../../../src/rules/no-call-expression';
const messageId: MessageIds = 'noCallExpression';
export const valid = [
'{{ info }}',
'<button type="button" (click)="handleClick()">Click Here</button>',
'{{ $any(info) }}',
'<input (change)="obj?.changeHandler()">',
'<form [formGroup]="form" (ngSubmit)="form.valid || save()"></form>',
'<form [formGroup]="form" (ngSubmit)="form.valid && save()"></form>',
'<form [formGroup]="form" (ngSubmit)="id ? save() : edit()"></form>',
{
code: `
{{ obj?.nested() }} {{ obj!.nested() }}
<a [href]="getHref()">info</a>
`,
options: [
{
allowList: ['nested', 'getHref'],
},
],
},
];
export const invalid = [
convertAnnotatedSourceToFailureCase({
description: 'should fail for `FunctionCall` within `Interpolation`',
annotatedSource: `
<div>{{ getInfo()() }}</div>
~~~~~~~~~~~
`,
messageId,
}),
convertAnnotatedSourceToFailureCase({
description: 'should fail for `MethodCall` within `TextAttribute`',
annotatedSource: `
<a href="{{ getUrls().user }}"></a>
~~~~~~~~~
`,
messageId,
}),
convertAnnotatedSourceToFailureCase({
description: 'should fail for `SafeMethodCall` within `BoundAttribute`',
annotatedSource: `
<p [test]="test?.getInfo()"></p>
~~~~~~~~~~~~~~~
`,
messageId,
}),
convertAnnotatedSourceToFailureCase({
description:
'should fail for `FunctionCall`, `MethodCall` and `SafeMethodCall` within `Binary`',
annotatedSource: `
<a [href]="id && createUrl() && test()($any)">info</a>
~~~~~~~~~~~ ^^^^^^^^^^^^
{{ id || obj?.nested1() }}
##############
`,
messages: [
{ char: '~', messageId },
{ char: '^', messageId },
{ char: '#', messageId },
],
}),
convertAnnotatedSourceToFailureCase({
description:
'should fail for `FunctionCall`, `MethodCall` and `SafeMethodCall` within `Conditional`',
annotatedSource: `
<a [href]="id ? a?.createUrl() : editUrl(3)">info</a>
~~~~~~~~~~~~~~ ^^^^^^^^^^
{{ 1 === 2 ? 3 : obj?.nested1()() }}
################
`,
messages: [
{ char: '~', messageId },
{ char: '^', messageId },
{ char: '#', messageId },
],
}),
convertAnnotatedSourceToFailureCase({
description: 'should fail for safe/unsafe calls',
annotatedSource: `
{{ obj?.nested1() }} {{ obj!.nested1() }}
~~~~~~~~~~~~~~ ^^^^^^^^^^^^^^
<button [type]="obj!.$any(b)!.getType()()">info</button>
#########################
<a [href]="obj.propertyA?.href()">info</a>
%%%%%%%%%%%%%%%%%%%%%
`,
messages: [
{ char: '~', messageId },
{ char: '^', messageId },
{ char: '#', messageId },
{ char: '%', messageId },
],
}),
];