summaryrefslogtreecommitdiff
path: root/test/handler/test_eslint_json_handler.vader
blob: 8e07bd801903489d55d0085c4119df56578d8dd7 (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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
Before:
  Save g:ale_javascript_eslint_suppress_eslintignore
  Save g:ale_javascript_eslint_suppress_missing_config
  Save g:ale_warn_about_trailing_whitespace
  Save g:ale_warn_about_trailing_blank_lines

  let g:ale_javascript_eslint_suppress_eslintignore = 0
  let g:ale_javascript_eslint_suppress_missing_config = 0
  let g:ale_warn_about_trailing_whitespace = 1
  let g:ale_warn_about_trailing_blank_lines = 1
  unlet! b:ale_warn_about_trailing_whitespace
  unlet! b:ale_warn_about_trailing_blank_lines

After:
  Restore

  unlet! b:ale_javascript_eslint_suppress_eslintignore
  unlet! b:ale_javascript_eslint_suppress_missing_config
  unlet! b:ale_warn_about_trailing_whitespace
  unlet! b:ale_warn_about_trailing_blank_lines
  unlet! g:config_error_lines

Execute(The eslint handler should parse json correctly):
  AssertEqual
  \ [
  \   {
  \     'lnum': 1,
  \     'end_lnum': 1,
  \     'col': 7,
  \     'end_col': 14,
  \     'text': '''variable'' is assigned a value but never used.',
  \     'code': 'no-unused-vars',
  \     'type': 'W',
  \   },
  \   {
  \     'lnum': 5,
  \     'col': 15,
  \     'text': 'Missing semicolon.',
  \     'code': 'semi',
  \     'type': 'W',
  \   },
  \   {
  \     'lnum': 7,
  \     'end_lnum': 7,
  \     'col': 7,
  \     'end_col': 14,
  \     'text': '''variable'' is already defined.',
  \     'code': 'no-redeclare',
  \     'type': 'E',
  \   },
  \ ],
  \ ale#handlers#eslint#HandleJSON(bufnr(''), [
  \ '[{"filePath":"foo.js","messages":[{"ruleId":"no-unused-vars","severity":1,"message":"''variable'' is assigned a value but never used.","line":1,"column":7,"nodeType":"Identifier","endLine":1,"endColumn":15},{"ruleId":"semi","severity":1,"message":"Missing semicolon.","line":5,"column":15,"nodeType":"ExpressionStatement","fix":{"range":[46,46],"text":";"}},{"ruleId":"no-redeclare","severity":2,"message":"''variable'' is already defined.","line":7,"column":7,"nodeType":"Identifier","endLine":7,"endColumn":15}],"errorCount":1,"warningCount":3,"fixableErrorCount":0,"fixableWarningCount":1,"source":"const variable = {\n    a: 3\n};\n\nconsole.log(1)\n\nclass variable {\n}\n"}]'
  \ ])

Execute(The eslint handler should print a message about a missing configuration file):
  let g:config_error_lines = [
  \   '',
  \   'Oops! Something went wrong! :(',
  \   '',
  \   'ESLint couldn''t find a configuration file. To set up a configuration file for this project, please run:',
  \   '    eslint --init',
  \   '',
  \   'ESLint looked for configuration files in /some/path/or/other and its ancestors.',
  \   '',
  \   'If you think you already have a configuration file or if you need more help, please stop by the ESLint chat room: https://gitter.im/eslint/eslint',
  \   '',
  \ ]

  AssertEqual
  \ [{
  \   'lnum': 1,
  \   'text': 'eslint configuration error (type :ALEDetail for more information)',
  \   'detail': join(g:config_error_lines, "\n"),
  \ }],
  \ ale#handlers#eslint#HandleJSON(bufnr(''), g:config_error_lines[:])

Execute(The eslint handler should allow the missing config error to be suppressed):
  let b:ale_javascript_eslint_suppress_missing_config = 1
  let g:config_error_lines = [
  \   '',
  \   'Oops! Something went wrong! :(',
  \   '',
  \   'ESLint couldn''t find a configuration file. To set up a configuration file for this project, please run:',
  \   '    eslint --init',
  \   '',
  \   'ESLint looked for configuration files in /some/path/or/other and its ancestors.',
  \   '',
  \   'If you think you already have a configuration file or if you need more help, please stop by the ESLint chat room: https://gitter.im/eslint/eslint',
  \   '',
  \ ]

  AssertEqual
  \ [],
  \ ale#handlers#eslint#HandleJSON(bufnr(''), g:config_error_lines[:])

