add phpcbf fixer
This commit is contained in:
parent
e5d0a17694
commit
5a9a365aed
@ -104,7 +104,7 @@ name. That seems to be the fairest way to arrange this table.
|
||||
| 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
|
||||
| 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/)|
|
||||
| Pug | [pug-lint](https://github.com/pugjs/pug-lint) |
|
||||
| Puppet | [puppet](https://puppet.com), [puppet-lint](https://puppet-lint.com) |
|
||||
|
@ -77,6 +77,11 @@ let s:default_registry = {
|
||||
\ 'suggested_filetypes': ['swift'],
|
||||
\ '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.
|
||||
|
24
autoload/ale/fixers/phpcbf.vim
Normal file
24
autoload/ale/fixers/phpcbf.vim
Normal 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
|
@ -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
|
||||
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:
|
||||
|
@ -83,6 +83,7 @@ CONTENTS *ale-contents*
|
||||
phpcs...............................|ale-php-phpcs|
|
||||
phpmd...............................|ale-php-phpmd|
|
||||
phpstan.............................|ale-php-phpstan|
|
||||
phpcbf..............................|ale-php-phpcbf|
|
||||
pug...................................|ale-pug-options|
|
||||
puglint.............................|ale-pug-puglint|
|
||||
python................................|ale-python-options|
|
||||
@ -210,7 +211,7 @@ The following languages and tools are supported.
|
||||
* Objective-C++: 'clang'
|
||||
* OCaml: 'merlin' (see |ale-ocaml-merlin|)
|
||||
* 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'
|
||||
* Pug: 'pug-lint'
|
||||
* Puppet: 'puppet', 'puppet-lint'
|
||||
|
0
test/command_callback/php_paths/project-with-phpcbf/vendor/bin/phpcbf
vendored
Normal file
0
test/command_callback/php_paths/project-with-phpcbf/vendor/bin/phpcbf
vendored
Normal file
56
test/fixers/test_phpcbf_fixer_callback.vader
Normal file
56
test/fixers/test_phpcbf_fixer_callback.vader
Normal 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(''))
|
||||
|
Loading…
Reference in New Issue
Block a user