dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.52k stars 1.43k forks source link

php shell / cli script and namespaces #4235

Open Nickwiz opened 2 years ago

Nickwiz commented 2 years ago

Discussed in https://github.com/dense-analysis/ale/discussions/4232

Originally posted by **Nickwiz** June 14, 2022 When using ALE with PHP as cgi, shell script ... and using `namespace` the first lines can be something like: ```php #! /usr/bin/env php Namespace declaration statement has to be the very first statement or after any declare call in the script It complains about the *shebang* and note that PHP does so if the file is redirected instead of used as an argument, i.e: **OK:** ```sh $ php -l -d error_reporting=E_ALL -d display_errors=1 -d log_errors=0 test.php No syntax errors detected in test.php $ php test.php OK $ ./test.php OK ``` **BAD:** ```sh $ php -l -d error_reporting=E_ALL -d display_errors=1 -d log_errors=0
hsanson commented 2 years ago

You can see the command that ALE uses at php.vim#L37

call ale#linter#Define('php', {
\   'name': 'php',
\   'executable': {b -> ale#Var(b, 'php_php_executable')},
\   'output_stream': 'stdout',
\   'command': '%e -l -d error_reporting=E_ALL -d display_errors=1 -d log_errors=0 --',
\   'callback': 'ale_linters#php#php#Handle',
\})

By default ALE uses stdin (redirection) for passing the data to the linters but this can be changed by setting the lint_file option to "1". See :h ale#linter#Define. Unfortunatelly this change would require changes to ALEs code as this cannot be changed via config and also reading files from disk disables linting while typing. Read the docs in lint_file option for more details.