From 97189eb81502741b65abbe2a77ca2c98a11f2a4a Mon Sep 17 00:00:00 2001 From: Daniel Dvorkin Date: Sun, 3 Jul 2016 21:56:35 +0000 Subject: [PATCH 1/3] Support PHPCBF --- autoload/Phpqa.vim | 24 +++++++++++++++++++++++- plugin/Phpqa.vim | 18 +++++++++++++++--- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/autoload/Phpqa.vim b/autoload/Phpqa.vim index f74337f..58b1aa8 100644 --- a/autoload/Phpqa.vim +++ b/autoload/Phpqa.vim @@ -135,6 +135,24 @@ function! Phpqa#PhpCodeSniffer() return l:phpcs_list endf +" Run PHP code fixer. +function! Phpqa#PhpCodeFixer() + if @% == "" + echohl Error | echo "Invalid buffer (are you in the error window?)" |echohl None + return [] + endif + " Run codefixer if the command hasn't been unset + if 0 != len(g:phpqa_codefixer_cmd) + write + call system(g:phpqa_codefixer_cmd." ".g:phpqa_codesniffer_args." ".@%) + edit + else + if 1 == g:phpqa_verbose + echohl Error | echo "PHPCBF binary set to empty, not running code beautifier and fixer" | echohl None + endif + endif +endf + " Run mess detector. " " The user is required to specify a ruleset XML file if they haven't already. @@ -160,7 +178,7 @@ function! Phpqa#PhpMessDetector() endf " Run Code Sniffer and Mess Detector. -function! Phpqa#PhpQaTools(runcs,runmd) +function! Phpqa#PhpQaTools(runcs,runmd,runcbf) let l:bufNo = bufnr('%') call s:RemoveSigns() @@ -176,6 +194,10 @@ function! Phpqa#PhpQaTools(runcs,runmd) let l:phpmd_list = [] endif + if 1 == a:runcbf + call Phpqa#PhpCodeFixer() + endif + let error_list=s:CombineLists(l:phpcs_list,l:phpmd_list) if 0 != len(error_list) set errorformat=%t\ %f:%l:%c:\ %m,%t\ %f:%l\ %m diff --git a/plugin/Phpqa.vim b/plugin/Phpqa.vim index f7f19e3..61906f4 100644 --- a/plugin/Phpqa.vim +++ b/plugin/Phpqa.vim @@ -46,6 +46,12 @@ if !exists("g:phpqa_codesniffer_cmd") let g:phpqa_codesniffer_cmd='phpcs' endif +" PHPCBF binary (PHP_CodeSniffer) +if !exists("g:phpqa_codefixer_cmd") + let g:phpqa_codefixer_cmd='phpcbf' +endif + + " Arguments to pass to code sniffer, e.g standard name if !exists("g:phpqa_codesniffer_args") let g:phpqa_codesniffer_args="" @@ -88,6 +94,11 @@ if !exists("g:phpqa_codesniffer_autorun") let g:phpqa_codesniffer_autorun = 1 endif +" Whether to automatically run codefixer when saving a file +if !exists("g:phpqa_codefixer_autorun") + let g:phpqa_codefixer_autorun = 0 +endif + " Whether to automatically run messdetector when saving a file if !exists("g:phpqa_messdetector_autorun") let g:phpqa_messdetector_autorun = 1 @@ -111,7 +122,7 @@ function! PhpqaRunAll() " Check syntax valid before running others let retval=Phpqa#PhpLint() if 0 == retval && 1 == g:phpqa_run_on_write - call Phpqa#PhpQaTools(g:phpqa_codesniffer_autorun,g:phpqa_messdetector_autorun) + call Phpqa#PhpQaTools(g:phpqa_codesniffer_autorun,g:phpqa_messdetector_autorun,g:phpqa_codefixer_autorun) endif endif endf @@ -140,8 +151,9 @@ endif " Allow each command to be called individually command Php call Phpqa#PhpLint() -command Phpcs call Phpqa#PhpQaTools(1,0) -command Phpmd call Phpqa#PhpQaTools(0,1) +command Phpcs call Phpqa#PhpQaTools(1,0,0) +command Phpcbf call Phpqa#PhpQaTools(0,0,1) +command Phpmd call Phpqa#PhpQaTools(0,1,0) command Phpcc call Phpqa#PhpCodeCoverage() From a5d50fa2fba9c28cce4328a61b174cacf76cf434 Mon Sep 17 00:00:00 2001 From: Daniel Dvorkin Date: Sun, 3 Jul 2016 22:07:11 +0000 Subject: [PATCH 2/3] Add key mapping for PHPCBF --- plugin/Phpqa.vim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugin/Phpqa.vim b/plugin/Phpqa.vim index 61906f4..832d8f1 100644 --- a/plugin/Phpqa.vim +++ b/plugin/Phpqa.vim @@ -163,6 +163,12 @@ endif nnoremap