summaryrefslogtreecommitdiff
path: root/test/handler/test_eslint_handler.vader
blob: 0a230c705930be33115e666246a09bd9b35ec748 (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
After:
  unlet! g:config_error_lines

Execute(The eslint handler should parse lines correctly):
  AssertEqual
  \ [
  \   {
  \     'lnum': 47,
  \     'col': 14,
  \     'text': 'Missing trailing comma. [Warning/comma-dangle]',
  \     'type': 'W',
  \   },
  \   {
  \     'lnum': 56,
  \     'col': 41,
  \     'text': 'Missing semicolon. [Error/semi]',
  \     'type': 'E',
  \   },
  \   {
  \     'lnum': 13,
  \     'col': 3,
  \     'text': 'Parsing error: Unexpected token',
  \     'type': 'E',
  \   },
  \ ],
  \ ale#handlers#eslint#Handle(347, [
  \   'This line should be ignored completely',
  \   '/path/to/some-filename.js:47:14: Missing trailing comma. [Warning/comma-dangle]',
  \   '/path/to/some-filename.js:56:41: Missing semicolon. [Error/semi]',
  \   'This line should be ignored completely',
  \   '/path/to/some-filename.js:13:3: Parsing error: Unexpected token',
  \ ])

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#Handle(347, 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#Handle(347, 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#Handle(347, g:config_error_lines[:])

Execute(The eslint handler should output end_col values where appropriate):
  AssertEqual
  \ [
  \   {
  \     'lnum': 4,
  \     'col': 3,
  \     'end_col': 15,
  \     'text': 'Parsing error: Unexpected token ''some string'' [Error]',
  \     'type': 'E',
  \   },
  \   {
  \     'lnum': 70,
  \     'col': 3,
  \     'end_col': 5,
  \     'text': '''foo'' is not defined. [Error/no-undef]',
  \     'type': 'E',
  \   },
  \   {
  \     'lnum': 71,
  \     'col': 2,
  \     'end_col': 6,
  \     'text': 'Unexpected `await` inside a loop. [Error/no-await-in-loop]',
  \     'type': 'E',
  \   },
  \   {
  \     'lnum': 72,
  \     'col': 6,
  \     'end_col': 10,
  \     'text': 'Redundant use of `await` on a return value. [Error/no-return-await]',
  \     'type': 'E',
  \   },
  \   {
  \     'lnum': 73,
  \     'col': 4,
  \     'end_col': 10,
  \     'text': 'Unexpected console statement [Error/no-console]',
  \     'type': 'E',
  \   },
  \   {
  \     'lnum': 74,
  \     'col': 4,
  \     'end_col': 11,
  \     'text': 'Unexpected ''debugger'' statement. [Error/no-debugger]',
  \     'type': 'E',
  \   },
  \ ],
  \ ale#handlers#eslint#Handle(347, [
  \   'app.js:4:3: Parsing error: Unexpected token ''some string'' [Error]',
  \   'app.js:70:3: ''foo'' is not defined. [Error/no-undef]',
  \   'app.js:71:2: Unexpected `await` inside a loop. [Error/no-await-in-loop]',
  \   'app.js:72:6: Redundant use of `await` on a return value. [Error/no-return-await]',
  \   'app.js:73:4: Unexpected console statement [Error/no-console]',
  \   'app.js:74:4: Unexpected ''debugger'' statement. [Error/no-debugger]',
  \ ])

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

  AssertEqual
  \ [
  \   {
  \     'lnum': 451,
  \     'col': 2,
  \     'end_col': 2,
  \     'text': 'Parsing error (You may need configure typescript-eslint-parser): Unexpected token ) [Error]',
  \     'type': 'E',
  \   },
  \ ],
  \ ale#handlers#eslint#Handle(bufnr(''), [
  \ 'foo.ts:451:2: Parsing error: Unexpected token ) [Error]',
  \ ])