1
+ if exists (" g:vim_php_cs_fixer" ) || &cp
2
+ finish
3
+ endif
4
+ let g: vim_php_cs_fixer = 1
5
+
1
6
" Taken from NerdTree
2
7
function ! s: initVariable (var , value)
3
8
if ! exists (a: var )
@@ -18,14 +23,15 @@ call s:initVariable("g:php_cs_fixer_verbose", 0)
18
23
19
24
let g: php_cs_fixer_command = g: php_cs_fixer_php_path .' ' .g: php_cs_fixer_path .' fix --config=' .g: php_cs_fixer_config
20
25
21
- fun ! PhpCsFixerFix (path )
26
+ fun ! PhpCsFixerFix (path , dry_run )
22
27
let command = g: php_cs_fixer_command .' ' .a: path
23
28
24
- if (g: php_cs_fixer_dry_run == 1 )
29
+ if a: dry_run == 1
30
+ echohl Title | echo " [DRY RUN MODE]" | echohl None
25
31
let command = command .' --dry-run'
26
32
endif
27
33
28
- if ( strlen (g: php_cs_fixer_fixers_list) )
34
+ if strlen (g: php_cs_fixer_fixers_list )
29
35
let command = command .' --fixers=' .g: php_cs_fixer_fixers_list
30
36
endif
31
37
@@ -36,28 +42,31 @@ fun! PhpCsFixerFix(path)
36
42
let s: nbLines = len (split (s: output , ' \n' ))
37
43
let s: nbFilesModified = (s: nbLines - 1 )
38
44
39
- if (g: php_cs_fixer_verbose == 1 )
40
- " @todo, if dry-run, purpose to user to launch command without
41
- " dry-run
45
+ if g: php_cs_fixer_verbose == 1
42
46
echohl Title | echo s: output | echohl None
43
47
else
44
- if (s: nbFilesModified > 0 )
45
- " @todo, if dry-run, purpose to user to launch command without
46
- " dry-run
48
+ if s: nbFilesModified > 0
47
49
echohl Title | echo " There is " .s: nbFilesModified ." file(s) modified(s)" | echohl None
48
50
else
49
51
echohl Title | echo " There is no cs to fix" | echohl None
50
52
endif
51
53
endif
54
+
55
+ if a: dry_run == 1
56
+ let l: confirmed = confirm (" Do you want to launch command without dry-run option ?" , " &Yes\n &No" , 2 )
57
+ if l: confirmed == 1
58
+ call PhpCsFixerFix (a: path , 0 )
59
+ endif
60
+ endif
52
61
endif
53
62
endfun
54
63
55
64
fun ! PhpCsFixerFixDirectory ()
56
- call PhpCsFixerFix (expand (' %:p:h' ))
65
+ call PhpCsFixerFix (expand (' %:p:h' ), g: php_cs_fixer_dry_run )
57
66
endfun
58
67
59
68
fun ! PhpCsFixerFixFile ()
60
- call PhpCsFixerFix (expand (' %:p' ))
69
+ call PhpCsFixerFix (expand (' %:p' ), g: php_cs_fixer_dry_run )
61
70
endfun
62
71
63
72
if (g: php_cs_fixer_default_mapping == 1 )
0 commit comments