summaryrefslogtreecommitdiff
path: root/test/handler/test_tslint_handler.vader
blob: 8d263eface4c5ed8d9786883d1f53297799aa611 (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
Before:
  Save g:ale_typescript_tslint_ignore_empty_files

  unlet! g:ale_typescript_tslint_ignore_empty_files
  unlet! b:ale_typescript_tslint_ignore_empty_files

  runtime ale_linters/typescript/tslint.vim

  call ale#test#SetDirectory('/testplugin/test/handler')

After:
  Restore

  unlet! b:ale_typescript_tslint_ignore_empty_files
  unlet! b:relative_to_root
  unlet! b:tempname_suffix
  unlet! b:relative_tempname

  call ale#test#RestoreDirectory()
  call ale#linter#Reset()

Execute(The tslint handler should parse lines correctly):
  call ale#test#SetFilename('app/test.ts')

  AssertEqual
  \ [
  \   {
  \     'lnum': 1,
  \     'col': 15,
  \     'filename': ale#path#Winify(expand('%:p:h') . '/test.ts'),
  \     'end_lnum': 1,
  \     'type': 'E',
  \     'end_col': 15,
  \     'text': 'Missing semicolon',
  \     'code': 'semicolon',
  \   },
  \   {
  \     'lnum': 2,
  \     'col': 8,
  \     'filename': ale#path#Winify(expand('%:p:h') . '/test.ts'),
  \     'end_lnum': 3,
  \     'type': 'W',
  \     'end_col': 12,
  \     'text': 'Something else',
  \   },
  \   {
  \     'lnum': 2,
  \     'col': 8,
  \     'filename': ale#path#Winify(expand('%:p:h') . '/something-else.ts'),
  \     'end_lnum': 3,
  \     'type': 'W',
  \     'end_col': 12,
  \     'text': 'Something else',
  \     'code': 'something',
  \   },
  \   {
  \     'lnum': 31,
  \     'col': 9,
  \     'filename': ale#path#Winify(expand('%:p:h') . '/test.ts'),
  \     'end_lnum': 31,
  \     'type': 'E',
  \     'end_col': 20,
  \     'text': 'Calls to console.log are not allowed.',
  \     'code': 'no-console',
  \   },
  \ ] ,
  \ ale_linters#typescript#tslint#Handle(bufnr(''), [json_encode([
  \   {
  \     'endPosition': {
  \       'character': 14,
  \       'line': 0,
  \       'position': 1000
  \     },
  \     'failure': 'Missing semicolon',
  \     'fix': {
  \       'innerLength': 0,
  \       'innerStart': 14,
  \       'innerText': ';'
  \     },
  \     'name': 'test.ts',
  \     'ruleName': 'semicolon',
  \     'ruleSeverity': 'ERROR',
  \     'startPosition': {
  \       'character': 14,
  \       'line': 0,
  \       'position': 1000
  \     }
  \   },
  \   {
  \     'endPosition': {
  \       'character': 11,
  \       'line': 2,
  \       'position': 1000
  \     },
  \     'failure': 'Something else',
  \     'fix': {
  \       'innerLength': 0,
  \       'innerStart': 14,
  \       'innerText': ';'
  \     },
  \     'name': 'test.ts',
  \     'ruleSeverity': 'WARNING',
  \     'startPosition': {
  \       'character': 7,
  \       'line': 1,
  \       'position': 1000
  \     }
  \   },
  \   {
  \     'endPosition': {
  \       'character': 11,
  \       'line': 2,
  \       'position': 22
  \     },
  \     'failure': 'Something else',
  \     'fix': {
  \       'innerLength': 0,
  \       'innerStart': 14,
  \       'innerText': ';'
  \     },
  \     'name': 'something-else.ts',
  \     'ruleName': 'something',
  \     'ruleSeverity': 'WARNING',
  \     'startPosition': {
  \       'character': 7,
  \       'line': 1,
  \       'position': 14
  \     }
  \   },
  \   {
  \     "endPosition": {
  \       "character": 19,
  \       "line": 30,
  \       "position": 14590
  \     },
  \     "failure": "Calls to console.log are not allowed.",
  \     'name': 'test.ts',
  \     "ruleName": "no-console",
  \     "startPosition": {
  \       "character": 8,
  \       "line": 30,
  \       "position": 14579
  \     }
  \   },
  \])])

Execute(The tslint handler should handle empty output):
  AssertEqual
  \ [],
  \ ale_linters#typescript#tslint#Handle(bufnr(''), [])

