test_eslint_json_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 json correctly): 24 call ale#test#SetFilename('foo.js') 25 AssertEqual 26 \ [ 27 \ { 28 \ 'lnum': 1, 29 \ 'end_lnum': 1, 30 \ 'col': 7, 31 \ 'end_col': 14, 32 \ 'text': '''variable'' is assigned a value but never used.', 33 \ 'code': 'no-unused-vars', 34 \ 'type': 'W', 35 \ }, 36 \ { 37 \ 'lnum': 5, 38 \ 'col': 15, 39 \ 'text': 'Missing semicolon.', 40 \ 'code': 'semi', 41 \ 'type': 'W', 42 \ }, 43 \ { 44 \ 'lnum': 7, 45 \ 'end_lnum': 7, 46 \ 'col': 7, 47 \ 'end_col': 14, 48 \ 'text': '''variable'' is already defined.', 49 \ 'code': 'no-redeclare', 50 \ 'type': 'E', 51 \ }, 52 \ ], 53 \ ale#handlers#eslint#HandleJSON(bufnr(''), [ 54 \ '[{"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"}]' 55 \ ]) 56 57 Execute(The eslint handler should suppress deprecation warnings): 58 call ale#test#SetFilename('foo.js') 59 AssertEqual 60 \ [ 61 \ { 62 \ 'lnum': 1, 63 \ 'col': 9, 64 \ 'text': 'Parsing error: Unexpected token Controller', 65 \ 'type': 'E', 66 \ } 67 \ ], 68 \ ale#handlers#eslint#HandleJSON(bufnr(''), [ 69 \ '[{"filePath":"foo.js","messages":[{"ruleId":null,"fatal":true,"severity":2 ,"message":"Parsing error: Unexpected token Controller","line":1,"column":9}],"errorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount": 0,"source":"i:mport Controller from \"@ember/controller\";\nimport listViewControllerMixin from \"elearning/mixins/list-view-controller\";\nimport { inject as service } from \"@ember/service\";\n\nexport default Controller.extend(listViewControllerMixin(), {\n modelName: \"notification\",\n intl: service(),\n\n flatpickrLocale: computed(\"intl.locale\", function() {\n return this.intl.locale.firstObject.split(\"-\")[0];\n })\n});\n"}]', '(node:616989) [ESLINT_LEGACY_OBJECT_REST_SPREAD] DeprecationWarning: The ''parserOptions.ecmaFeatures.experimentalObjectRestSpread'' option is deprecated. Use ''parser Options.ecmaVersion'' instead. (found in "node_modules/eslint-plugin-ember/lib/config/base.js")]' 70 \ ]) 71 72 Execute(The eslint handler should print a message about a missing configuration file): 73 let g:config_error_lines = [ 74 \ '', 75 \ 'Oops! Something went wrong! :(', 76 \ '', 77 \ 'ESLint couldn''t find a configuration file. To set up a configuration file for this project, please run:', 78 \ ' eslint --init', 79 \ '', 80 \ 'ESLint looked for configuration files in /some/path/or/other and its ancestors.', 81 \ '', 82 \ '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', 83 \ '', 84 \ ] 85 86 AssertEqual 87 \ [{ 88 \ 'lnum': 1, 89 \ 'text': 'eslint configuration error (type :ALEDetail for more information)', 90 \ 'detail': join(g:config_error_lines, "\n"), 91 \ }], 92 \ ale#handlers#eslint#HandleJSON(bufnr(''), g:config_error_lines[:]) 93 94 Execute(The eslint handler should allow the missing config error to be suppressed): 95 let b:ale_javascript_eslint_suppress_missing_config = 1 96 let g:config_error_lines = [ 97 \ '', 98 \ 'Oops! Something went wrong! :(', 99 \ '', 100 \ 'ESLint couldn''t find a configuration file. To set up a configuration file for this project, please run:', 101 \ ' eslint --init', 102 \ '', 103 \ 'ESLint looked for configuration files in /some/path/or/other and its ancestors.', 104 \ '', 105 \ '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', 106 \ '', 107 \ ] 108 109 AssertEqual 110 \ [], 111 \ ale#handlers#eslint#HandleJSON(bufnr(''), g:config_error_lines[:]) 112 113 Execute(The eslint handler should print a message for config parsing errors): 114 let g:config_error_lines = [ 115 \ 'Cannot read config file: /some/path/or/other/.eslintrc.js', 116 \ 'Error: Unexpected token <<', 117 \ '/some/path/or/other/.eslintrc.js:1', 118 \ '(function (exports, require, module, __filename, __dirname) { <<<>>>', 119 \ ' ^^', 120 \ 'SyntaxError: Unexpected token <<', 121 \ ' at Object.exports.runInThisContext (vm.js:76:16)', 122 \ ' at Module._compile (module.js:528:28)', 123 \ ' at Object.Module._extensions..js (module.js:565:10)', 124 \ ' at Module.load (module.js:473:32)', 125 \ ' at tryModuleLoad (module.js:432:12)', 126 \ ' at Function.Module._load (module.js:424:3)', 127 \ ' at Module.require (module.js:483:17)', 128 \ ' at require (internal/module.js:20:19)', 129 \ ' at module.exports (/usr/local/lib/node_modules/eslint/node_modules/require-uncached/index.js:14:12)', 130 \ ' at loadJSConfigFile (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:160:16)', 131 \] 132 133 AssertEqual 134 \ [{ 135 \ 'lnum': 1, 136 \ 'text': 'eslint configuration error (type :ALEDetail for more information)', 137 \ 'detail': join(g:config_error_lines, "\n"), 138 \ }], 139 \ ale#handlers#eslint#HandleJSON(bufnr(''), g:config_error_lines[:]) 140 141 Execute(Suppressing missing configs shouldn't suppress parsing errors): 142 let b:ale_javascript_eslint_suppress_missing_config = 1 143 let g:config_error_lines = [ 144 \ 'Cannot read config file: /some/path/or/other/.eslintrc.js', 145 \ 'Error: Unexpected token <<', 146 \ '/some/path/or/other/.eslintrc.js:1', 147 \ '(function (exports, require, module, __filename, __dirname) { <<<>>>', 148 \ ' ^^', 149 \ 'SyntaxError: Unexpected token <<', 150 \ ' at Object.exports.runInThisContext (vm.js:76:16)', 151 \ ' at Module._compile (module.js:528:28)', 152 \ ' at Object.Module._extensions..js (module.js:565:10)', 153 \ ' at Module.load (module.js:473:32)', 154 \ ' at tryModuleLoad (module.js:432:12)', 155 \ ' at Function.Module._load (module.js:424:3)', 156 \ ' at Module.require (module.js:483:17)', 157 \ ' at require (internal/module.js:20:19)', 158 \ ' at module.exports (/usr/local/lib/node_modules/eslint/node_modules/require-uncached/index.js:14:12)', 159 \ ' at loadJSConfigFile (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:160:16)', 160 \] 161 162 AssertEqual 163 \ [{ 164 \ 'lnum': 1, 165 \ 'text': 'eslint configuration error (type :ALEDetail for more information)', 166 \ 'detail': join(g:config_error_lines, "\n"), 167 \ }], 168 \ ale#handlers#eslint#HandleJSON(bufnr(''), g:config_error_lines[:]) 169 170 Execute(The eslint handler should print a message for invalid configuration settings): 171 let g:config_error_lines = [ 172 \ '/home/w0rp/git/wazoku/wazoku-spotlight/.eslintrc.js:', 173 \ ' Configuration for rule "indent" is invalid:', 174 \ ' Value "off" is the wrong type.', 175 \ '', 176 \ 'Error: /home/w0rp/git/wazoku/wazoku-spotlight/.eslintrc.js:', 177 \ ' Configuration for rule "indent" is invalid:', 178 \ ' Value "off" is the wrong type.', 179 \ '', 180 \ ' at validateRuleOptions (/usr/local/lib/node_modules/eslint/lib/config/config-validator.js:115:15)', 181 \ ' at /usr/local/lib/node_modules/eslint/lib/config/config-validator.js:162:13', 182 \ ' at Array.forEach (native)', 183 \ ' at Object.validate (/usr/local/lib/node_modules/eslint/lib/config/config-validator.js:161:35)', 184 \ ' at Object.load (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:522:19)', 185 \ ' at loadConfig (/usr/local/lib/node_modules/eslint/lib/config.js:63:33)', 186 \ ' at getLocalConfig (/usr/local/lib/node_modules/eslint/lib/config.js:130:29)', 187 \ ' at Config.getConfig (/usr/local/lib/node_modules/eslint/lib/config.js:256:22)', 188 \ ' at processText (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:224:33)', 189 \ ' at CLIEngine.executeOnText (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:756:26)', 190 \] 191 192 AssertEqual 193 \ [{ 194 \ 'lnum': 1, 195 \ 'text': 'eslint configuration error (type :ALEDetail for more information)', 196 \ 'detail': join(g:config_error_lines, "\n"), 197 \ }], 198 \ ale#handlers#eslint#HandleJSON(bufnr(''), g:config_error_lines[:]) 199 200 Execute(Suppressing missing configs shouldn't suppress invalid config errors): 201 let b:ale_javascript_eslint_suppress_missing_config = 1 202 let g:config_error_lines = [ 203 \ '/home/w0rp/git/wazoku/wazoku-spotlight/.eslintrc.js:', 204 \ ' Configuration for rule "indent" is invalid:', 205 \ ' Value "off" is the wrong type.', 206 \ '', 207 \ 'Error: /home/w0rp/git/wazoku/wazoku-spotlight/.eslintrc.js:', 208 \ ' Configuration for rule "indent" is invalid:', 209 \ ' Value "off" is the wrong type.', 210 \ '', 211 \ ' at validateRuleOptions (/usr/local/lib/node_modules/eslint/lib/config/config-validator.js:115:15)', 212 \ ' at /usr/local/lib/node_modules/eslint/lib/config/config-validator.js:162:13', 213 \ ' at Array.forEach (native)', 214 \ ' at Object.validate (/usr/local/lib/node_modules/eslint/lib/config/config-validator.js:161:35)', 215 \ ' at Object.load (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:522:19)', 216 \ ' at loadConfig (/usr/local/lib/node_modules/eslint/lib/config.js:63:33)', 217 \ ' at getLocalConfig (/usr/local/lib/node_modules/eslint/lib/config.js:130:29)', 218 \ ' at Config.getConfig (/usr/local/lib/node_modules/eslint/lib/config.js:256:22)', 219 \ ' at processText (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:224:33)', 220 \ ' at CLIEngine.executeOnText (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:756:26)', 221 \] 222 223 AssertEqual 224 \ [{ 225 \ 'lnum': 1, 226 \ 'text': 'eslint configuration error (type :ALEDetail for more information)', 227 \ 'detail': join(g:config_error_lines, "\n"), 228 \ }], 229 \ ale#handlers#eslint#HandleJSON(bufnr(''), g:config_error_lines[:]) 230 231 Execute(The eslint handler should print a message when import is not used in a module): 232 let g:config_error_lines = [ 233 \ 'ImportDeclaration should appear when the mode is ES6 and in the module context.', 234 \ 'AssertionError: ImportDeclaration should appear when the mode is ES6 and in the module context.', 235 \ ' at Referencer.ImportDeclaration (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint-scope/lib/referencer.js:597:9)', 236 \ ' at Referencer.Visitor.visit (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/esrecurse/esrecurse.js:122:34)', 237 \ ' at Referencer.Visitor.visitChildren (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/esrecurse/esrecurse.js:101:38)', 238 \ ' at Referencer.Program (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint-scope/lib/referencer.js:449:14)', 239 \ ' at Referencer.Visitor.visit (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/esrecurse/esrecurse.js:122:34)', 240 \ ' at Object.analyze (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint-scope/lib/index.js:138:16)', 241 \ ' at EventEmitter.module.exports.api.verify (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/eslint.js:887:40)', 242 \ ' at processText (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/cli-engine.js:278:31)', 243 \ ' at CLIEngine.executeOnText (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/cli-engine.js:734:26)', 244 \ ' at Object.execute (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/cli.js:171:42) ', 245 \] 246 247 AssertEqual 248 \ [{ 249 \ 'lnum': 1, 250 \ 'text': 'eslint configuration error (type :ALEDetail for more information)', 251 \ 'detail': join(g:config_error_lines, "\n"), 252 \ }], 253 \ ale#handlers#eslint#HandleJSON(bufnr(''), g:config_error_lines[:]) 254 255 Execute(Suppressing missing configs shouldn't suppress module import errors): 256 let b:ale_javascript_eslint_suppress_missing_config = 1 257 let g:config_error_lines = [ 258 \ 'ImportDeclaration should appear when the mode is ES6 and in the module context.', 259 \ 'AssertionError: ImportDeclaration should appear when the mode is ES6 and in the module context.', 260 \ ' at Referencer.ImportDeclaration (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint-scope/lib/referencer.js:597:9)', 261 \ ' at Referencer.Visitor.visit (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/esrecurse/esrecurse.js:122:34)', 262 \ ' at Referencer.Visitor.visitChildren (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/esrecurse/esrecurse.js:101:38)', 263 \ ' at Referencer.Program (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint-scope/lib/referencer.js:449:14)', 264 \ ' at Referencer.Visitor.visit (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/esrecurse/esrecurse.js:122:34)', 265 \ ' at Object.analyze (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint-scope/lib/index.js:138:16)', 266 \ ' at EventEmitter.module.exports.api.verify (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/eslint.js:887:40)', 267 \ ' at processText (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/cli-engine.js:278:31)', 268 \ ' at CLIEngine.executeOnText (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/cli-engine.js:734:26)', 269 \ ' at Object.execute (/home/w0rp/git/wazoku/wazoku-spotlight/spotlight/static/node_modules/eslint/lib/cli.js:171:42) ', 270 \] 271 272 AssertEqual 273 \ [{ 274 \ 'lnum': 1, 275 \ 'text': 'eslint configuration error (type :ALEDetail for more information)', 276 \ 'detail': join(g:config_error_lines, "\n"), 277 \ }], 278 \ ale#handlers#eslint#HandleJSON(bufnr(''), g:config_error_lines[:]) 279 280 Execute(The eslint handler should hint about using typescript-eslint-parser): 281 call ale#test#SetFilename('foo.ts') 282 283 AssertEqual 284 \ [ 285 \ { 286 \ 'lnum': 2, 287 \ 'col': 1, 288 \ 'text': 'Parsing error (You may need configure typescript-eslint-parser): The keyword ''interface'' is reserved', 289 \ 'type': 'E', 290 \ }, 291 \ ], 292 \ ale#handlers#eslint#HandleJSON(bufnr(''), [ 293 \ '[{"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"}]', 294 \ ]) 295 296 Execute(eslint should warn about ignored files by default): 297 AssertEqual 298 \ [{ 299 \ 'lnum': 0, 300 \ 'type': 'W', 301 \ 'text': 'File ignored because of a matching ignore pattern. Use "--no-ignore" to override.' 302 \ }], 303 \ ale#handlers#eslint#HandleJSON(bufnr(''), [ 304 \ '[{"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}]', 305 \ ]) 306 307 AssertEqual 308 \ [{ 309 \ 'lnum': 0, 310 \ 'type': 'W', 311 \ 'text': 'File ignored by default. Use "--ignore-pattern ''!node_modules/*''" to override.', 312 \ }], 313 \ ale#handlers#eslint#HandleJSON(bufnr(''), [ 314 \ '[{"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}]', 315 \ ]) 316 317 Execute(eslint should not warn about ignored files when explicitly disabled): 318 let g:ale_javascript_eslint_suppress_eslintignore = 1 319 320 AssertEqual 321 \ [], 322 \ ale#handlers#eslint#HandleJSON(bufnr(''), [ 323 \ '[{"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}]', 324 \ ]) 325 326 AssertEqual 327 \ [], 328 \ ale#handlers#eslint#HandleJSON(bufnr(''), [ 329 \ '[{"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}]', 330 \ ]) 331 332 Execute(Failing to connect to eslint_d should be handled correctly): 333 AssertEqual 334 \ [ 335 \ { 336 \ 'lnum': 1, 337 \ 'text': 'Could not connect to eslint_d. Try updating eslint_d or killing it.', 338 \ }, 339 \ ], 340 \ ale#handlers#eslint#HandleJSON(bufnr(''), [ 341 \ 'Could not connect', 342 \ ]) 343 344 Execute(Disabling warnings about trailing spaces should work): 345 call ale#test#SetFilename('foo.js') 346 347 AssertEqual 348 \ [ 349 \ { 350 \ 'lnum': 2, 351 \ 'col': 16, 352 \ 'code': 'no-trailing-spaces', 353 \ 'type': 'W', 354 \ 'text': 'Trailing spaces not allowed.', 355 \ }, 356 \ ], 357 \ ale#handlers#eslint#HandleJSON(bufnr(''), [ 358 \ '[{"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"}]' 359 \ ]) 360 361 let g:ale_warn_about_trailing_whitespace = 0 362 363 AssertEqual 364 \ [], 365 \ ale#handlers#eslint#HandleJSON(bufnr(''), [ 366 \ '[{"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"}]' 367 \ ]) 368 369 let g:ale_warn_about_trailing_whitespace = 1 370 let b:ale_warn_about_trailing_whitespace = 0 371 372 AssertEqual 373 \ [], 374 \ ale#handlers#eslint#HandleJSON(bufnr(''), [ 375 \ '[{"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"}]' 376 \ ])