Execute(The eslint handler should print a message for config parsing errors):
  let g:config_error_lines = [
  \ 'Cannot read config file: /some/path/or/other/.eslintrc.js',
  \ 'Error: Unexpected token <<',
  \ '/some/path/or/other/.eslintrc.js:1',
  \ '(function (exports, require, module, __filename, __dirname) { <<<>>>',
  \ '                                                              ^^',
  \ 'SyntaxError: Unexpected token <<',
  \ '    at Object.exports.runInThisContext (vm.js:76:16)',
  \ '    at Module._compile (module.js:528:28)',
  \ '    at Object.Module._extensions..js (module.js:565:10)',
  \ '    at Module.load (module.js:473:32)',
  \ '    at tryModuleLoad (module.js:432:12)',
  \ '    at Function.Module._load (module.js:424:3)',
  \ '    at Module.require (module.js:483:17)',
  \ '    at require (internal/module.js:20:19)',
  \ '    at module.exports (/usr/local/lib/node_modules/eslint/node_modules/require-uncached/index.js:14:12)',
  \ '    at loadJSConfigFile (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:160:16)',
  \]

  AssertEqual
  \ [{
  \   'lnum': 1,
  \   'text': 'eslint configuration error (type :ALEDetail for more information)',
  \   'detail': join(g:config_error_lines, "\n"),
  \ }],
  \ ale#handlers#eslint#HandleJSON(bufnr(''), g:config_error_lines[:])

