From 716b46e10d2abe54daa09e876d4b7a6b56024ad0 Mon Sep 17 00:00:00 2001 From: Kevin Tindall Date: Sat, 10 Feb 2018 13:04:43 -0600 Subject: [PATCH] functional pony linter --- README.md | 1 + ale_linters/pony/ponyc.vim | 21 ++++++++++++ autoload/ale/handlers/pony.vim | 34 +++++++++++++++++++ doc/ale-pony.txt | 25 ++++++++++++++ doc/ale.txt | 3 ++ .../test_pony_ponyc_command_callbacks.vader | 23 +++++++++++++ test/handler/test_pony_handler.vader | 21 ++++++++++++ 7 files changed, 128 insertions(+) create mode 100644 ale_linters/pony/ponyc.vim create mode 100644 autoload/ale/handlers/pony.vim create mode 100644 doc/ale-pony.txt create mode 100644 test/command_callback/test_pony_ponyc_command_callbacks.vader create mode 100644 test/handler/test_pony_handler.vader diff --git a/README.md b/README.md index b09a643..0a0e0d9 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,7 @@ formatting. | PHP | [hack](http://hacklang.org/), [hackfmt](https://github.com/facebook/flow/tree/master/hack/hackfmt), [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/), [phpcs](https://github.com/squizlabs/PHP_CodeSniffer), [phpmd](https://phpmd.org), [phpstan](https://github.com/phpstan/phpstan), [phpcbf](https://github.com/squizlabs/PHP_CodeSniffer) | | PO | [alex](https://github.com/wooorm/alex) !!, [msgfmt](https://www.gnu.org/software/gettext/manual/html_node/msgfmt-Invocation.html), [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) | | Pod | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) | +| Pony | [ponyc](https://github.com/ponylang/ponyc) | | proto | [protoc-gen-lint](https://github.com/ckaznocha/protoc-gen-lint) | | Pug | [pug-lint](https://github.com/pugjs/pug-lint) | | Puppet | [puppet](https://puppet.com), [puppet-lint](https://puppet-lint.com) | diff --git a/ale_linters/pony/ponyc.vim b/ale_linters/pony/ponyc.vim new file mode 100644 index 0000000..4120df5 --- /dev/null +++ b/ale_linters/pony/ponyc.vim @@ -0,0 +1,21 @@ +" Description: ponyc linter for pony files + +call ale#Set('pony_ponyc_executable', 'ponyc') +call ale#Set('pony_ponyc_options', '--pass paint') + +function! ale_linters#pony#ponyc#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'pony_ponyc_executable') +endfunction + +function! ale_linters#pony#ponyc#GetCommand(buffer) abort + return ale_linters#pony#ponyc#GetExecutable(a:buffer) + \ . ' ' . ale#Var(a:buffer, 'pony_ponyc_options') +endfunction + +call ale#linter#Define('pony', { +\ 'name': 'ponyc', +\ 'output_stream': 'stderr', +\ 'executable_callback': 'ale_linters#pony#ponyc#GetExecutable', +\ 'command_callback': 'ale_linters#pony#ponyc#GetCommand', +\ 'callback': 'ale#handlers#pony#HandlePonycFormat', +\}) diff --git a/autoload/ale/handlers/pony.vim b/autoload/ale/handlers/pony.vim new file mode 100644 index 0000000..0ac18e7 --- /dev/null +++ b/autoload/ale/handlers/pony.vim @@ -0,0 +1,34 @@ +scriptencoding utf-8 +" Description: This file defines a handler function which ought to work for +" any program which outputs errors in the format that ponyc uses. + +function! s:RemoveUnicodeQuotes(text) abort + let l:text = a:text + let l:text = substitute(l:text, '[`´‘’]', '''', 'g') + let l:text = substitute(l:text, '\v\\u2018([^\\]+)\\u2019', '''\1''', 'g') + let l:text = substitute(l:text, '[“”]', '"', 'g') + + return l:text +endfunction + +function! ale#handlers#pony#HandlePonycFormat(buffer, lines) abort + " Look for lines like the following. + " /home/code/pony/classes/Wombat.pony:22:30: can't lookup private fields from outside the type + + let l:pattern = '\v^([^:]+):(\d+):(\d+)?:? (.+)$' + let l:output = [] + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + let l:item = { + \ 'filename': l:match[1], + \ 'lnum': str2nr(l:match[2]), + \ 'col': str2nr(l:match[3]), + \ 'type': 'E', + \ 'text': s:RemoveUnicodeQuotes(l:match[4]), + \} + + call add(l:output, l:item) + endfor + + return l:output +endfunction diff --git a/doc/ale-pony.txt b/doc/ale-pony.txt new file mode 100644 index 0000000..3b32168 --- /dev/null +++ b/doc/ale-pony.txt @@ -0,0 +1,25 @@ +=============================================================================== +ALE Pony Integration *ale-pony-options* + + +=============================================================================== +ponyc *ale-pony-ponyc* + +g:ale_pony_ponyc_executable *g:ale_pony_ponyc_executable* + *b:ale_pony_ponyc_executable* + Type: |String| + Default: `'ponyc'` + + See |ale-integrations-local-executables| + + +g:ale_pony_ponyc_options *g:ale_pony_ponyc_options* + *b:ale_pony_ponyc_options* + Type: |String| + Default: `'--pass paint'` + + This variable can be set to pass options to ponyc. + + +=============================================================================== + vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index 6ace9d5..296d640 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -160,6 +160,8 @@ CONTENTS *ale-contents* write-good..........................|ale-po-write-good| pod...................................|ale-pod-options| write-good..........................|ale-pod-write-good| + pony..................................|ale-pony-options| + ponyc...............................|ale-pony-ponyc| proto.................................|ale-proto-options| protoc-gen-lint.....................|ale-proto-protoc-gen-lint| pug...................................|ale-pug-options| @@ -349,6 +351,7 @@ Notes: * PHP: `hack`, `hackfmt`, `langserver`, `phan`, `php -l`, `phpcs`, `phpmd`, `phpstan`, `phpcbf` * PO: `alex`!!, `msgfmt`, `proselint`, `write-good` * Pod: `alex`!!, `proselint`, `write-good` +* Pony: `ponyc` * proto: `protoc-gen-lint` * Pug: `pug-lint` * Puppet: `puppet`, `puppet-lint` diff --git a/test/command_callback/test_pony_ponyc_command_callbacks.vader b/test/command_callback/test_pony_ponyc_command_callbacks.vader new file mode 100644 index 0000000..e48346e --- /dev/null +++ b/test/command_callback/test_pony_ponyc_command_callbacks.vader @@ -0,0 +1,23 @@ +Before: + Save g:ale_pony_ponyc_options + + unlet! g:ale_pony_ponyc_options + unlet! b:ale_pony_ponyc_options + + runtime ale_linters/pony/ponyc.vim + +After: + Restore + unlet! b:ale_pony_ponyc_options + call ale#linter#Reset() + +Execute(The options should be used in the command): + AssertEqual + \ 'ponyc --pass paint', + \ ale_linters#pony#ponyc#GetCommand(bufnr('')) + + let b:ale_pony_ponyc_options = 'foobar' + + AssertEqual + \ 'ponyc foobar', + \ ale_linters#pony#ponyc#GetCommand(bufnr('')) diff --git a/test/handler/test_pony_handler.vader b/test/handler/test_pony_handler.vader new file mode 100644 index 0000000..25a8254 --- /dev/null +++ b/test/handler/test_pony_handler.vader @@ -0,0 +1,21 @@ +Execute(The pony handler should handle ponyc output): + call ale#test#SetFilename('foo.pony') + + AssertEqual + \ [ + \ { + \ 'filename': '/home/projects/Wombat.pony', + \ 'lnum': 22, + \ 'type': 'E', + \ 'col': 30, + \ 'text': 'can''t lookup private fields from outside the type', + \ }, + \ ], + \ ale#handlers#pony#HandlePonycFormat(bufnr(''), [ + \ 'Building builtin -> /usr/lib/pony/0.21.3/packages/builtin', + \ 'Building . -> /home/projects', + \ 'Error:', + \ '/home/projects/Wombat.pony:22:30: can''t lookup private fields from outside the type', + \ ' env.out.print(defaultWombat._hunger_level)', + \ ' ^', + \ ])