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
|
Before:
call ale#assert#SetUpFixerTest('javascript', 'prettier')
Save g:ale_command_wrapper
let g:ale_command_wrapper = ''
After:
call ale#assert#TearDownFixerTest()
Execute(The prettier callback should return the correct default values):
call ale#test#SetFilename('../test-files/prettier/testfile.js')
AssertFixer
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' %t'
\ . ' --write',
\ }
Execute(The --config option should not be set automatically):
let g:ale_javascript_prettier_use_local_config = 1
call ale#test#SetFilename('../test-files/prettier/with_config/testfile.js')
AssertFixer
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' %t'
\ . ' --write',
\ }
Execute(The prettier callback should include custom prettier options):
let g:ale_javascript_prettier_options = '--no-semi'
call ale#test#SetFilename('../test-files/prettier/with_config/testfile.js')
AssertFixer
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' %t'
\ . ' --no-semi'
\ . ' --write',
\ }
Execute(The version check should be correct):
call ale#test#SetFilename('../test-files/prettier/testfile.js')
AssertFixer [
\ ale#Escape('prettier') . ' --version',
\ {'read_temporary_file': 1, 'command': ale#Escape('prettier') . ' %t --write'}
\]
Execute(--stdin-filepath should be used when prettier is new enough):
let g:ale_javascript_prettier_options = '--no-semi'
call ale#test#SetFilename('../test-files/prettier/with_config/testfile.js')
GivenCommandOutput ['1.6.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --no-semi'
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(The version number should be cached):
call ale#test#SetFilename('../test-files/prettier/with_config/testfile.js')
GivenCommandOutput ['1.6.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --stdin-filepath %s --stdin',
\ }
GivenCommandOutput []
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(Should set --parser to `babylon` by default, < 1.16.0):
call ale#test#SetFilename('../test-files/prettier/testfile')
set filetype=javascript
GivenCommandOutput ['1.6.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --parser babylon'
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(Should set --parser to `babel` by default, >= 1.16.0):
call ale#test#SetFilename('../test-files/prettier/testfile')
set filetype=javascript
GivenCommandOutput ['1.16.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --parser babel'
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(Should set --parser based on filetype, TypeScript):
call ale#test#SetFilename('../test-files/prettier/testfile')
set filetype=typescript
GivenCommandOutput ['1.6.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --parser typescript'
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(Should set --parser based on filetype, CSS):
call ale#test#SetFilename('../test-files/prettier/testfile')
set filetype=css
GivenCommandOutput ['1.6.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --parser css'
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(Should set --parser based on filetype, LESS):
call ale#test#SetFilename('../test-files/prettier/testfile')
set filetype=less
GivenCommandOutput ['1.6.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --parser less'
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(Should set --parser based on filetype, SCSS):
call ale#test#SetFilename('../test-files/prettier/testfile')
set filetype=scss
GivenCommandOutput ['1.6.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --parser scss'
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(Should set --parser based on filetype, JSON):
call ale#test#SetFilename('../test-files/prettier/testfile')
set filetype=json
GivenCommandOutput ['1.6.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --parser json'
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(Should set --parser based on filetype, JSON5):
call ale#test#SetFilename('../test-files/prettier/testfile')
set filetype=json5
GivenCommandOutput ['1.6.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --parser json5'
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(Should set --parser based on filetype, GraphQL):
call ale#test#SetFilename('../test-files/prettier/testfile')
set filetype=graphql
GivenCommandOutput ['1.6.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --parser graphql'
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(Should set --parser based on filetype, Markdown):
call ale#test#SetFilename('../test-files/prettier/testfile')
set filetype=markdown
GivenCommandOutput ['1.6.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --parser markdown'
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(Should set --parser based on filetype, Vue):
call ale#test#SetFilename('../test-files/prettier/testfile')
set filetype=vue
GivenCommandOutput ['1.6.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --parser vue'
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(Should set --parser based on filetype, YAML):
call ale#test#SetFilename('../test-files/prettier/testfile')
set filetype=yaml
GivenCommandOutput ['1.6.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --parser yaml'
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(Should set --parser based on filetype, HTML):
call ale#test#SetFilename('../test-files/prettier/testfile')
set filetype=html
GivenCommandOutput ['1.6.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --parser html'
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(Should set --parser based on filetype, Ruby):
call ale#test#SetFilename('../test-files/prettier/testfile')
set filetype=ruby
GivenCommandOutput ['1.6.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --parser ruby'
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(Should set --parser based on first filetype of multiple filetypes):
call ale#test#SetFilename('../test-files/prettier/testfile')
set filetype=css.scss
GivenCommandOutput ['1.6.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --parser css'
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(Should set --parser based on first filetype of multiple filetypes):
call ale#test#SetFilename('../test-files/prettier/testfile')
set filetype=astro
GivenCommandOutput ['1.6.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --parser astro'
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(Should set --parser for experimental language, Handlebars):
call ale#test#SetFilename('../test-files/prettier/testfile.hbs')
set filetype=html.handlebars
GivenCommandOutput ['1.6.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --parser glimmer'
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(Changes to directory where .prettierignore is found):
call ale#test#SetFilename('../test-files/prettier/with_prettierignore/src/testfile.js')
GivenCommandOutput ['1.6.0']
AssertFixer
\ {
\ 'cwd': expand('%:p:h:h'),
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --stdin-filepath %s --stdin',
\ }
Execute(The prettier_d post-processor should permit regular JavaScript content):
AssertEqual
\ [
\ 'const x = ''Error: foo''',
\ 'const y = 3',
\ ],
\ ale#fixers#prettier#ProcessPrettierDOutput(bufnr(''), [
\ 'const x = ''Error: foo''',
\ 'const y = 3',
\ ])
Execute(The prettier_d post-processor should handle error messages correctly):
AssertEqual
\ [],
\ ale#fixers#prettier#ProcessPrettierDOutput(bufnr(''), [
\ 'SyntaxError: Unexpected token, expected "," (36:28)',
\ ])
|