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
|
Before:
call ale#test#SetDirectory('/testplugin/test/fixers')
Save g:ale_javascript_prettier_executable
Save g:ale_javascript_prettier_options
" Use an invalid global executable, so we don't match it.
let g:ale_javascript_prettier_executable = 'xxxinvalid'
let g:ale_javascript_prettier_options = ''
call ale#test#SetDirectory('/testplugin/test/fixers')
silent cd ..
silent cd command_callback
let g:dir = getcwd()
After:
let g:ale_has_override = {}
call ale#test#RestoreDirectory()
call ale#semver#ResetVersionCache()
Execute(The prettier callback should return the correct default values):
call ale#test#SetFilename('../prettier-test-files/testfile.js')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' %t'
\ . ' --write',
\ },
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), [])
Execute(The --config option should not be set automatically):
let g:ale_javascript_prettier_use_local_config = 1
call ale#test#SetFilename('../prettier-test-files/with_config/testfile.js')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' %t'
\ . ' --write',
\ },
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), [])
Execute(The prettier callback should include custom prettier options):
let g:ale_javascript_prettier_options = '--no-semi'
call ale#test#SetFilename('../prettier-test-files/with_config/testfile.js')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' %t'
\ . ' --no-semi'
\ . ' --write',
\ },
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), [])
Execute(The version check should be correct):
call ale#test#SetFilename('../prettier-test-files/testfile.js')
AssertEqual
\ {
\ 'chain_with': 'ale#fixers#prettier#ApplyFixForVersion',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --version',
\ },
\ ale#fixers#prettier#Fix(bufnr(''))
Execute(--stdin-filepath should be used when prettier is new enough):
let g:ale_javascript_prettier_options = '--no-semi'
call ale#test#SetFilename('../prettier-test-files/with_config/testfile.js')
AssertEqual
\ {
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
\ . ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --no-semi'
\ . ' --stdin-filepath %s --stdin',
\ },
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0'])
Execute(The version number should be cached):
call ale#test#SetFilename('../prettier-test-files/with_config/testfile.js')
" Call the second callback with the version output.
call ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0'])
" Call it again without the version output. We should use the newer command.
AssertEqual
\ {
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
\ . ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --stdin-filepath %s --stdin',
\ },
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), [])
|