Execute(Suppressing missing configs shouldn't suppress parsing errors):
  let b:ale_javascript_eslint_suppress_missing_config = 1
  let g:config_error_lines = [
  \ 'Cannot read config file: /some/path/or/other/.eslintrc.js',
  \ 'Error: Unexpected token <<',
  \ '/some/path/or/other/.eslintrc.js:1',
  \ '(function (exports, require, module, __filename, __dirname) { <<<>>>',
  \ '                                                              ^^',
  \ 'SyntaxError: Unexpected token <<',
  \ '    at Object.exports.runInThisContext (vm.js:76:16)',
  \ '    at Module._compile (module.js:528:28)',
  \ '    at Object.Module._extensions..js (module.js:565:10)',
  \ '    at Module.load (module.js:473:32)',
  \ '    at tryModuleLoad (module.js:432:12)',
  \ '    at Function.Module._load (module.js:424:3)',
  \ '    at Module.require (module.js:483:17)',
  \ '    at require (internal/module.js:20:19)',
  \ '    at module.exports (/usr/local/lib/node_modules/eslint/node_modules/require-uncached/index.js:14:12)',
  \ '    at loadJSConfigFile (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:160:16)',
  \]

  AssertEqual
  \ [{
  \   'lnum': 1,
  \   'text': 'eslint configuration error (type :ALEDetail for more information)',
  \   'detail': join(g:config_error_lines, "\n"),
  \ }],
  \ ale#handlers#eslint#HandleJSON(bufnr(''), g:config_error_lines[:])

Execute(The eslint handler should print a message for invalid configuration settings):
  let g:config_error_lines = [
  \ '/home/w0rp/git/wazoku/wazoku-spotlight/.eslintrc.js:',
  \ ' Configuration for rule "indent" is invalid:',
  \ ' Value "off" is the wrong type.',
  \ '',
  \ 'Error: /home/w0rp/git/wazoku/wazoku-spotlight/.eslintrc.js:',
  \ ' Configuration for rule "indent" is invalid:',
  \ ' Value "off" is the wrong type.',
  \ '',
  \ '    at validateRuleOptions (/usr/local/lib/node_modules/eslint/lib/config/config-validator.js:115:15)',
  \ '    at /usr/local/lib/node_modules/eslint/lib/config/config-validator.js:162:13',
  \ '    at Array.forEach (native)',
  \ '    at Object.validate (/usr/local/lib/node_modules/eslint/lib/config/config-validator.js:161:35)',
  \ '    at Object.load (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:522:19)',
  \ '    at loadConfig (/usr/local/lib/node_modules/eslint/lib/config.js:63:33)',
  \ '    at getLocalConfig (/usr/local/lib/node_modules/eslint/lib/config.js:130:29)',
  \ '    at Config.getConfig (/usr/local/lib/node_modules/eslint/lib/config.js:256:22)',
  \ '    at processText (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:224:33)',
  \ '    at CLIEngine.executeOnText (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:756:26)',
  \]

  AssertEqual
  \ [{
  \   'lnum': 1,
  \   'text': 'eslint configuration error (type :ALEDetail for more information)',
  \   'detail': join(g:config_error_lines, "\n"),
  \ }],
  \ ale#handlers#eslint#HandleJSON(bufnr(''), g:config_error_lines[:])

Execute(Suppressing missing configs shouldn't suppress invalid config errors):
  let b:ale_javascript_eslint_suppress_missing_config = 1
  let g:config_error_lines = [
  \ '/home/w0rp/git/wazoku/wazoku-spotlight/.eslintrc.js:',
  \ ' Configuration for rule "indent" is invalid:',
  \ ' Value "off" is the wrong type.',
  \ '',
  \ 'Error: /home/w0rp/git/wazoku/wazoku-spotlight/.eslintrc.js:',
  \ ' Configuration for rule "indent" is invalid:',
  \ ' Value "off" is the wrong type.',
  \ '',
  \ '    at validateRuleOptions (/usr/local/lib/node_modules/eslint/lib/config/config-validator.js:115:15)',
  \ '    at /usr/local/lib/node_modules/eslint/lib/config/config-validator.js:162:13',
  \ '    at Array.forEach (native)',
  \ '    at Object.validate (/usr/local/lib/node_modules/eslint/lib/config/config-validator.js:161:35)',
  \ '    at Object.load (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:522:19)',
  \ '    at loadConfig (/usr/local/lib/node_modules/eslint/lib/config.js:63:33)',
  \ '    at getLocalConfig (/usr/local/lib/node_modules/eslint/lib/config.js:130:29)',
  \ '    at Config.getConfig (/usr/local/lib/node_modules/eslint/lib/config.js:256:22)',
  \ '    at processText (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:224:33)',
  \ '    at CLIEngine.executeOnText (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:756:26)',
  \]

  AssertEqual
  \ [{
  \   'lnum': 1,
  \   'text': 'eslint configuration error (type :ALEDetail for more information)',
  \   'detail': join(g:config_error_lines, "\n"),
  \ }],
  \ ale#handlers#eslint#HandleJSON(bufnr(''), g:config_error_lines[:])

Execute(The eslint handler should print a message when import is not used in a module):
  let g:config_error_lines = [
  \ 'ImportDeclaration should appear when the mode is ES6 and in the module context.',
  \ 'AssertionError: ImportDeclaration should appear when the mode is ES6 and in the module context.',
  \ '    at Referencer.ImportDeclaration (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint-scope/lib/referencer.js:597:9)',
  \ '    at Referencer.Visitor.visit (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/esrecurse/esrecurse.js:122:34)',
  \ '    at Referencer.Visitor.visitChildren (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/esrecurse/esrecurse.js:101:38)',
  \ '    at Referencer.Program (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint-scope/lib/referencer.js:449:14)',
  \ '    at Referencer.Visitor.visit (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/esrecurse/esrecurse.js:122:34)',
  \ '    at Object.analyze (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint-scope/lib/index.js:138:16)',
  \ '    at EventEmitter.module.exports.api.verify (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/eslint.js:887:40)',
  \ '    at processText (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/cli-engine.js:278:31)',
  \ '    at CLIEngine.executeOnText (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/cli-engine.js:734:26)',
  \ '    at Object.execute (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/cli.js:171:42)   ',
  \]

  AssertEqual
  \ [{
  \   'lnum': 1,
  \   'text': 'eslint configuration error (type :ALEDetail for more information)',
  \   'detail': join(g:config_error_lines, "\n"),
  \ }],
  \ ale#handlers#eslint#HandleJSON(bufnr(''), g:config_error_lines[:])

Execute(Suppressing missing configs shouldn't suppress module import errors):
  let b:ale_javascript_eslint_suppress_missing_config = 1
  let g:config_error_lines = [
  \ 'ImportDeclaration should appear when the mode is ES6 and in the module context.',
  \ 'AssertionError: ImportDeclaration should appear when the mode is ES6 and in the module context.',
  \ '    at Referencer.ImportDeclaration (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint-scope/lib/referencer.js:597:9)',
  \ '    at Referencer.Visitor.visit (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/esrecurse/esrecurse.js:122:34)',
  \ '    at Referencer.Visitor.visitChildren (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/esrecurse/esrecurse.js:101:38)',
  \ '    at Referencer.Program (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint-scope/lib/referencer.js:449:14)',
  \ '    at Referencer.Visitor.visit (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/esrecurse/esrecurse.js:122:34)',
  \ '    at Object.analyze (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint-scope/lib/index.js:138:16)',
  \ '    at EventEmitter.module.exports.api.verify (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/eslint.js:887:40)',
  \ '    at processText (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/cli-engine.js:278:31)',
  \ '    at CLIEngine.executeOnText (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/cli-engine.js:734:26)',
  \ '    at Object.execute (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/cli.js:171:42)   ',
  \]

  AssertEqual
  \ [{
  \   'lnum': 1,
  \   'text': 'eslint configuration error (type :ALEDetail for more information)',
  \   'detail': join(g:config_error_lines, "\n"),
  \ }],
  \ ale#handlers#eslint#HandleJSON(bufnr(''), g:config_error_lines[:])

Execute(The eslint handler should hint about using typescript-eslint-parser):
  silent! noautocmd file foo.ts

  AssertEqual
  \ [
  \   {
  \     'lnum': 2,
  \     'col': 1,
  \     'text': 'Parsing error (You may need configure typescript-eslint-parser): The keyword ''interface'' is reserved',
  \     'type': 'E',
  \   },
  \ ],
  \ ale#handlers#eslint#HandleJSON(bufnr(''), [
  \ '[{"filePath":"foo.ts","messages":[{"ruleId":null,"fatal":true,"severity":2,"message":"Parsing error: The keyword ''interface'' is reserved","line":2,"column":1}],"errorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":"\ninterface test {}\n"}]',
  \ ])

Execute(eslint should warn about ignored files by default):
  AssertEqual
  \ [{
  \    'lnum': 0,
  \    'type': 'W',
  \    'text': 'File ignored because of a matching ignore pattern. Use "--no-ignore" to override.'
  \ }],
  \ ale#handlers#eslint#HandleJSON(bufnr(''), [
  \  '[{"filePath":"/path/to/some/ignored/file.js","messages":[{"fatal":false,"severity":1,"message":"File ignored because of a matching ignore pattern. Use \"--no-ignore\" to override."}],"errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0}]',
  \ ])

  AssertEqual
  \ [{
  \    'lnum': 0,
  \    'type': 'W',
  \    'text': 'File ignored by default. Use "--ignore-pattern ''!node_modules/*''" to override.',
  \ }],
  \ ale#handlers#eslint#HandleJSON(bufnr(''), [
  \  '[{"filePath":"/path/to/some/ignored/file.js","messages":[{"fatal":false,"severity":1,"message":"File ignored by default. Use \"--ignore-pattern ''!node_modules/*''\" to override."}],"errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0}]',
  \ ])

