All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Author: Jesse Harris - https://github.com/zigford
2 " Description: This file adds support for lintng powershell scripts
3 " using the PSScriptAnalyzer module.
5 " let g:ale_powershell_psscriptanalyzer_exclusions =
6 " \ 'PSAvoidUsingWriteHost,PSAvoidGlobalVars'
7 call ale#Set('powershell_psscriptanalyzer_exclusions', '')
8 call ale#Set('powershell_psscriptanalyzer_executable', 'pwsh')
9 call ale#Set('powershell_psscriptanalyzer_module',
12 function! ale_linters#powershell#psscriptanalyzer#GetExecutable(buffer) abort
13 return ale#Var(a:buffer, 'powershell_psscriptanalyzer_executable')
16 " Run Invoke-ScriptAnalyzer and output each linting message as 4 separate lines
18 function! ale_linters#powershell#psscriptanalyzer#GetCommand(buffer) abort
19 let l:exclude_option = ale#Var(
20 \ a:buffer, 'powershell_psscriptanalyzer_exclusions')
21 let l:module = ale#Var(
22 \ a:buffer, 'powershell_psscriptanalyzer_module')
23 let l:script = ['Param($Script);
24 \ Invoke-ScriptAnalyzer "$Script" '
25 \ . (!empty(l:exclude_option) ? '-Exclude ' . l:exclude_option : '')
26 \ . '| ForEach-Object {
32 return ale#powershell#RunPowerShell(
34 \ 'powershell_psscriptanalyzer',
38 " add every 4 lines to an item(Dict) and every item to a list
40 function! ale_linters#powershell#psscriptanalyzer#Handle(buffer, lines) abort
47 let l:item = {'lnum': str2nr(l:line)}
50 let l:item['type'] = 'E'
51 elseif l:line is# 'Information'
52 let l:item['type'] = 'I'
54 let l:item['type'] = 'W'
57 let l:item['text'] = l:line
59 let l:item['code'] = l:line
60 call add(l:output, l:item)
64 let l:lcount = l:lcount + 1
70 call ale#linter#Define('powershell', {
71 \ 'name': 'psscriptanalyzer',
72 \ 'executable': function('ale_linters#powershell#psscriptanalyzer#GetExecutable'),
73 \ 'command': function('ale_linters#powershell#psscriptanalyzer#GetCommand'),
74 \ 'output_stream': 'stdout',
75 \ 'callback': 'ale_linters#powershell#psscriptanalyzer#Handle',