Merge pull request #862 from notomo/add-phpcbf-fixer

add phpcbf fixer
This commit is contained in:
w0rp 2017-08-20 13:42:03 +01:00 committed by GitHub
commit 47e681529b
9 changed files with 118 additions and 2 deletions

View file

@ -105,7 +105,7 @@ name. That seems to be the fairest way to arrange this table.
| Objective-C++ | [clang](http://clang.llvm.org/) | | Objective-C++ | [clang](http://clang.llvm.org/) |
| OCaml | [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-integration-ocaml-merlin` for configuration instructions | OCaml | [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-integration-ocaml-merlin` for configuration instructions
| Perl | [perl -c](https://perl.org/), [perl-critic](https://metacpan.org/pod/Perl::Critic) | | Perl | [perl -c](https://perl.org/), [perl-critic](https://metacpan.org/pod/Perl::Critic) |
| PHP | [hack](http://hacklang.org/), [langserver](https://github.com/felixfbecker/php-language-server), [php -l](https://secure.php.net/), [phpcs](https://github.com/squizlabs/PHP_CodeSniffer), [phpmd](https://phpmd.org), [phpstan](https://github.com/phpstan/phpstan) | | PHP | [hack](http://hacklang.org/), [langserver](https://github.com/felixfbecker/php-language-server), [php -l](https://secure.php.net/), [phpcs](https://github.com/squizlabs/PHP_CodeSniffer), [phpmd](https://phpmd.org), [phpstan](https://github.com/phpstan/phpstan), [phpcbf](https://github.com/squizlabs/PHP_CodeSniffer) |
| Pod | [proselint](http://proselint.com/)| | Pod | [proselint](http://proselint.com/)|
| Pug | [pug-lint](https://github.com/pugjs/pug-lint) | | Pug | [pug-lint](https://github.com/pugjs/pug-lint) |
| Puppet | [puppet](https://puppet.com), [puppet-lint](https://puppet-lint.com) | | Puppet | [puppet](https://puppet.com), [puppet-lint](https://puppet-lint.com) |

View file

@ -77,6 +77,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['swift'], \ 'suggested_filetypes': ['swift'],
\ 'description': 'Apply SwiftFormat to a file.', \ 'description': 'Apply SwiftFormat to a file.',
\ }, \ },
\ 'phpcbf': {
\ 'function': 'ale#fixers#phpcbf#Fix',
\ 'suggested_filetypes': ['php'],
\ 'description': 'Fix PHP files with phpcbf.',
\ },
\} \}
" Reset the function registry to the default entries. " Reset the function registry to the default entries.

View file

@ -0,0 +1,24 @@
" Author: notomo <notomo.motono@gmail.com>
" Description: Fixing files with phpcbf.
call ale#Set('php_phpcbf_standard', '')
call ale#Set('php_phpcbf_executable', 'phpcbf')
call ale#Set('php_phpcbf_use_global', 0)
function! ale#fixers#phpcbf#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'php_phpcbf', [
\ 'vendor/bin/phpcbf',
\ 'phpcbf'
\])
endfunction
function! ale#fixers#phpcbf#Fix(buffer) abort
let l:executable = ale#fixers#phpcbf#GetExecutable(a:buffer)
let l:standard = ale#Var(a:buffer, 'php_phpcbf_standard')
let l:standard_option = !empty(l:standard)
\ ? '--standard=' . l:standard
\ : ''
return {
\ 'command': ale#Escape(l:executable) . ' --stdin-path=%s ' . l:standard_option
\}
endfunction

View file

@ -94,5 +94,35 @@ g:ale_php_phpstan_level *g:ale_php_phpstan_level*
This variable controls the rule levels. 0 is the loosest and 4 is the This variable controls the rule levels. 0 is the loosest and 4 is the
strictest. strictest.
-------------------------------------------------------------------------------
phpcbf *ale-php-phpcbf*
g:ale_php_phpcbf_executable *g:ale_php_phpcbf_executable*
*b:ale_php_phpcbf_executable*
Type: |String|
Default: `'phpcbf'`
See |ale-integrations-local-executables|
g:ale_php_phpcbf_standard *g:ale_php_phpcbf_standard*
*b:ale_php_phpcbf_standard*
Type: |String|
Default: `''`
This variable can be set to specify the coding standard used by phpcbf. If no
coding standard is specified, phpcbf will default to fixing against the
PEAR coding standard, or the standard you have set as the default.
g:ale_php_phpcbf_use_global *g:ale_php_phpcbf_use_global*
*b:ale_php_phpcbf_use_global*
Type: |Number|
Default: `0`
See |ale-integrations-local-executables|
=============================================================================== ===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View file

@ -85,6 +85,7 @@ CONTENTS *ale-contents*
phpcs...............................|ale-php-phpcs| phpcs...............................|ale-php-phpcs|
phpmd...............................|ale-php-phpmd| phpmd...............................|ale-php-phpmd|
phpstan.............................|ale-php-phpstan| phpstan.............................|ale-php-phpstan|
phpcbf..............................|ale-php-phpcbf|
pug...................................|ale-pug-options| pug...................................|ale-pug-options|
puglint.............................|ale-pug-puglint| puglint.............................|ale-pug-puglint|
python................................|ale-python-options| python................................|ale-python-options|
@ -212,7 +213,7 @@ The following languages and tools are supported.
* Objective-C++: 'clang' * Objective-C++: 'clang'
* OCaml: 'merlin' (see |ale-ocaml-merlin|) * OCaml: 'merlin' (see |ale-ocaml-merlin|)
* Perl: 'perl' (-c flag), 'perlcritic' * Perl: 'perl' (-c flag), 'perlcritic'
* PHP: 'hack', 'langserver', 'php' (-l flag), 'phpcs', 'phpmd', 'phpstan' * PHP: 'hack', 'langserver', 'php' (-l flag), 'phpcs', 'phpmd', 'phpstan', 'phpcbf'
* Pod: 'proselint' * Pod: 'proselint'
* Pug: 'pug-lint' * Pug: 'pug-lint'
* Puppet: 'puppet', 'puppet-lint' * Puppet: 'puppet', 'puppet-lint'

View file

@ -0,0 +1,56 @@
Before:
Save g:ale_php_phpcbf_executable
Save g:ale_php_phpcbf_standard
Save g:ale_php_phpcbf_use_global
let g:ale_php_phpcbf_executable = 'phpcbf_test'
let g:ale_php_phpcbf_standard = ''
let g:ale_php_phpcbf_use_global = 0
call ale#test#SetDirectory('/testplugin/test/fixers')
silent cd ..
silent cd command_callback
let g:dir = getcwd()
After:
Restore
call ale#test#RestoreDirectory()
Execute(project with phpcbf should use local by default):
call ale#test#SetFilename('php_paths/project-with-phpcbf/foo/test.php')
AssertEqual
\ g:dir . '/php_paths/project-with-phpcbf/vendor/bin/phpcbf',
\ ale#fixers#phpcbf#GetExecutable(bufnr(''))
Execute(use-global should override local detection):
let g:ale_php_phpcbf_use_global = 1
call ale#test#SetFilename('php_paths/project-with-phpcbf/foo/test.php')
AssertEqual
\ 'phpcbf_test',
\ ale#fixers#phpcbf#GetExecutable(bufnr(''))
Execute(project without phpcbf should use global):
call ale#test#SetFilename('php_paths/project-without-phpcbf/foo/test.php')
AssertEqual
\ 'phpcbf_test',
\ ale#fixers#phpcbf#GetExecutable(bufnr(''))
Execute(The phpcbf callback should return the correct default values):
call ale#test#SetFilename('php_paths/project-with-phpcbf/foo/test.php')
AssertEqual
\ {'command': ale#Escape(g:dir . '/php_paths/project-with-phpcbf/vendor/bin/phpcbf') . ' --stdin-path=%s ' },
\ ale#fixers#phpcbf#Fix(bufnr(''))
Execute(The phpcbf callback should include the phpcbf_standard option):
let g:ale_php_phpcbf_standard = 'phpcbf_ruleset.xml'
call ale#test#SetFilename('php_paths/project-with-phpcbf/foo/test.php')
AssertEqual
\ {'command': ale#Escape(g:dir . '/php_paths/project-with-phpcbf/vendor/bin/phpcbf') . ' --stdin-path=%s ' . '--standard=phpcbf_ruleset.xml'},
\ ale#fixers#phpcbf#Fix(bufnr(''))