summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--ale_linters/pony/ponyc.vim21
-rw-r--r--autoload/ale/handlers/pony.vim34
-rw-r--r--doc/ale-pony.txt25
-rw-r--r--doc/ale.txt3
-rw-r--r--test/command_callback/test_pony_ponyc_command_callbacks.vader23
-rw-r--r--test/handler/test_pony_handler.vader21
7 files changed, 128 insertions, 0 deletions
diff --git a/README.md b/README.md
index b09a643a..0a0e0d98 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 00000000..4120df51
--- /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 00000000..0ac18e76
--- /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 00000000..3b32168e
--- /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 6ace9d55..296d6406 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 00000000..e48346e8
--- /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 00000000..25a8254b
--- /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)',
+ \ ' ^',
+ \ ])