summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/pint.vim25
-rw-r--r--doc/ale-php.txt27
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md3
-rw-r--r--test/fixers/test_pint_fixer.vader62
-rw-r--r--test/test-files/php/project-with-pint/test.php0
-rw-r--r--test/test-files/php/project-with-pint/vendor/bin/pint0
-rw-r--r--test/test-files/php/project-without-pint/test.php0
10 files changed, 123 insertions, 1 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 57fff655..e9b289c6 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -231,6 +231,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['php'],
\ 'description': 'Fix PHP files with php-cs-fixer.',
\ },
+\ 'pint': {
+\ 'function': 'ale#fixers#pint#Fix',
+\ 'suggested_filetypes': ['php'],
+\ 'description': 'Fix PHP files with Laravel Pint.',
+\ },
\ 'astyle': {
\ 'function': 'ale#fixers#astyle#Fix',
\ 'suggested_filetypes': ['c', 'cpp'],
diff --git a/autoload/ale/fixers/pint.vim b/autoload/ale/fixers/pint.vim
new file mode 100644
index 00000000..274ddd9e
--- /dev/null
+++ b/autoload/ale/fixers/pint.vim
@@ -0,0 +1,25 @@
+" Author: Michael Dyrynda <michael@dyrynda.com.au>
+" Description: Fixing files with Laravel Pint.
+
+call ale#Set('php_pint_executable', 'pint')
+call ale#Set('php_pint_use_global', get(g:, 'ale_use_global_executables', 0))
+call ale#Set('php_pint_options', '')
+
+function! ale#fixers#pint#GetExecutable(buffer) abort
+ return ale#path#FindExecutable(a:buffer, 'php_pint', [
+ \ 'vendor/bin/pint',
+ \ 'pint'
+ \])
+endfunction
+
+function! ale#fixers#pint#Fix(buffer) abort
+ let l:executable = ale#fixers#pint#GetExecutable(a:buffer)
+
+ return {
+ \ 'command': ale#Escape(l:executable)
+ \ . ' ' . ale#Var(a:buffer, 'php_pint_options')
+ \ . ' %t',
+ \ 'read_temporary_file': 1,
+ \}
+endfunction
+
diff --git a/doc/ale-php.txt b/doc/ale-php.txt
index e4da97d3..2750a319 100644
--- a/doc/ale-php.txt
+++ b/doc/ale-php.txt
@@ -273,6 +273,33 @@ g:ale_php_php_executable *g:ale_php_php_executable*
===============================================================================
+pint *ale-php-pint*
+
+g:ale_php_pint_executable *g:ale_php_pint_executable*
+ *b:ale_php_pint_executable*
+ Type: |String|
+ Default: `'pint'`
+
+ This variable sets the executable used for pint.
+
+
+g:ale_php_pint_options *g:ale_php_pint_options*
+ *b:ale_php_pint_options*
+ Type: |String|
+ Default: `''`
+
+ This variable can be set to pass additional options to pint.
+
+
+g:ale_php_pint_use_global *g:ale_php_pint_use_global*
+ *b:ale_php_pint_use_global*
+ Type: |Boolean|
+ Default: `get(g:, 'ale_use_global_executables', 0)`
+
+ See |ale-integrations-local-executables|
+
+
+===============================================================================
tlint *ale-php-tlint*
g:ale_php_tlint_executable *g:ale_php_tlint_executable*
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 10ee6ae5..8db54406 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -417,6 +417,7 @@ Notes:
* `phpcs`
* `phpmd`
* `phpstan`
+ * `pint`
* `psalm`!!
* `tlint`
* PO
diff --git a/doc/ale.txt b/doc/ale.txt
index 0d5d7564..448c937c 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -3071,6 +3071,7 @@ documented in additional help files.
psalm.................................|ale-php-psalm|
php-cs-fixer..........................|ale-php-php-cs-fixer|
php...................................|ale-php-php|
+ pint..................................|ale-php-pint|
tlint.................................|ale-php-tlint|
intelephense..........................|ale-php-intelephense|
po......................................|ale-po-options|
diff --git a/supported-tools.md b/supported-tools.md
index 4033205e..785c21d5 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -420,12 +420,13 @@ formatting.
* [langserver](https://github.com/felixfbecker/php-language-server)
* [phan](https://github.com/phan/phan) see `:help ale-php-phan` to instructions
* [php -l](https://secure.php.net/)
- * [php-cs-fixer](http://cs.sensiolabs.org/)
+ * [php-cs-fixer](https://cs.symfony.com)
* [phpactor](https://github.com/phpactor/phpactor)
* [phpcbf](https://github.com/squizlabs/PHP_CodeSniffer)
* [phpcs](https://github.com/squizlabs/PHP_CodeSniffer)
* [phpmd](https://phpmd.org)
* [phpstan](https://github.com/phpstan/phpstan)
+ * [pint](https://github.com/laravel/pint) :beer:
* [psalm](https://getpsalm.org) :floppy_disk:
* [tlint](https://github.com/tightenco/tlint)
* PO
diff --git a/test/fixers/test_pint_fixer.vader b/test/fixers/test_pint_fixer.vader
new file mode 100644
index 00000000..5ea28b33
--- /dev/null
+++ b/test/fixers/test_pint_fixer.vader
@@ -0,0 +1,62 @@
+Before:
+ Save g:ale_php_pint_executable
+ Save g:ale_php_pint_options
+ let g:ale_php_pint_executable = 'pint'
+ let g:ale_php_pint_options = ''
+
+ call ale#test#SetDirectory('/testplugin/test/fixers')
+
+After:
+ Restore
+
+ call ale#test#RestoreDirectory()
+
+
+Execute(project with pint should use local by default):
+ call ale#test#SetFilename('../test-files/php/project-with-pint/test.php')
+
+ AssertEqual
+ \ ale#path#Simplify(g:dir . '/../test-files/php/project-with-pint/vendor/bin/pint'),
+ \ ale#fixers#pint#GetExecutable(bufnr(''))
+
+Execute(use-global should override local detection):
+ let g:ale_php_pint_use_global = 1
+ call ale#test#SetFilename('../test-files/php/project-with-pint/test.php')
+
+ AssertEqual
+ \ 'pint',
+ \ ale#fixers#pint#GetExecutable(bufnr(''))
+
+Execute(project without pint should use global):
+ call ale#test#SetFilename('../test-files/php/project-without-pint/test.php')
+
+ AssertEqual
+ \ 'pint',
+ \ ale#fixers#pint#GetExecutable(bufnr(''))
+
+
+
+
+Execute(The pint callback should return the correct default values):
+ call ale#test#SetFilename('../test-files/php/project-without-pint/foo/test.php')
+
+ AssertEqual
+ \ {
+ \ 'read_temporary_file': 1,
+ \ 'command': ale#Escape('pint')
+ \ . ' ' . g:ale_php_pint_options
+ \ . ' %t'
+ \ },
+ \ ale#fixers#pint#Fix(bufnr(''))
+
+Execute(The pint callback should include custom pint options):
+ let g:ale_php_pint_options = '--test'
+ call ale#test#SetFilename('../test-files/php/project-without-pint/test.php')
+
+ AssertEqual
+ \ {
+ \ 'command': ale#Escape(g:ale_php_pint_executable)
+ \ . ' --test %t',
+ \ 'read_temporary_file': 1,
+ \ },
+ \ ale#fixers#pint#Fix(bufnr(''))
diff --git a/test/test-files/php/project-with-pint/test.php b/test/test-files/php/project-with-pint/test.php
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/test-files/php/project-with-pint/test.php
diff --git a/test/test-files/php/project-with-pint/vendor/bin/pint b/test/test-files/php/project-with-pint/vendor/bin/pint
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/test-files/php/project-with-pint/vendor/bin/pint
diff --git a/test/test-files/php/project-without-pint/test.php b/test/test-files/php/project-without-pint/test.php
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/test-files/php/project-without-pint/test.php