Execute(eslint should not warn about ignored files when explicitly disabled):
  let g:ale_javascript_eslint_suppress_eslintignore = 1

  AssertEqual
  \ [],
  \ ale#handlers#eslint#HandleJSON(bufnr(''), [
  \  '[{"filePath":"/path/to/some/ignored/file.js","messages":[{"fatal":false,"severity":1,"message":"File ignored because of a matching ignore pattern. Use \"--no-ignore\" to override."}],"errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0}]',
  \ ])

  AssertEqual
  \ [],
  \ ale#handlers#eslint#HandleJSON(bufnr(''), [
  \  '[{"filePath":"/path/to/some/ignored/file.js","messages":[{"fatal":false,"severity":1,"message":"File ignored by default. Use \"--ignore-pattern ''!node_modules/*''\" to override."}],"errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0}]',
  \ ])

Execute(Failing to connect to eslint_d should be handled correctly):
  AssertEqual
  \ [
  \   {
  \     'lnum': 1,
  \     'text': 'Could not connect to eslint_d. Try updating eslint_d or killing it.',
  \   },
  \ ],
  \ ale#handlers#eslint#HandleJSON(bufnr(''), [
  \  'Could not connect',
  \ ])

Execute(Disabling warnings about trailing spaces should work):
  silent! noautocmd file foo.ts

  AssertEqual
  \ [
  \   {
  \     'lnum': 2,
  \     'col': 16,
  \     'code': 'no-trailing-spaces',
  \     'type': 'W',
  \     'text': 'Trailing spaces not allowed.',
  \   },
  \ ],
  \ ale#handlers#eslint#HandleJSON(bufnr(''), [
  \ '[{"filePath":"foo.js","messages":[{"ruleId":"no-trailing-spaces","severity":1,"message":"Trailing spaces not allowed.","line":2,"column":16,"nodeType":"Program","fix":{"range":[16,17],"text":""}}],"errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":1,"source":"\nconsole.log(1); \n"}]'
  \ ])

  let g:ale_warn_about_trailing_whitespace = 0

  AssertEqual
  \ [],
  \ ale#handlers#eslint#HandleJSON(bufnr(''), [
  \ '[{"filePath":"foo.js","messages":[{"ruleId":"no-trailing-spaces","severity":1,"message":"Trailing spaces not allowed.","line":2,"column":16,"nodeType":"Program","fix":{"range":[16,17],"text":""}}],"errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":1,"source":"\nconsole.log(1); \n"}]'
  \ ])

  let g:ale_warn_about_trailing_whitespace = 1
  let b:ale_warn_about_trailing_whitespace = 0

  AssertEqual
  \ [],
  \ ale#handlers#eslint#HandleJSON(bufnr(''), [
  \ '[{"filePath":"foo.js","messages":[{"ruleId":"no-trailing-spaces","severity":1,"message":"Trailing spaces not allowed.","line":2,"column":16,"nodeType":"Program","fix":{"range":[16,17],"text":""}}],"errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":1,"source":"\nconsole.log(1); \n"}]'
  \ ])