]> git.madduck.net Git - etc/vim.git/blob - test/handler/test_flow_handler.vader

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / test / handler / test_flow_handler.vader
1 Before:
2   runtime ale_linters/javascript/flow.vim
3
4 After:
5   unlet! g:flow_output
6   unlet! g:expected
7   unlet! g:actual
8   call ale#linter#Reset()
9
10 Execute(The flow handler should throw away non-JSON lines):
11   AssertEqual
12   \ [],
13   \ ale_linters#javascript#flow#Handle(bufnr(''), [
14   \   'Already up-to-date.',
15   \   '{"flowVersion":"0.50.0","errors":[],"passed":true}',
16   \ ])
17   AssertEqual
18   \ [],
19   \ ale_linters#javascript#flow#Handle(bufnr(''), [
20   \   'foo',
21   \   'bar',
22   \   'baz',
23   \   '{"flowVersion":"0.50.0","errors":[],"passed":true}',
24   \ ])
25
26 Execute(The flow handler should process errors correctly.):
27   silent! noautocmd file /home/w0rp/Downloads/graphql-js/src/language/parser.js
28
29   let g:flow_output = {
30   \ "flowVersion": "0.39.0",
31   \ "errors": [
32   \   {
33   \     "kind": "infer",
34   \     "level": "error",
35   \     "message": [
36   \       {
37   \         "context": "  return 1",
38   \         "descr": "number",
39   \         "type": "Blame",
40   \         "loc": {
41   \           "source": expand('%:p'),
42   \           "type": "SourceFile",
43   \           "start": {
44   \             "line": 417,
45   \             "column": 10,
46   \             "offset": 9503
47   \           },
48   \           "end": {
49   \             "line": 417,
50   \             "column": 10,
51   \             "offset": 9504
52   \           }
53   \         },
54   \         "path": expand('%:p'),
55   \         "line": 417,
56   \         "endline": 417,
57   \         "start": 10,
58   \         "end": 10
59   \       },
60   \       {
61   \         "context": v:null,
62   \         "descr": "This type is incompatible with the expected return type of",
63   \         "type": "Comment",
64   \         "path": "",
65   \         "line": 0,
66   \         "endline": 0,
67   \         "start": 1,
68   \         "end": 0
69   \       },
70   \       {
71   \         "context": "function parseArguments(lexer: Lexer<*>): Array<ArgumentNode> {",
72   \         "descr": "array type",
73   \         "type": "Blame",
74   \         "loc": {
75   \           "source": expand('%:p'),
76   \           "type": "SourceFile",
77   \           "start": {
78   \             "line": 416,
79   \             "column": 43,
80   \             "offset": 9472
81   \           },
82   \           "end": {
83   \             "line": 416,
84   \             "column": 61,
85   \             "offset": 9491
86   \           }
87   \         },
88   \         "path": expand('%:p'),
89   \         "line": 416,
90   \         "endline": 416,
91   \         "start": 43,
92   \         "end": 61
93   \       }
94   \     ]
95   \   },
96   \   {
97   \     "kind": "infer",
98   \     "level": "warning",
99   \     "message": [
100   \       {
101   \         "context": "  return peek(lexer, TokenKind.PAREN_L) ?",
102   \         "descr": "unreachable code",
103   \         "type": "Blame",
104   \         "loc": {
105   \           "source": expand('%:p'),
106   \           "type": "SourceFile",
107   \           "start": {
108   \             "line": 419,
109   \             "column": 3,
110   \             "offset": 9508
111   \           },
112   \           "end": {
113   \             "line": 421,
114   \             "column": 7,
115   \             "offset": 9626
116   \           }
117   \         },
118   \         "path": expand('%:p'),
119   \         "line": 419,
120   \         "endline": 421,
121   \         "start": 3,
122   \         "end": 7
123   \       }
124   \     ]
125   \   }
126   \ ],
127   \ "passed": v:false
128   \}
129
130   let g:actual = ale_linters#javascript#flow#Handle(bufnr(''), [json_encode(g:flow_output)])
131   let g:expected = [
132   \ {
133   \   'lnum': 417,
134   \   'type': 'E',
135   \   'col': 10,
136   \   'text': 'number: This type is incompatible with the expected return type of array type',
137   \ },
138   \ {
139   \   'lnum': 419,
140   \   'type': 'W',
141   \   'col': 3,
142   \   'text': 'unreachable code:',
143   \ },
144   \]
145
146   AssertEqual g:expected, g:actual
147
148 Execute(The flow handler should fetch the correct location for the currently opened file, even when it's not in the first message.):
149   silent! noautocmd file /Users/rav/Projects/vim-ale-flow/index.js
150
151   let g:flow_output = {
152   \ "flowVersion": "0.44.0",
153   \ "errors": [{
154   \   "operation": {
155   \     "context": "  <Foo foo=\"bar\"/>, document.getElementById('foo')",
156   \     "descr": "React element `Foo`",
157   \     "type": "Blame",
158   \     "loc": {
159   \       "source": expand('%:p'),
160   \       "type": "SourceFile",
161   \       "start": {
162   \         "line": 6,
163   \         "column": 3,
164   \         "offset": 92
165   \       },
166   \       "end": {
167   \         "line": 6,
168   \         "column": 18,
169   \         "offset": 108
170   \       }
171   \     },
172   \     "path": expand('%:p'),
173   \     "line": 6,
174   \     "endline": 6,
175   \     "start": 3,
176   \     "end": 18
177   \   },
178   \   "kind": "infer",
179   \   "level": "error",
180   \   "message": [{
181   \     "context": "module.exports = function(props: Props) {",
182   \     "descr": "property `bar`",
183   \     "type": "Blame",
184   \     "loc": {
185   \       "source": "/Users/rav/Projects/vim-ale-flow/foo.js",
186   \       "type": "SourceFile",
187   \       "start": {
188   \         "line": 9,
189   \         "column": 34,
190   \         "offset": 121
191   \       },
192   \       "end": {
193   \         "line": 9,
194   \         "column": 38,
195   \         "offset": 126
196   \       }
197   \     },
198   \     "path": "/Users/rav/Projects/vim-ale-flow/foo.js",
199   \     "line": 9,
200   \     "endline": 9,
201   \     "start": 34,
202   \     "end": 38
203   \   }, {
204   \     "context": v:null,
205   \     "descr": "Property not found in",
206   \     "type": "Comment",
207   \     "path": "",
208   \     "line": 0,
209   \     "endline": 0,
210   \     "start": 1,
211   \     "end": 0
212   \   }, {
213   \     "context": "  <Foo foo=\"bar\"/>, document.getElementById('foo')",
214   \     "descr": "props of React element `Foo`",
215   \     "type": "Blame",
216   \     "loc": {
217   \       "source": expand('%:p'),
218   \       "type": "SourceFile",
219   \       "start": {
220   \         "line": 6,
221   \         "column": 3,
222   \         "offset": 92
223   \       },
224   \       "end": {
225   \         "line": 6,
226   \         "column": 18,
227   \         "offset": 108
228   \       }
229   \     },
230   \     "path": expand('%:p'),
231   \     "line": 6,
232   \     "endline": 6,
233   \     "start": 3,
234   \     "end": 18
235   \   }]
236   \ }],
237   \ "passed": v:false
238   \}
239
240   let g:actual = ale_linters#javascript#flow#Handle(bufnr(''), [json_encode(g:flow_output)])
241   let g:expected = [
242   \ {
243   \   'lnum': 6,
244   \   'col': 3,
245   \   'type': 'E',
246   \   'text': 'property `bar`: Property not found in props of React element `Foo` See also: React element `Foo`',
247   \ }
248   \]
249
250   AssertEqual g:expected, g:actual
251
252 Execute(The flow handler should handle relative paths):
253   silent! noautocmd file /Users/rav/Projects/vim-ale-flow/index.js
254
255   let g:flow_output = {
256   \ "flowVersion": "0.44.0",
257   \ "errors": [{
258   \   "operation": {
259   \     "context": "  <Foo foo=\"bar\"/>, document.getElementById('foo')",
260   \     "descr": "React element `Foo`",
261   \     "type": "Blame",
262   \     "loc": {
263   \       "source": expand('%:p'),
264   \       "type": "SourceFile",
265   \       "start": {
266   \         "line": 6,
267   \         "column": 3,
268   \         "offset": 92
269   \       },
270   \       "end": {
271   \         "line": 6,
272   \         "column": 18,
273   \         "offset": 108
274   \       }
275   \     },
276   \     "path": expand('%:p'),
277   \     "line": 6,
278   \     "endline": 6,
279   \     "start": 3,
280   \     "end": 18
281   \   },
282   \   "kind": "infer",
283   \   "level": "error",
284   \   "message": [{
285   \     "context": "module.exports = function(props: Props) {",
286   \     "descr": "property `bar`",
287   \     "type": "Blame",
288   \     "loc": {
289   \       "source": "vim-ale-flow/foo.js",
290   \       "type": "SourceFile",
291   \       "start": {
292   \         "line": 9,
293   \         "column": 34,
294   \         "offset": 121
295   \       },
296   \       "end": {
297   \         "line": 9,
298   \         "column": 38,
299   \         "offset": 126
300   \       }
301   \     },
302   \     "path": "vim-ale-flow/foo.js",
303   \     "line": 9,
304   \     "endline": 9,
305   \     "start": 34,
306   \     "end": 38
307   \   }, {
308   \     "context": v:null,
309   \     "descr": "Property not found in",
310   \     "type": "Comment",
311   \     "path": "",
312   \     "line": 0,
313   \     "endline": 0,
314   \     "start": 1,
315   \     "end": 0
316   \   }, {
317   \     "context": "  <Foo foo=\"bar\"/>, document.getElementById('foo')",
318   \     "descr": "props of React element `Foo`",
319   \     "type": "Blame",
320   \     "loc": {
321   \       "source": expand('%:p'),
322   \       "type": "SourceFile",
323   \       "start": {
324   \         "line": 6,
325   \         "column": 3,
326   \         "offset": 92
327   \       },
328   \       "end": {
329   \         "line": 6,
330   \         "column": 18,
331   \         "offset": 108
332   \       }
333   \     },
334   \     "path": expand('%:p'),
335   \     "line": 6,
336   \     "endline": 6,
337   \     "start": 3,
338   \     "end": 18
339   \   }]
340   \ }],
341   \ "passed": v:false
342   \}
343
344   let g:actual = ale_linters#javascript#flow#Handle(bufnr(''), [json_encode(g:flow_output)])
345   let g:expected = [
346   \ {
347   \   'lnum': 6,
348   \   'col': 3,
349   \   'type': 'E',
350   \   'text': 'property `bar`: Property not found in props of React element `Foo` See also: React element `Foo`',
351   \ }
352   \]
353
354   AssertEqual g:expected, g:actual
355
356 Execute(The flow handler should handle extra errors):
357   silent! noautocmd file /Users/rav/Projects/vim-ale-flow/index.js
358
359   let g:flow_output = {
360   \  "flowVersion": "0.54.0",
361   \  "errors": [{
362   \    "extra": [{
363   \      "message": [{
364   \        "context": v:null,
365   \        "descr": "Property \`setVector\` is incompatible:",
366   \        "type": "Blame ",
367   \        "path": "",
368   \        "line": 0,
369   \        "endline": 0,
370   \        "start": 1,
371   \        "end": 0
372   \      }],
373   \      "children": [{
374   \        "message": [{
375   \          "context": "setVector = \{2\}",
376   \          "descr": "number ",
377   \          "type": "Blame ",
378   \          "loc": {
379   \            "source": expand('%:p'),
380   \            "type": "SourceFile ",
381   \            "start": {
382   \              "line": 90,
383   \              "column": 30,
384   \              "offset": 2296
385   \            },
386   \            "end": {
387   \              "line": 90,
388   \              "column": 30,
389   \              "offset": 2297
390   \            }
391   \          },
392   \          "path": expand('%:p'),
393   \          "line": 90,
394   \          "endline": 90,
395   \          "start": 30,
396   \          "end": 30
397   \        }, {
398   \          "context": v:null,
399   \          "descr": "This type is incompatible with ",
400   \          "type": "Comment ",
401   \          "path": "",
402   \          "line": 0,
403   \          "endline": 0,
404   \          "start": 1,
405   \          "end": 0
406   \        }, {
407   \          "context": "setVector: VectorType => void,",
408   \          "descr": "function type ",
409   \          "type": "Blame ",
410   \          "loc": {
411   \            "source": expand('%:p'),
412   \            "type": "SourceFile",
413   \            "start": {
414   \              "line": 9,
415   \              "column": 14,
416   \              "offset": 252
417   \            },
418   \            "end": {
419   \              "line": 9,
420   \              "column": 31,
421   \              "offset": 270
422   \            }
423   \          },
424   \          "path": expand('%:p'),
425   \          "line": 9,
426   \          "endline": 9,
427   \          "start": 14,
428   \          "end": 31
429   \        }]
430   \      }]
431   \    }],
432   \    "kind": "infer",
433   \    "level": "error",
434   \    "suppressions": [],
435   \    "message": [{
436   \      "context": " < New ",
437   \      "descr": "props of React element `New`",
438   \      "type": "Blame",
439   \      "loc": {
440   \        "source": "vim-ale-flow/foo.js",
441   \        "type": "SourceFile",
442   \        "start": {
443   \          "line": 89,
444   \          "column": 17,
445   \          "offset": 2262
446   \        },
447   \        "end": {
448   \          "line": 94,
449   \          "column": 18,
450   \          "offset": 2488
451   \        }
452   \      },
453   \      "path": "",
454   \      "line": 89,
455   \      "endline": 94,
456   \      "start": 17,
457   \      "end": 18
458   \    }, {
459   \      "context": v:null,
460   \      "descr": "This type is incompatible with",
461   \      "type": "Comment",
462   \      "path": "",
463   \      "line": 0,
464   \      "endline": 0,
465   \      "start": 1,
466   \      "end": 0
467   \    }, {
468   \      "context": "class New extends React.Component < NewProps,NewState > {",
469   \      "descr": "object type",
470   \      "type": "Blame",
471   \      "loc": {
472   \        "source": expand('%:p'),
473   \        "type": "SourceFile",
474   \        "start": {
475   \          "line": 20,
476   \          "column": 35,
477   \          "offset": 489
478   \        },
479   \        "end": {
480   \          "line": 20,
481   \          "column": 42,
482   \          "offset": 497
483   \        }
484   \      },
485   \      "path": expand('%:p'),
486   \      "line": 20,
487   \      "endline": 20,
488   \      "start": 35,
489   \      "end": 42
490   \    }]
491   \  }],
492   \  "passed": v:false
493   \}
494
495   let g:actual = ale_linters#javascript#flow#Handle(bufnr(''), [json_encode(g:flow_output)])
496   let g:expected = [
497   \ {
498   \   'lnum': 20,
499   \   'col': 35,
500   \   'type': 'E',
501   \   'text': 'props of React element `New`: This type is incompatible with object type',
502   \   'detail': 'props of React element `New`: This type is incompatible with object type'
503   \     .  "\nProperty `setVector` is incompatible: number  This type is incompatible with  function type ",
504   \ }
505   \]
506
507   AssertEqual g:expected, g:actual