test_eslint_handler.vader
1 Before: 2 Save g:ale_javascript_eslint_suppress_eslintignore 3 Save g:ale_javascript_eslint_suppress_missing_config 4 Save g:ale_warn_about_trailing_whitespace 5 Save g:ale_warn_about_trailing_blank_lines 6 7 let g:ale_javascript_eslint_suppress_eslintignore = 0 8 let g:ale_javascript_eslint_suppress_missing_config = 0 9 let g:ale_warn_about_trailing_whitespace = 1 10 let g:ale_warn_about_trailing_blank_lines = 1 11 unlet! b:ale_warn_about_trailing_whitespace 12 unlet! b:ale_warn_about_trailing_blank_lines 13 14 After: 15 Restore 16 17 unlet! b:ale_javascript_eslint_suppress_eslintignore 18 unlet! b:ale_javascript_eslint_suppress_missing_config 19 unlet! b:ale_warn_about_trailing_whitespace 20 unlet! b:ale_warn_about_trailing_blank_lines 21 unlet! g:config_error_lines 22 23 Execute(The eslint handler should parse lines correctly): 24 AssertEqual 25 \ [ 26 \ { 27 \ 'lnum': 47, 28 \ 'col': 14, 29 \ 'text': 'Missing trailing comma.', 30 \ 'code': 'comma-dangle', 31 \ 'type': 'W', 32 \ }, 33 \ { 34 \ 'lnum': 56, 35 \ 'col': 41, 36 \ 'text': 'Missing semicolon.', 37 \ 'code': 'semi', 38 \ 'type': 'E', 39 \ }, 40 \ { 41 \ 'lnum': 13, 42 \ 'col': 3, 43 \ 'text': 'Parsing error: Unexpected token', 44 \ 'type': 'E', 45 \ }, 46 \ ], 47 \ ale#handlers#eslint#Handle(bufnr(''), [ 48 \ 'This line should be ignored completely', 49 \ '/path/to/some-filename.js:47:14: Missing trailing comma. [Warning/comma-dangle]', 50 \ '/path/to/some-filename.js:56:41: Missing semicolon. [Error/semi]', 51 \ 'This line should be ignored completely', 52 \ '/path/to/some-filename.js:13:3: Parsing error: Unexpected token', 53 \ ]) 54 55 Execute(The eslint handler should print a message about a missing configuration file): 56 let g:config_error_lines = [ 57 \ '', 58 \ 'Oops! Something went wrong! :(', 59 \ '', 60 \ 'ESLint couldn''t find a configuration file. To set up a configuration file for this project, please run:', 61 \ ' eslint --init', 62 \ '', 63 \ 'ESLint looked for configuration files in /some/path/or/other and its ancestors.', 64 \ '', 65 \ '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', 66 \ '', 67 \ ] 68 69 AssertEqual 70 \ [{ 71 \ 'lnum': 1, 72 \ 'text': 'eslint configuration error (type :ALEDetail for more information)', 73 \ 'detail': join(g:config_error_lines, "\n"), 74 \ }], 75 \ ale#handlers#eslint#Handle(bufnr(''), g:config_error_lines[:]) 76 77 Execute(The eslint handler should allow the missing config error to be suppressed): 78 let b:ale_javascript_eslint_suppress_missing_config = 1 79 let g:config_error_lines = [ 80 \ '', 81 \ 'Oops! Something went wrong! :(', 82 \ '', 83 \ 'ESLint couldn''t find a configuration file. To set up a configuration file for this project, please run:', 84 \ ' eslint --init', 85 \ '', 86 \ 'ESLint looked for configuration files in /some/path/or/other and its ancestors.', 87 \ '', 88 \ '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', 89 \ '', 90 \ ] 91 92 AssertEqual 93 \ [], 94 \ ale#handlers#eslint#Handle(bufnr(''), g:config_error_lines[:]) 95 96 Execute(The eslint handler should print a message for config parsing errors): 97 let g:config_error_lines = [ 98 \ 'Cannot read config file: /some/path/or/other/.eslintrc.js', 99 \ 'Error: Unexpected token <<', 100 \ '/some/path/or/other/.eslintrc.js:1', 101 \ '(function (exports, require, module, __filename, __dirname) { <<<>>>', 102 \ ' ^^', 103 \ 'SyntaxError: Unexpected token <<', 104 \ ' at Object.exports.runInThisContext (vm.js:76:16)', 105 \ ' at Module._compile (module.js:528:28)', 106 \ ' at Object.Module._extensions..js (module.js:565:10)', 107 \ ' at Module.load (module.js:473:32)', 108 \ ' at tryModuleLoad (module.js:432:12)', 109 \ ' at Function.Module._load (module.js:424:3)', 110 \ ' at Module.require (module.js:483:17)', 111 \ ' at require (internal/module.js:20:19)', 112 \ ' at module.exports (/usr/local/lib/node_modules/eslint/node_modules/require-uncached/index.js:14:12)', 113 \ ' at loadJSConfigFile (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:160:16)', 114 \] 115 116 AssertEqual 117 \ [{ 118 \ 'lnum': 1, 119 \ 'text': 'eslint configuration error (type :ALEDetail for more information)', 120 \ 'detail': join(g:config_error_lines, "\n"), 121 \ }], 122 \ ale#handlers#eslint#Handle(bufnr(''), g:config_error_lines[:]) 123 124 Execute(Suppressing missing configs shouldn't suppress parsing errors): 125 let b:ale_javascript_eslint_suppress_missing_config = 1 126 let g:config_error_lines = [ 127 \ 'Cannot read config file: /some/path/or/other/.eslintrc.js', 128 \ 'Error: Unexpected token <<', 129 \ '/some/path/or/other/.eslintrc.js:1', 130 \ '(function (exports, require, module, __filename, __dirname) { <<<>>>', 131 \ ' ^^', 132 \ 'SyntaxError: Unexpected token <<', 133 \ ' at Object.exports.runInThisContext (vm.js:76:16)', 134 \ ' at Module._compile (module.js:528:28)', 135 \ ' at Object.Module._extensions..js (module.js:565:10)', 136 \ ' at Module.load (module.js:473:32)', 137 \ ' at tryModuleLoad (module.js:432:12)', 138 \ ' at Function.Module._load (module.js:424:3)', 139 \ ' at Module.require (module.js:483:17)', 140 \ ' at require (internal/module.js:20:19)', 141 \ ' at module.exports (/usr/local/lib/node_modules/eslint/node_modules/require-uncached/index.js:14:12)', 142 \ ' at loadJSConfigFile (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:160:16)', 143 \] 144 145 AssertEqual 146 \ [{ 147 \ 'lnum': 1, 148 \ 'text': 'eslint configuration error (type :ALEDetail for more information)', 149 \ 'detail': join(g:config_error_lines, "\n"), 150 \ }], 151 \ ale#handlers#eslint#Handle(bufnr(''), g:config_error_lines[:]) 152 153 Execute(The eslint handler should print a message for invalid configuration settings): 154 let g:config_error_lines = [ 155 \ '/home/w0rp/git/wazoku/wazoku-spotlight/.eslintrc.js:', 156 \ ' Configuration for rule "indent" is invalid:', 157 \ ' Value "off" is the wrong type.', 158 \ '', 159 \ 'Error: /home/w0rp/git/wazoku/wazoku-spotlight/.eslintrc.js:', 160 \ ' Configuration for rule "indent" is invalid:', 161 \ ' Value "off" is the wrong type.', 162 \ '', 163 \ ' at validateRuleOptions (/usr/local/lib/node_modules/eslint/lib/config/config-validator.js:115:15)', 164 \ ' at /usr/local/lib/node_modules/eslint/lib/config/config-validator.js:162:13', 165 \ ' at Array.forEach (native)', 166 \ ' at Object.validate (/usr/local/lib/node_modules/eslint/lib/config/config-validator.js:161:35)', 167 \ ' at Object.load (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:522:19)', 168 \ ' at loadConfig (/usr/local/lib/node_modules/eslint/lib/config.js:63:33)', 169 \ ' at getLocalConfig (/usr/local/lib/node_modules/eslint/lib/config.js:130:29)', 170 \ ' at Config.getConfig (/usr/local/lib/node_modules/eslint/lib/config.js:256:22)', 171 \ ' at processText (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:224:33)', 172 \ ' at CLIEngine.executeOnText (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:756:26)', 173 \] 174 175 AssertEqual 176 \ [{ 177 \ 'lnum': 1, 178 \ 'text': 'eslint configuration error (type :ALEDetail for more information)', 179 \ 'detail': join(g:config_error_lines, "\n"), 180 \ }], 181 \ ale#handlers#eslint#Handle(bufnr(''), g:config_error_lines[:]) 182 183 Execute(Suppressing missing configs shouldn't suppress invalid config errors): 184 let b:ale_javascript_eslint_suppress_missing_config = 1 185 let g:config_error_lines = [ 186 \ '/home/w0rp/git/wazoku/wazoku-spotlight/.eslintrc.js:', 187 \ ' Configuration for rule "indent" is invalid:', 188 \ ' Value "off" is the wrong type.', 189 \ '', 190 \ 'Error: /home/w0rp/git/wazoku/wazoku-spotlight/.eslintrc.js:', 191 \ ' Configuration for rule "indent" is invalid:', 192 \ ' Value "off" is the wrong type.', 193 \ '', 194 \ ' at validateRuleOptions (/usr/local/lib/node_modules/eslint/lib/config/config-validator.js:115:15)', 195 \ ' at /usr/local/lib/node_modules/eslint/lib/config/config-validator.js:162:13', 196 \ ' at Array.forEach (native)', 197 \ ' at Object.validate (/usr/local/lib/node_modules/eslint/lib/config/config-validator.js:161:35)', 198 \ ' at Object.load (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:522:19)', 199 \ ' at loadConfig (/usr/local/lib/node_modules/eslint/lib/config.js:63:33)', 200 \ ' at getLocalConfig (/usr/local/lib/node_modules/eslint/lib/config.js:130:29)', 201 \ ' at Config.getConfig (/usr/local/lib/node_modules/eslint/lib/config.js:256:22)', 202 \ ' at processText (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:224:33)', 203 \ ' at CLIEngine.executeOnText (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:756:26)', 204 \] 205 206 AssertEqual 207 \ [{ 208 \ 'lnum': 1, 209 \ 'text': 'eslint configuration error (type :ALEDetail for more information)', 210 \ 'detail': join(g:config_error_lines, "\n"), 211 \ }], 212 \ ale#handlers#eslint#Handle(bufnr(''), g:config_error_lines[:]) 213 214 Execute(The eslint handler should print a message when import is not used in a module): 215 let g:config_error_lines = [ 216 \ 'ImportDeclaration should appear when the mode is ES6 and in the module context.', 217 \ 'AssertionError: ImportDeclaration should appear when the mode is ES6 and in the module context.', 218 \ ' at Referencer.ImportDeclaration (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint-scope/lib/referencer.js:597:9)', 219 \ ' at Referencer.Visitor.visit (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/esrecurse/esrecurse.js:122:34)', 220 \ ' at Referencer.Visitor.visitChildren (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/esrecurse/esrecurse.js:101:38)', 221 \ ' at Referencer.Program (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint-scope/lib/referencer.js:449:14)', 222 \ ' at Referencer.Visitor.visit (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/esrecurse/esrecurse.js:122:34)', 223 \ ' at Object.analyze (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint-scope/lib/index.js:138:16)', 224 \ ' at EventEmitter.module.exports.api.verify (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/eslint.js:887:40)', 225 \ ' at processText (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/cli-engine.js:278:31)', 226 \ ' at CLIEngine.executeOnText (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/cli-engine.js:734:26)', 227 \ ' at Object.execute (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/cli.js:171:42) ', 228 \] 229 230 AssertEqual 231 \ [{ 232 \ 'lnum': 1, 233 \ 'text': 'eslint configuration error (type :ALEDetail for more information)', 234 \ 'detail': join(g:config_error_lines, "\n"), 235 \ }], 236 \ ale#handlers#eslint#Handle(bufnr(''), g:config_error_lines[:]) 237 238 Execute(Suppressing missing configs shouldn't suppress module import errors): 239 let b:ale_javascript_eslint_suppress_missing_config = 1 240 let g:config_error_lines = [ 241 \ 'ImportDeclaration should appear when the mode is ES6 and in the module context.', 242 \ 'AssertionError: ImportDeclaration should appear when the mode is ES6 and in the module context.', 243 \ ' at Referencer.ImportDeclaration (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint-scope/lib/referencer.js:597:9)', 244 \ ' at Referencer.Visitor.visit (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/esrecurse/esrecurse.js:122:34)', 245 \ ' at Referencer.Visitor.visitChildren (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/esrecurse/esrecurse.js:101:38)', 246 \ ' at Referencer.Program (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint-scope/lib/referencer.js:449:14)', 247 \ ' at Referencer.Visitor.visit (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/esrecurse/esrecurse.js:122:34)', 248 \ ' at Object.analyze (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint-scope/lib/index.js:138:16)', 249 \ ' at EventEmitter.module.exports.api.verify (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/eslint.js:887:40)', 250 \ ' at processText (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/cli-engine.js:278:31)', 251 \ ' at CLIEngine.executeOnText (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/cli-engine.js:734:26)', 252 \ ' at Object.execute (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/cli.js:171:42) ', 253 \] 254 255 AssertEqual 256 \ [{ 257 \ 'lnum': 1, 258 \ 'text': 'eslint configuration error (type :ALEDetail for more information)', 259 \ 'detail': join(g:config_error_lines, "\n"), 260 \ }], 261 \ ale#handlers#eslint#Handle(bufnr(''), g:config_error_lines[:]) 262 263 264 Execute(The eslint handler should output end_col values where appropriate): 265 AssertEqual 266 \ [ 267 \ { 268 \ 'lnum': 4, 269 \ 'col': 3, 270 \ 'end_col': 15, 271 \ 'text': 'Parsing error: Unexpected token ''some string''', 272 \ 'type': 'E', 273 \ }, 274 \ { 275 \ 'lnum': 70, 276 \ 'col': 3, 277 \ 'end_col': 5, 278 \ 'text': '''foo'' is not defined.', 279 \ 'code': 'no-undef', 280 \ 'type': 'E', 281 \ }, 282 \ { 283 \ 'lnum': 71, 284 \ 'col': 2, 285 \ 'end_col': 6, 286 \ 'text': 'Unexpected `await` inside a loop.', 287 \ 'code': 'no-await-in-loop', 288 \ 'type': 'E', 289 \ }, 290 \ { 291 \ 'lnum': 72, 292 \ 'col': 6, 293 \ 'end_col': 10, 294 \ 'text': 'Redundant use of `await` on a return value.', 295 \ 'code': 'no-return-await', 296 \ 'type': 'E', 297 \ }, 298 \ { 299 \ 'lnum': 73, 300 \ 'col': 4, 301 \ 'end_col': 10, 302 \ 'text': 'Unexpected console statement', 303 \ 'code': 'no-console', 304 \ 'type': 'E', 305 \ }, 306 \ { 307 \ 'lnum': 74, 308 \ 'col': 4, 309 \ 'end_col': 11, 310 \ 'text': 'Unexpected ''debugger'' statement.', 311 \ 'code': 'no-debugger', 312 \ 'type': 'E', 313 \ }, 314 \ ], 315 \ ale#handlers#eslint#Handle(bufnr(''), [ 316 \ 'app.js:4:3: Parsing error: Unexpected token ''some string'' [Error]', 317 \ 'app.js:70:3: ''foo'' is not defined. [Error/no-undef]', 318 \ 'app.js:71:2: Unexpected `await` inside a loop. [Error/no-await-in-loop]', 319 \ 'app.js:72:6: Redundant use of `await` on a return value. [Error/no-return-await]', 320 \ 'app.js:73:4: Unexpected console statement [Error/no-console]', 321 \ 'app.js:74:4: Unexpected ''debugger'' statement. [Error/no-debugger]', 322 \ ]) 323 324 Execute(The eslint hint about using typescript-eslint-parser): 325 silent! noautocmd file foo.ts 326 327 AssertEqual 328 \ [ 329 \ { 330 \ 'lnum': 451, 331 \ 'col': 2, 332 \ 'end_col': 2, 333 \ 'text': 'Parsing error (You may need configure typescript-eslint-parser): Unexpected token )', 334 \ 'type': 'E', 335 \ }, 336 \ ], 337 \ ale#handlers#eslint#Handle(bufnr(''), [ 338 \ 'foo.ts:451:2: Parsing error: Unexpected token ) [Error]', 339 \ ]) 340 341 Execute(eslint should warn about ignored files by default): 342 AssertEqual 343 \ [{ 344 \ 'lnum': 0, 345 \ 'col': 0, 346 \ 'type': 'W', 347 \ 'text': 'File ignored because of a matching ignore pattern. Use "--no-ignore" to override.' 348 \ }], 349 \ ale#handlers#eslint#Handle(bufnr(''), [ 350 \ '/path/to/some/ignored.js:0:0: File ignored because of a matching ignore pattern. Use "--no-ignore" to override. [Warning]', 351 \ ]) 352 353 AssertEqual 354 \ [{ 355 \ 'lnum': 0, 356 \ 'col': 0, 357 \ 'type': 'W', 358 \ 'text': 'File ignored by default. Use "--ignore-pattern ''!node_modules/*''" to override.', 359 \ }], 360 \ ale#handlers#eslint#Handle(bufnr(''), [ 361 \ '/path/to/some/ignored.js:0:0: File ignored by default. Use "--ignore-pattern ''!node_modules/*''" to override. [Warning]', 362 \ ]) 363 364 Execute(eslint should not warn about ignored files when explicitly disabled): 365 let g:ale_javascript_eslint_suppress_eslintignore = 1 366 367 AssertEqual 368 \ [], 369 \ ale#handlers#eslint#Handle(bufnr(''), [ 370 \ '/path/to/some/ignored.js:0:0: File ignored because of a matching ignore pattern. Use "--no-ignore" to override. [Warning]', 371 \ ]) 372 373 AssertEqual 374 \ [], 375 \ ale#handlers#eslint#Handle(bufnr(''), [ 376 \ '/path/to/some/ignored.js:0:0: File ignored by default. Use "--ignore-pattern ''!node_modules/*''" to override. [Warning]', 377 \ ]) 378 379 Execute(eslint should handle react errors correctly): 380 AssertEqual 381 \ [ 382 \ { 383 \ 'lnum': 59, 384 \ 'col': 9, 385 \ 'type': 'E', 386 \ 'text': 'Property should be placed on the same line as the component declaration', 387 \ 'code': 'react/jsx-first-prop-new-line', 388 \ }, 389 \ ], 390 \ ale#handlers#eslint#Handle(bufnr(''), [ 391 \ '/path/editor-help.jsx:59:9: Property should be placed on the same line as the component declaration [Error/react/jsx-first-prop-new-line]', 392 \ ]) 393 394 Execute(Failing to connect to eslint_d should be handled correctly): 395 AssertEqual 396 \ [ 397 \ { 398 \ 'lnum': 1, 399 \ 'text': 'Could not connect to eslint_d. Try updating eslint_d or killing it.', 400 \ }, 401 \ ], 402 \ ale#handlers#eslint#Handle(bufnr(''), [ 403 \ 'Could not connect', 404 \ ]) 405 406 Execute(Disabling warnings about trailing spaces should work): 407 silent! noautocmd file foo.ts 408 409 AssertEqual 410 \ [ 411 \ { 412 \ 'lnum': 182, 413 \ 'col': 22, 414 \ 'code': 'no-trailing-spaces', 415 \ 'type': 'E', 416 \ 'text': 'Trailing spaces not allowed.', 417 \ }, 418 \ ], 419 \ ale#handlers#eslint#Handle(bufnr(''), [ 420 \ 'foo.js:182:22: Trailing spaces not allowed. [Error/no-trailing-spaces]', 421 \ ]) 422 423 let g:ale_warn_about_trailing_whitespace = 0 424 425 AssertEqual 426 \ [], 427 \ ale#handlers#eslint#Handle(bufnr(''), [ 428 \ 'foo.js:182:22: Trailing spaces not allowed. [Error/no-trailing-spaces]', 429 \ ]) 430 431 let g:ale_warn_about_trailing_whitespace = 1 432 let b:ale_warn_about_trailing_whitespace = 0 433 434 AssertEqual 435 \ [], 436 \ ale#handlers#eslint#Handle(bufnr(''), [ 437 \ 'foo.js:182:22: Trailing spaces not allowed. [Error/no-trailing-spaces]', 438 \ ])