Skip to content

Commit ca3da75

Browse files
committed
if you use dry-run command, it'll show you results and then ask you if you want to re use command without dry-run option
1 parent ab87fe7 commit ca3da75

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,3 @@ To see how to install `php-cs-fixer`, look at [php-cs-fixer](https://github.com/
3939

4040
If you see any improvement or question, contribute or create an issue
4141

42-
# Todo
43-
44-
- If `dry-run` option, ask to user if he wants to launch command without dry-run after he launchs command.

plugin/php-cs-fixer.vim

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
if exists("g:vim_php_cs_fixer") || &cp
2+
finish
3+
endif
4+
let g:vim_php_cs_fixer = 1
5+
16
" Taken from NerdTree
27
function! s:initVariable(var, value)
38
if !exists(a:var)
@@ -18,14 +23,15 @@ call s:initVariable("g:php_cs_fixer_verbose", 0)
1823

1924
let g:php_cs_fixer_command = g:php_cs_fixer_php_path.' '.g:php_cs_fixer_path.' fix --config='.g:php_cs_fixer_config
2025

21-
fun! PhpCsFixerFix(path)
26+
fun! PhpCsFixerFix(path, dry_run)
2227
let command = g:php_cs_fixer_command.' '.a:path
2328

24-
if(g:php_cs_fixer_dry_run == 1)
29+
if a:dry_run == 1
30+
echohl Title | echo "[DRY RUN MODE]" | echohl None
2531
let command = command.' --dry-run'
2632
endif
2733

28-
if(strlen(g:php_cs_fixer_fixers_list))
34+
if strlen(g:php_cs_fixer_fixers_list)
2935
let command = command.' --fixers='.g:php_cs_fixer_fixers_list
3036
endif
3137

@@ -36,28 +42,31 @@ fun! PhpCsFixerFix(path)
3642
let s:nbLines = len(split(s:output, '\n'))
3743
let s:nbFilesModified = (s:nbLines - 1)
3844

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
4246
echohl Title | echo s:output | echohl None
4347
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
4749
echohl Title | echo "There is ".s:nbFilesModified." file(s) modified(s)" | echohl None
4850
else
4951
echohl Title | echo "There is no cs to fix" | echohl None
5052
endif
5153
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
5261
endif
5362
endfun
5463

5564
fun! PhpCsFixerFixDirectory()
56-
call PhpCsFixerFix(expand('%:p:h'))
65+
call PhpCsFixerFix(expand('%:p:h'), g:php_cs_fixer_dry_run)
5766
endfun
5867

5968
fun! PhpCsFixerFixFile()
60-
call PhpCsFixerFix(expand('%:p'))
69+
call PhpCsFixerFix(expand('%:p'), g:php_cs_fixer_dry_run)
6170
endfun
6271

6372
if(g:php_cs_fixer_default_mapping == 1)

0 commit comments

Comments
 (0)