/pack/general/start/ale/ale_linters/php/phpcs.vim

https://bitbucket.org/lilydjwg/dotvim · Vim Script · 54 lines · 40 code · 9 blank · 5 comment · 1 complexity · 7dbdd066a87783542ab7f36d4292ecf9 MD5 · raw file

  1. " Author: jwilliams108 <https://github.com/jwilliams108>, Eric Stern <https://github.com/firehed>
  2. " Description: phpcs for PHP files
  3. let g:ale_php_phpcs_standard = get(g:, 'ale_php_phpcs_standard', '')
  4. call ale#Set('php_phpcs_options', '')
  5. call ale#Set('php_phpcs_executable', 'phpcs')
  6. call ale#Set('php_phpcs_use_global', get(g:, 'ale_use_global_executables', 0))
  7. function! ale_linters#php#phpcs#GetCommand(buffer) abort
  8. let l:standard = ale#Var(a:buffer, 'php_phpcs_standard')
  9. let l:standard_option = !empty(l:standard)
  10. \ ? '--standard=' . ale#Escape(l:standard)
  11. \ : ''
  12. return ale#path#BufferCdString(a:buffer)
  13. \ . '%e -s --report=emacs --stdin-path=%s'
  14. \ . ale#Pad(l:standard_option)
  15. \ . ale#Pad(ale#Var(a:buffer, 'php_phpcs_options'))
  16. endfunction
  17. function! ale_linters#php#phpcs#Handle(buffer, lines) abort
  18. " Matches against lines like the following:
  19. "
  20. " /path/to/some-filename.php:18:3: error - Line indented incorrectly; expected 4 spaces, found 2 (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
  21. let l:pattern = '^.*:\(\d\+\):\(\d\+\): \(.\+\) - \(.\+\) (\(.\+\))$'
  22. let l:output = []
  23. for l:match in ale#util#GetMatches(a:lines, l:pattern)
  24. let l:code = l:match[5]
  25. let l:text = l:match[4] . ' (' . l:code . ')'
  26. let l:type = l:match[3]
  27. call add(l:output, {
  28. \ 'lnum': l:match[1] + 0,
  29. \ 'col': l:match[2] + 0,
  30. \ 'text': l:text,
  31. \ 'type': l:type is# 'error' ? 'E' : 'W',
  32. \ 'sub_type': 'style',
  33. \})
  34. endfor
  35. return l:output
  36. endfunction
  37. call ale#linter#Define('php', {
  38. \ 'name': 'phpcs',
  39. \ 'executable': {b -> ale#node#FindExecutable(b, 'php_phpcs', [
  40. \ 'vendor/bin/phpcs',
  41. \ 'phpcs'
  42. \ ])},
  43. \ 'command': function('ale_linters#php#phpcs#GetCommand'),
  44. \ 'callback': 'ale_linters#php#phpcs#Handle',
  45. \})