Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(D): add D-Scanner #2563

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 35 additions & 1 deletion autoload/neomake/makers/ft/d.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
function! neomake#makers#ft#d#EnabledMakers() abort
" dmd, ldmd, and gdmd all share a common CLI.
" Ordered in efficiency of compiler
for m in ['dmd', 'ldmd', 'gdmd']
for m in ['dmd', 'ldmd', 'gdmd', 'dscanner']
if executable(m)
return [m]
endif
Expand Down Expand Up @@ -90,3 +90,37 @@ function! neomake#makers#ft#d#gdmd() abort
\ '%f:%l: %m',
\ }
endfunction

function! neomake#makers#ft#d#DScannerProcessJSON(context) abort
let entries = []
for i in get(a:context.json, 'issues', [])
let type='E'
if i.type ==# 'warn'
let type = 'W'
endif
let length = i.endIndex - i.index
let entry = {
\ 'code': i.key,
\ 'col': i.column,
\ 'end_col': i.endColumn,
\ 'end_lnum': i.endLine,
\ 'filename': i['fileName'],
\ 'length': length,
\ 'lnum': i.line,
\ 'maker_name': 'dscanner',
\ 'text': i.message,
\ 'type': type,
\ }
call add(entries, entry)
endfor
return entries

endfunction

function! neomake#makers#ft#d#dscanner() abort
return {
\ 'args': ['--report', 'source/'],
\ 'process_json': function('neomake#makers#ft#d#DScannerProcessJSON'),
\ 'supports_stdin': 0,
\ }
endfunction
48 changes: 48 additions & 0 deletions tests/ft_d.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Include: include/setup.vader

Execute (d: dscanner):
let null = g:neomake#compat#json_null
let true = g:neomake#compat#json_true

let json_output = '
\ {
\ "classCount": 0,
\ "functionCount": 1,
\ "interfaceCount": 0,
\ "issues": [
\ {
\ "column": 13,
\ "endColumn": 16,
\ "endIndex": 48,
\ "endLine": 5,
\ "fileName": "source\/app.d",
\ "index": 45,
\ "key": "dscanner.suspicious.unused_variable",
\ "line": 5,
\ "message": "Variable abc is never used.",
\ "name": "unused_variable_check",
\ "supplemental": [],
\ "type": "warn"
\ }
\ ],
\ "lineOfCodeCount": 3,
\ "statementCount": 1,
\ "structCount": 0,
\ "templateCount": 0,
\ "undocumentedPublicSymbols": 0
\ }
\ '
let context = {'json': neomake#compat#json_decode(json_output)}
let errors = neomake#makers#ft#d#DScannerProcessJSON(context)
AssertEqual [{
\ 'lnum': 5,
\ 'col': 13,
\ 'end_col': 16,
\ 'end_lnum': 5,
\ 'filename': 'source/app.d',
\ 'code': 'dscanner.suspicious.unused_variable',
\ 'length': 3,
\ 'type': 'W',
\ 'maker_name': 'dscanner',
\ 'text': 'Variable abc is never used.',
\ }], errors
1 change: 1 addition & 0 deletions tests/main.vader
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Include (Asciidoc): ft_asciidoc.vader
Include (Clojure): ft_clojure.vader
Include (Cs): ft_cs.vader
Include (Css): ft_css.vader
Include (D): ft_d.vader
Include (Dockerfile): ft_dockerfile.vader
Include (Elixir): ft_elixir.vader
Include (Elm): ft_elm.vader
Expand Down