Execute(The tslint handler report errors for empty files by default):
  call ale#test#SetFilename('app/test.ts')

  AssertEqual
  \ [
  \   {
  \     'lnum': 2,
  \     'col': 1,
  \     'filename': ale#path#Winify(expand('%:p:h') . '/test.ts'),
  \     'end_lnum': 2,
  \     'type': 'E',
  \     'end_col': 1,
  \     'text': 'Consecutive blank lines are forbidden',
  \     'code': 'no-consecutive-blank-lines',
  \   },
  \ ],
  \ ale_linters#typescript#tslint#Handle(bufnr(''), [json_encode([{
  \   'endPosition': {
  \     'character': 0,
  \     'line': 1,
  \     'position': 1
  \   },
  \   'failure': 'Consecutive blank lines are forbidden',
  \   'fix': [{
  \     'innerStart': 0,
  \     'innerLength': 1,
  \     'innerText': ''
  \   }],
  \   'name': 'test.ts',
  \   'ruleName': 'no-consecutive-blank-lines',
  \   'ruleSeverity': 'ERROR',
  \   'startPosition': {
  \     'character': 0,
  \     'line': 1,
  \     'position': 1
  \   }
  \ }])])

Execute(The tslint handler should not report errors for empty files when the ignore option is on):
  let b:ale_typescript_tslint_ignore_empty_files = 1
  call ale#test#SetFilename('app/test.ts')

  AssertEqual
  \ [
  \ ],
  \ ale_linters#typescript#tslint#Handle(bufnr(''), [json_encode([{
  \   'endPosition': {
  \     'character': 0,
  \     'line': 1,
  \     'position': 1
  \   },
  \   'failure': 'Consecutive blank lines are forbidden',
  \   'fix': [{
  \     'innerStart': 0,
  \     'innerLength': 1,
  \     'innerText': ''
  \   }],
  \   'name': 'test.ts',
  \   'ruleName': 'no-consecutive-blank-lines',
  \   'ruleSeverity': 'ERROR',
  \   'startPosition': {
  \     'character': 0,
  \     'line': 1,
  \     'position': 1
  \   }
  \ }])])

Given typescript(A file with extra blank lines):
  const x = 3


  const y = 4

Execute(The tslint handler should report errors when the ignore option is on, but the file is not empty):
  let b:ale_typescript_tslint_ignore_empty_files = 1
  call ale#test#SetFilename('app/test.ts')

  AssertEqual
  \ [
  \   {
  \     'lnum': 2,
  \     'col': 1,
  \     'filename': ale#path#Winify(expand('%:p:h') . '/test.ts'),
  \     'end_lnum': 2,
  \     'type': 'E',
  \     'end_col': 1,
  \     'text': 'Consecutive blank lines are forbidden',
  \     'code': 'no-consecutive-blank-lines',
  \   },
  \ ],
  \ ale_linters#typescript#tslint#Handle(bufnr(''), [json_encode([{
  \   'endPosition': {
  \     'character': 0,
  \     'line': 1,
  \     'position': 1
  \   },
  \   'failure': 'Consecutive blank lines are forbidden',
  \   'fix': [{
  \     'innerStart': 0,
  \     'innerLength': 1,
  \     'innerText': ''
  \   }],
  \   'name': 'test.ts',
  \   'ruleName': 'no-consecutive-blank-lines',
  \   'ruleSeverity': 'ERROR',
  \   'startPosition': {
  \     'character': 0,
  \     'line': 1,
  \     'position': 1
  \   }
  \ }])])

Execute(The tslint handler should not report no-implicit-dependencies errors):
  call ale#test#SetFilename('app/test.ts')

  AssertEqual
  \ [
  \ ],
  \ ale_linters#typescript#tslint#Handle(bufnr(''), [json_encode([{
  \   'endPosition': {
  \     'character': 0,
  \     'line': 1,
  \     'position': 1
  \   },
  \   'failure': 'this is ignored',
  \   'name': 'test.ts',
  \   'ruleName': 'no-implicit-dependencies',
  \   'ruleSeverity': 'ERROR',
  \   'startPosition': {
  \     'character': 0,
  \     'line': 1,
  \     'position': 1
  \   },
  \ }])])

Execute(The tslint handler should set filename keys for temporary files):
  " The temporay filename below is hacked into being a relative path so we can
  " test that we resolve the temporary filename first.
  let b:relative_to_root = substitute(expand('%:p'), '\v[^/\\]*([/\\])[^/\\]*', '../', 'g')
  let b:tempname_suffix = substitute(tempname(), '^\v([A-Z]:)?[/\\]', '', '')
  let b:relative_tempname = substitute(b:relative_to_root . b:tempname_suffix, '\\', '/', 'g')

  AssertEqual
  \ [
  \   {'lnum': 47, 'col': 1, 'code': 'curly', 'end_lnum': 47, 'type': 'E', 'end_col': 26, 'text': 'if statements must be braced'},
  \ ],
  \ ale_linters#typescript#tslint#Handle(bufnr(''), [json_encode([
  \   {
  \     'endPosition': {
  \       'character':25,
  \       'line':46,
  \       'position':1383,
  \     },
  \     'failure': 'if statements must be braced',
  \     'name': b:relative_tempname,
  \     'ruleName': 'curly',
  \     'ruleSeverity':'ERROR',
  \     'startPosition': {
  \       'character':0,
  \       'line':46,
  \       'position':1358,
  \     }
  \   },
  \ ])])