Merge pull request #2068 from m-pilia/ispc

Add linter for ispc
This commit is contained in:
w0rp 2018-11-21 16:44:59 +00:00 committed by GitHub
commit ff0bd14efe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 183 additions and 0 deletions

View File

@ -141,6 +141,7 @@ formatting.
| HCL | [terraform-fmt](https://github.com/hashicorp/terraform) |
| HTML | [alex](https://github.com/wooorm/alex) !!, [HTMLHint](http://htmlhint.com/), [proselint](http://proselint.com/), [tidy](http://www.html-tidy.org/), [prettier](https://github.com/prettier/prettier), [write-good](https://github.com/btford/write-good) |
| Idris | [idris](http://www.idris-lang.org/) |
| ISPC | [ispc](https://ispc.github.io/) !! |
| Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html), [google-java-format](https://github.com/google/google-java-format), [PMD](https://pmd.github.io/), [javalsp](https://github.com/georgewfraser/vscode-javac), [uncrustify](https://github.com/uncrustify/uncrustify) |
| JavaScript | [eslint](http://eslint.org/), [flow](https://flowtype.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [prettier](https://github.com/prettier/prettier), [prettier-eslint](https://github.com/prettier/prettier-eslint-cli), [prettier-standard](https://github.com/sheerun/prettier-standard), [standard](http://standardjs.com/), [xo](https://github.com/sindresorhus/xo)
| JSON | [fixjson](https://github.com/rhysd/fixjson), [jsonlint](http://zaa.ch/jsonlint/), [jq](https://stedolan.github.io/jq/), [prettier](https://github.com/prettier/prettier) |

45
ale_linters/ispc/ispc.vim Normal file
View File

@ -0,0 +1,45 @@
" Author: Martino Pilia <martino.pilia@gmail.com>
" Description: Lint ispc files with the Intel(R) SPMD Program Compiler
call ale#Set('ispc_ispc_executable', 'ispc')
call ale#Set('ispc_ispc_options', '')
function! ale_linters#ispc#ispc#GetCommand(buffer) abort
" --nowrap: do not wrap message lines
return '%e --nowrap'
\ . ale#Pad(ale#c#IncludeOptions(ale#c#FindLocalHeaderPaths(a:buffer)))
\ . ale#Pad(ale#Var(a:buffer, 'ispc_ispc_options'))
\ . ' %s'
endfunction
" Note that we ignore the two warnings in the beginning of the compiler output
" ('no output file specified' and 'no --target specified'), since they have
" nothing to do with linting.
function! ale_linters#ispc#ispc#Handle(buffer, lines) abort
" Message format: <filename>:<lnum>:<col> <type>: <text>
" As far as I know, <type> can be any of:
" 'error', 'Error', 'fatal error', 'Warning', 'Performance Warning'
let l:re = '\v.+:([0-9]+):([0-9]+):\s+([^:]+):\s+(.+)'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:re)
call add(l:output, {
\ 'bufnr': a:buffer,
\ 'lnum': str2nr(l:match[1]),
\ 'col': str2nr(l:match[2]),
\ 'type': l:match[3] =~? 'error' ? 'E' : 'W',
\ 'text': l:match[4],
\})
endfor
return l:output
endfunction
call ale#linter#Define('ispc', {
\ 'name': 'ispc',
\ 'output_stream': 'stderr',
\ 'executable_callback': ale#VarFunc('ispc_ispc_executable'),
\ 'command_callback': 'ale_linters#ispc#ispc#GetCommand',
\ 'callback': 'ale_linters#ispc#ispc#Handle',
\ 'lint_file': 1,
\})

24
doc/ale-ispc.txt Normal file
View File

@ -0,0 +1,24 @@
===============================================================================
ALE ISPC Integration *ale-ispc-options*
===============================================================================
ispc *ale-ispc-ispc*
g:ale_ispc_ispc_executable *g:ale_ispc_ispc_executable*
*b:ale_ispc_ispc_executable*
Type: |String|
Default: `'ispc'`
This variable can be changed to use a different executable for ispc.
g:ale_ispc_ispc_options *g:ale_ispc_ispc_options*
*b:ale_ispc_ispc_options*
Type: |String|
Default: `''`
This variable can be changed to modify flags given to ispc.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -147,6 +147,8 @@ CONTENTS *ale-contents*
write-good..........................|ale-html-write-good|
idris.................................|ale-idris-options|
idris...............................|ale-idris-idris|
ispc..................................|ale-ispc-options|
ispc................................|ale-ispc-ispc|
java..................................|ale-java-options|
checkstyle..........................|ale-java-checkstyle|
javac...............................|ale-java-javac|
@ -438,6 +440,7 @@ Notes:
* HCL: `terraform-fmt`
* HTML: `alex`!!, `HTMLHint`, `proselint`, `tidy`, `prettier`, `write-good`
* Idris: `idris`
* ISPC: `ispc`!!
* Java: `checkstyle`, `javac`, `google-java-format`, `PMD`, `javalsp`, `uncrustify`
* JavaScript: `eslint`, `flow`, `jscs`, `jshint`, `prettier`, `prettier-eslint`, `prettier-standard`, `standard`, `xo`
* JSON: `fixjson`, `jsonlint`, `jq`, `prettier`

View File

@ -0,0 +1,20 @@
Before:
call ale#assert#SetUpLinterTest('ispc', 'ispc')
After:
call ale#assert#TearDownLinterTest()
Execute(The executable should be configurable):
AssertLinter 'ispc',
\ ale#Escape('ispc') . ' --nowrap %s'
let b:ale_ispc_ispc_executable = 'foo'
AssertLinter 'foo',
\ ale#Escape('foo') . ' --nowrap %s'
Execute(The options should be configurable):
let g:ale_ispc_ispc_options = '--foo'
AssertLinter 'ispc',
\ ale#Escape('ispc') . ' --nowrap --foo' . ' %s'

View File

@ -0,0 +1,90 @@
Before:
runtime ale_linters/ispc/ispc.vim
After:
call ale#linter#Reset()
Execute(The ispc handler should parse input correctly):
AssertEqual
\ [
\ {
\ 'bufnr': 0,
\ 'lnum': 33,
\ 'col': 14,
\ 'type': 'E',
\ 'text': 'syntax error, unexpected ''int'', expecting '','' or '';''.',
\ },
\ {
\ 'bufnr': 0,
\ 'lnum': 36,
\ 'col': 5,
\ 'type': 'E',
\ 'text': 'syntax error, unexpected ''for''.',
\ },
\ {
\ 'bufnr': 0,
\ 'lnum': 51,
\ 'col': 9,
\ 'type': 'E',
\ 'text': '''foobar.h'' file not found',
\ },
\ {
\ 'bufnr': 0,
\ 'lnum': 79,
\ 'col': 52,
\ 'type': 'W',
\ 'text': 'Modulus operator with varying types is very inefficient.',
\ },
\ {
\ 'bufnr': 0,
\ 'lnum': 85,
\ 'col': 13,
\ 'type': 'W',
\ 'text': 'Undefined behavior: all program instances are writing to the same location!',
\ },
\ {
\ 'bufnr': 0,
\ 'lnum': 93,
\ 'col': 19,
\ 'type': 'W',
\ 'text': 'Gather required to load value.',
\ },
\ {
\ 'bufnr': 0,
\ 'lnum': 93,
\ 'col': 9,
\ 'type': 'W',
\ 'text': 'Scatter required to store value.',
\ },
\ ],
\ ale_linters#ispc#ispc#Handle(0, [
\ 'Warning: No output file or header file name specified. Program will be compiled and warnings/errors will be issued, but no output will be generated. ',
\ 'Warning: No --target specified on command-line. Using default system target "avx2-i32x8".',
\ 'mandelbrot.ispc:33:14: Error: syntax error, unexpected ''int'', expecting '','' or '';''.',
\ 'static iline int mandel(float c_re, float c_im, int count) {',
\ ' ^^^',
\ '',
\ 'mandelbrot.ispc:36:5: Error: syntax error, unexpected ''for''.',
\ ' for (i = 0; i < count; ++i) {',
\ ' ^^^',
\ '',
\ 'mandelbrot.ispc:51:9: fatal error: ''foobar.h'' file not found',
\ '#include<foobar.h>',
\ ' ^~~~~~~~~~',
\ 'mandelbrot.ispc:79:52: Performance Warning: Modulus operator with varying types is very inefficient.',
\ ' double x = x0 + i * (dx + epsilon*(k%2)*delta);',
\ ' ^^^',
\ '',
\ 'mandelbrot.ispc:85:13: Warning: Undefined behavior: all program instances are writing to the same location!',
\ ' output[index] = (NNN) / sample_size;',
\ ' ^^^^^^^^^^^^^',
\ '',
\ 'mandelbrot.ispc:93:19: Performance Warning: Gather required to load value.',
\ ' A[i*8] *= A[i*8];',
\ ' ^^^^^^',
\ '',
\ 'mandelbrot.ispc:93:9: Performance Warning: Scatter required to store value.',
\ ' A[i*8] *= A[i*8];',
\ ' ^^^^^^',
\ '',
\ ])