Add a script for custom checks to enforce using the abort flag for functions and trailing whitespace, and fix existing issues.
This commit is contained in:
parent
e4a4fcd26b
commit
d7ed49f849
8
Makefile
8
Makefile
@ -30,6 +30,14 @@ test: test-setup
|
||||
docker run -a stdout $(DOCKER_FLAGS) vint -s /testplugin | sed s:^/testplugin/:: || EXIT=$$?; \
|
||||
set +o pipefail; \
|
||||
echo; \
|
||||
echo '========================================'; \
|
||||
echo 'Running custom checks'; \
|
||||
echo '========================================'; \
|
||||
echo 'Custom warnings/errors follow:'; \
|
||||
echo; \
|
||||
set -o pipefail; \
|
||||
docker run -a stdout $(DOCKER_FLAGS) /testplugin/custom-checks /testplugin | sed s:^/testplugin/:: || EXIT=$$?; \
|
||||
set +o pipefail; \
|
||||
echo; \
|
||||
exit $$EXIT;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
" Author: Edward Larkey <edwlarkey@mac.com>
|
||||
" Description: This file adds the foodcritic linter for Chef files.
|
||||
|
||||
function! ale_linters#chef#foodcritic#Handle(buffer, lines)
|
||||
function! ale_linters#chef#foodcritic#Handle(buffer, lines) abort
|
||||
" Matches patterns line the following:
|
||||
"
|
||||
" FC002: Avoid string interpolation where not required: httpd.rb:13
|
||||
|
@ -1,7 +1,7 @@
|
||||
" Author: Prashanth Chandra https://github.com/prashcr
|
||||
" Description: coffeelint linter for coffeescript files
|
||||
|
||||
function! ale_linters#coffee#coffeelint#Handle(buffer, lines)
|
||||
function! ale_linters#coffee#coffeelint#Handle(buffer, lines) abort
|
||||
" Matches patterns like the following:
|
||||
"
|
||||
" path,lineNumber,lineNumberEnd,level,message
|
||||
|
@ -2,7 +2,7 @@
|
||||
" Description: "dmd for D files"
|
||||
|
||||
" A function for finding the dmd-wrapper script in the Vim runtime paths
|
||||
function! s:FindWrapperScript()
|
||||
function! s:FindWrapperScript() abort
|
||||
for l:parent in split(&runtimepath, ',')
|
||||
" Expand the path to deal with ~ issues.
|
||||
let l:path = expand(l:parent . '/' . 'dmd-wrapper')
|
||||
@ -13,7 +13,7 @@ function! s:FindWrapperScript()
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! ale_linters#d#dmd#GetCommand(buffer)
|
||||
function! ale_linters#d#dmd#GetCommand(buffer) abort
|
||||
let l:wrapper_script = s:FindWrapperScript()
|
||||
|
||||
let l:command = l:wrapper_script . ' -o- -vcolumns -c'
|
||||
@ -21,7 +21,7 @@ function! ale_linters#d#dmd#GetCommand(buffer)
|
||||
return l:command
|
||||
endfunction
|
||||
|
||||
function! ale_linters#d#dmd#Handle(buffer, lines)
|
||||
function! ale_linters#d#dmd#Handle(buffer, lines) abort
|
||||
" Matches patterns lines like the following:
|
||||
" /tmp/tmp.qclsa7qLP7/file.d(1): Error: function declaration without return type. (Note that constructors are always named 'this')
|
||||
" /tmp/tmp.G1L5xIizvB.d(8,8): Error: module weak_reference is in file 'dstruct/weak_reference.d' which cannot be read
|
||||
|
@ -1,6 +1,6 @@
|
||||
" Author: hauleth - https://github.com/haulethe
|
||||
|
||||
function! ale_linters#elixir#credo#Handle(buffer, lines)
|
||||
function! ale_linters#elixir#credo#Handle(buffer, lines) abort
|
||||
" Matches patterns line the following:
|
||||
"
|
||||
" stdin:19: F: Pipe chain should start with a raw value.
|
||||
|
@ -1,7 +1,7 @@
|
||||
" Author: buffalocoder - https://github.com/buffalocoder
|
||||
" Description: Elm linting in Ale. Closely follows the Syntastic checker in https://github.com/ElmCast/elm-vim.
|
||||
|
||||
function! ale_linters#elm#make#Handle(buffer, lines)
|
||||
function! ale_linters#elm#make#Handle(buffer, lines) abort
|
||||
let l:output = []
|
||||
let l:is_windows = has('win32')
|
||||
let l:temp_dir = l:is_windows ? $TMP : $TMPDIR
|
||||
|
@ -6,7 +6,7 @@ if !exists('g:ale_fortran_gcc_options')
|
||||
let g:ale_fortran_gcc_options = '-Wall'
|
||||
endif
|
||||
|
||||
function! ale_linters#fortran#gcc#Handle(buffer, lines)
|
||||
function! ale_linters#fortran#gcc#Handle(buffer, lines) abort
|
||||
" We have to match a starting line and a later ending line together,
|
||||
" like so.
|
||||
"
|
||||
|
@ -7,7 +7,7 @@ endif
|
||||
|
||||
let g:loaded_ale_linters_haskell_ghc = 1
|
||||
|
||||
function! ale_linters#haskell#ghc#Handle(buffer, lines)
|
||||
function! ale_linters#haskell#ghc#Handle(buffer, lines) abort
|
||||
" Look for lines like the following.
|
||||
"
|
||||
" /dev/stdin:28:26: Not in scope: `>>>>>'
|
||||
|
@ -1,7 +1,7 @@
|
||||
" Author: jparoz <jesse.paroz@gmail.com>
|
||||
" Description: hlint for Haskell files
|
||||
|
||||
function! ale_linters#haskell#hlint#Handle(buffer, lines)
|
||||
function! ale_linters#haskell#hlint#Handle(buffer, lines) abort
|
||||
let l:errors = json_decode(join(a:lines, ''))
|
||||
|
||||
let l:output = []
|
||||
|
@ -28,7 +28,7 @@ function! ale_linters#javascript#eslint#GetCommand(buffer) abort
|
||||
\ . ' -f unix --stdin --stdin-filename %s'
|
||||
endfunction
|
||||
|
||||
function! ale_linters#javascript#eslint#Handle(buffer, lines)
|
||||
function! ale_linters#javascript#eslint#Handle(buffer, lines) abort
|
||||
" Matches patterns line the following:
|
||||
"
|
||||
" /path/to/some-filename.js:47:14: Missing trailing comma. [Warning/comma-dangle]
|
||||
|
@ -24,7 +24,7 @@ function! ale_linters#javascript#flow#GetCommand(buffer) abort
|
||||
\ . ' check-contents --respect-pragma --json --from ale %s'
|
||||
endfunction
|
||||
|
||||
function! ale_linters#javascript#flow#Handle(buffer, lines)
|
||||
function! ale_linters#javascript#flow#Handle(buffer, lines) abort
|
||||
let l:str = join(a:lines, '')
|
||||
if l:str ==# ''
|
||||
return []
|
||||
|
@ -19,7 +19,7 @@ function! ale_linters#javascript#jshint#GetExecutable(buffer) abort
|
||||
\)
|
||||
endfunction
|
||||
|
||||
function! ale_linters#javascript#jshint#GetCommand(buffer)
|
||||
function! ale_linters#javascript#jshint#GetCommand(buffer) abort
|
||||
" Search for a local JShint config locaation, and default to a global one.
|
||||
let l:jshint_config = ale#util#ResolveLocalPath(
|
||||
\ a:buffer,
|
||||
|
@ -1,6 +1,6 @@
|
||||
" Author: KabbAmine <amine.kabb@gmail.com>
|
||||
|
||||
function! ale_linters#json#jsonlint#Handle(buffer, lines)
|
||||
function! ale_linters#json#jsonlint#Handle(buffer, lines) abort
|
||||
" Matches patterns like the following:
|
||||
" line 2, col 15, found: 'STRING' - expected: 'EOF', '}', ',', ']'.
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
let g:ale_lua_luacheck_executable =
|
||||
\ get(g:, 'ale_lua_luacheck_executable', 'luacheck')
|
||||
|
||||
function! ale_linters#lua#luacheck#Handle(buffer, lines)
|
||||
function! ale_linters#lua#luacheck#Handle(buffer, lines) abort
|
||||
" Matches patterns line the following:
|
||||
"
|
||||
" artal.lua:159:17: (W111) shadowing definition of loop variable 'i' on line 106
|
||||
|
@ -4,7 +4,7 @@
|
||||
let g:ale_matlab_mlint_executable =
|
||||
\ get(g:, 'ale_matlab_mlint_executable', 'mlint')
|
||||
|
||||
function! ale_linters#matlab#mlint#Handle(buffer, lines)
|
||||
function! ale_linters#matlab#mlint#Handle(buffer, lines) abort
|
||||
" Matches patterns like the following:
|
||||
"
|
||||
" L 27 (C 1): FNDEF: Terminate statement with semicolon to suppress output.
|
||||
|
@ -5,7 +5,7 @@ if !exists('g:merlin')
|
||||
finish
|
||||
endif
|
||||
|
||||
function! ale_linters#ocaml#merlin#Handle(buffer, lines)
|
||||
function! ale_linters#ocaml#merlin#Handle(buffer, lines) abort
|
||||
let l:errors = merlin#ErrorLocList()
|
||||
return l:errors
|
||||
endfunction
|
||||
|
@ -1,7 +1,7 @@
|
||||
" Author: Vincent Lequertier <https://github.com/SkySymbol>
|
||||
" Description: This file adds support for checking perl syntax
|
||||
|
||||
function! ale_linters#perl#perl#Handle(buffer, lines)
|
||||
function! ale_linters#perl#perl#Handle(buffer, lines) abort
|
||||
let l:pattern = '\(.\+\) at \(.\+\) line \(\d\+\)'
|
||||
let l:output = []
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
" Author: Vincent Lequertier <https://github.com/SkySymbol>
|
||||
" Description: This file adds support for checking perl with perl critic
|
||||
|
||||
function! ale_linters#perl#perlcritic#Handle(buffer, lines)
|
||||
function! ale_linters#perl#perlcritic#Handle(buffer, lines) abort
|
||||
let l:pattern = '\(.\+\) at \(.\+\) line \(\d\+\)'
|
||||
let l:output = []
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
" Author: Zefei Xuan <https://github.com/zefei>
|
||||
" Description: Hack type checking (http://hacklang.org/)
|
||||
|
||||
function! ale_linters#php#hack#Handle(buffer, lines)
|
||||
function! ale_linters#php#hack#Handle(buffer, lines) abort
|
||||
let l:pattern = '^\(.*\):\(\d\+\):\(\d\+\),\(\d\+\): \(.\+])\)$'
|
||||
let l:output = []
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
" Author: Spencer Wood <https://github.com/scwood>
|
||||
" Description: This file adds support for checking PHP with php-cli
|
||||
|
||||
function! ale_linters#php#php#Handle(buffer, lines)
|
||||
function! ale_linters#php#php#Handle(buffer, lines) abort
|
||||
" Matches patterns like the following:
|
||||
"
|
||||
" Parse error: parse error in - on line 7
|
||||
|
@ -1,7 +1,7 @@
|
||||
" Author: jwilliams108 <https://github.com/jwilliams108>
|
||||
" Description: phpcs for PHP files
|
||||
|
||||
function! ale_linters#php#phpcs#GetCommand(buffer)
|
||||
function! ale_linters#php#phpcs#GetCommand(buffer) abort
|
||||
let l:command = 'phpcs -s --report=emacs --stdin-path=%s'
|
||||
|
||||
" This option can be set to change the standard used by phpcs
|
||||
@ -12,7 +12,7 @@ function! ale_linters#php#phpcs#GetCommand(buffer)
|
||||
return l:command
|
||||
endfunction
|
||||
|
||||
function! ale_linters#php#phpcs#Handle(buffer, lines)
|
||||
function! ale_linters#php#phpcs#Handle(buffer, lines) abort
|
||||
" Matches against lines like the following:
|
||||
"
|
||||
" /path/to/some-filename.php:18:3: error - Line indented incorrectly; expected 4 spaces, found 2 (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
|
||||
|
@ -1,6 +1,6 @@
|
||||
" Author: Alexander Olofsson <alexander.olofsson@liu.se>
|
||||
|
||||
function! ale_linters#puppet#puppet#Handle(buffer, lines)
|
||||
function! ale_linters#puppet#puppet#Handle(buffer, lines) abort
|
||||
" Matches patterns like the following:
|
||||
" Error: Could not parse for environment production: Syntax error at ':' at /root/puppetcode/modules/nginx/manifests/init.pp:43:12
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
" Author: ynonp - https://github.com/ynonp
|
||||
" Description: rubocop for Ruby files
|
||||
|
||||
function! ale_linters#ruby#rubocop#Handle(buffer, lines)
|
||||
function! ale_linters#ruby#rubocop#Handle(buffer, lines) abort
|
||||
" Matches patterns line the following:
|
||||
"
|
||||
" <path>/_:47:14: 83:29: C: Prefer single-quoted strings when you don't
|
||||
|
@ -2,7 +2,7 @@
|
||||
" Description: rustc invoked by cargo for rust files
|
||||
|
||||
|
||||
function! ale_linters#rust#cargo#GetCargoExecutable(bufnr)
|
||||
function! ale_linters#rust#cargo#GetCargoExecutable(bufnr) abort
|
||||
if ale#util#FindNearestFile(a:bufnr, 'Cargo.toml') !=# ''
|
||||
return 'cargo'
|
||||
else
|
||||
|
@ -2,7 +2,7 @@
|
||||
" Author: Zoltan Kalmar - https://github.com/kalmiz
|
||||
" Description: Basic scala support using scalac
|
||||
|
||||
function! ale_linters#scala#scalac#Handle(buffer, lines)
|
||||
function! ale_linters#scala#scalac#Handle(buffer, lines) abort
|
||||
" Matches patterns line the following:
|
||||
"
|
||||
" /var/folders/5q/20rgxx3x1s34g3m14n5bq0x80000gn/T/vv6pSsy/0:26: error: expected class or object definition
|
||||
|
@ -1,7 +1,7 @@
|
||||
" Author: w0rp <devw0rp@gmail.com>
|
||||
" Description: This file add scsslint support for SCSS support
|
||||
|
||||
function! ale_linters#scss#scsslint#Handle(buffer, lines)
|
||||
function! ale_linters#scss#scsslint#Handle(buffer, lines) abort
|
||||
" Matches patterns like the following:
|
||||
"
|
||||
" test.scss:2:1 [W] Indentation: Line should be indented 2 spaces, but was indented 4 spaces
|
||||
|
@ -11,7 +11,7 @@ if !exists('g:ale_linters_sh_shell_default_shell')
|
||||
endif
|
||||
endif
|
||||
|
||||
function! ale_linters#sh#shell#GetExecutable(buffer)
|
||||
function! ale_linters#sh#shell#GetExecutable(buffer) abort
|
||||
let l:banglines = getbufline(a:buffer, 1)
|
||||
|
||||
" Take the shell executable from the hashbang, if we can.
|
||||
@ -29,11 +29,11 @@ function! ale_linters#sh#shell#GetExecutable(buffer)
|
||||
return g:ale_linters_sh_shell_default_shell
|
||||
endfunction
|
||||
|
||||
function! ale_linters#sh#shell#GetCommand(buffer)
|
||||
function! ale_linters#sh#shell#GetCommand(buffer) abort
|
||||
return ale_linters#sh#shell#GetExecutable(a:buffer) . ' -n'
|
||||
endfunction
|
||||
|
||||
function! ale_linters#sh#shell#Handle(buffer, lines)
|
||||
function! ale_linters#sh#shell#Handle(buffer, lines) abort
|
||||
" Matches patterns line the following:
|
||||
"
|
||||
" bash: line 13: syntax error near unexpected token `d'
|
||||
|
@ -16,7 +16,7 @@ else
|
||||
let s:exclude_option = ''
|
||||
endif
|
||||
|
||||
function! s:GetDialectArgument()
|
||||
function! s:GetDialectArgument() abort
|
||||
if exists('b:is_bash') && b:is_bash
|
||||
return '-s bash'
|
||||
elseif exists('b:is_sh') && b:is_sh
|
||||
@ -28,7 +28,7 @@ function! s:GetDialectArgument()
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! ale_linters#sh#shellcheck#GetCommand(buffer)
|
||||
function! ale_linters#sh#shellcheck#GetCommand(buffer) abort
|
||||
return 'shellcheck ' . s:exclude_option . ' ' . s:GetDialectArgument() . ' -f gcc -'
|
||||
endfunction
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
" Author: Prashanth Chandra https://github.com/prashcr
|
||||
" Description: tslint for TypeScript files
|
||||
|
||||
function! ale_linters#typescript#tslint#Handle(buffer, lines)
|
||||
function! ale_linters#typescript#tslint#Handle(buffer, lines) abort
|
||||
" Matches patterns like the following:
|
||||
"
|
||||
" hello.ts[7, 41]: trailing whitespace
|
||||
|
@ -1,7 +1,7 @@
|
||||
" Author: Prashanth Chandra https://github.com/prashcr, Aleh Kashnikau https://github.com/mkusher
|
||||
" Description: type checker for TypeScript files
|
||||
|
||||
function! ale_linters#typescript#typecheck#Handle(buffer, lines)
|
||||
function! ale_linters#typescript#typecheck#Handle(buffer, lines) abort
|
||||
" Matches patterns like the following:
|
||||
"
|
||||
" hello.ts[7, 41]: Property 'a' does not exist on type 'A'
|
||||
|
@ -1,7 +1,7 @@
|
||||
" Author: Masahiro H https://github.com/mshr-h
|
||||
" Description: iverilog for verilog files
|
||||
|
||||
function! ale_linters#verilog#iverilog#Handle(buffer, lines)
|
||||
function! ale_linters#verilog#iverilog#Handle(buffer, lines) abort
|
||||
" Look for lines like the following.
|
||||
"
|
||||
" tb_me_top.v:37: warning: Instantiating module me_top with dangling input port 1 (rst_n) floating.
|
||||
|
@ -1,7 +1,7 @@
|
||||
" Author: Masahiro H https://github.com/mshr-h
|
||||
" Description: verilator for verilog files
|
||||
|
||||
function! ale_linters#verilog#verilator#Handle(buffer, lines)
|
||||
function! ale_linters#verilog#verilator#Handle(buffer, lines) abort
|
||||
" Look for lines like the following.
|
||||
"
|
||||
" %Error: addr_gen.v:3: syntax error, unexpected IDENTIFIER
|
||||
|
@ -1,6 +1,6 @@
|
||||
" Author: KabbAmine <amine.kabb@gmail.com>
|
||||
|
||||
function! ale_linters#yaml#yamllint#Handle(buffer, lines)
|
||||
function! ale_linters#yaml#yamllint#Handle(buffer, lines) abort
|
||||
" Matches patterns line the following:
|
||||
" something.yaml:1:1: [warning] missing document start "---" (document-start)
|
||||
" something.yml:2:1: [error] syntax error: expected the node content, but found '<stream end>'
|
||||
|
@ -4,11 +4,11 @@
|
||||
" Return 1 if there is a buffer with buftype == 'quickfix' in bufffer list
|
||||
function! ale#list#IsQuickfixOpen() abort
|
||||
for l:buf in range(1, bufnr('$'))
|
||||
if getbufvar(l:buf, '&buftype') ==# 'quickfix'
|
||||
if getbufvar(l:buf, '&buftype') ==# 'quickfix'
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
return 0
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function! ale#list#SetLists(loclist) abort
|
||||
|
83
custom-checks
Executable file
83
custom-checks
Executable file
@ -0,0 +1,83 @@
|
||||
#!/bin/bash -eu
|
||||
|
||||
# This Bash script implements custom sanity checks for scripts beyond what
|
||||
# Vint covers, which are easy to check with regex.
|
||||
|
||||
# A flag for automatically fixing some errors.
|
||||
FIX_ERRORS=0
|
||||
RETURN_CODE=0
|
||||
|
||||
function print_help() {
|
||||
echo "Usage: ./custom-checks [--fix] [DIRECTORY]" 1>&2
|
||||
echo 1>&2
|
||||
echo " -h, --help Print this help text" 1>&2
|
||||
echo " --fix Automatically fix some errors" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
while [ $# -ne 0 ]; do
|
||||
case $1 in
|
||||
-h) ;& --help)
|
||||
print_help
|
||||
;;
|
||||
--fix)
|
||||
FIX_ERRORS=1
|
||||
shift
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-?*)
|
||||
echo "Invalid argument: $1" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ $# -eq 0 ] || [ -z "$1" ]; then
|
||||
print_help
|
||||
fi
|
||||
|
||||
# Called to output an error.
|
||||
# If called at least one, the return code for this script will be 1.
|
||||
output_error() {
|
||||
echo "$FILENAME:$LINE_NUMBER $1"
|
||||
RETURN_CODE=1
|
||||
}
|
||||
|
||||
# This function is called for each line in each file to check syntax.
|
||||
check_line() {
|
||||
line="$1"
|
||||
|
||||
if [[ "$line" =~ ^function ]]; then
|
||||
if ! [[ "$line" =~ abort$ ]]; then
|
||||
if ((FIX_ERRORS)); then
|
||||
# Use sed to add the 'abort' flag
|
||||
sed -i "${LINE_NUMBER}s/$/ abort/" "$FILENAME"
|
||||
else
|
||||
output_error 'Function without abort keyword (See :help except-compat)'
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$line" =~ ' '+$ ]]; then
|
||||
output_error 'Trailing whitespace'
|
||||
fi
|
||||
}
|
||||
|
||||
# Loop through all of the vim files and keep track of the file line numbers.
|
||||
for FILENAME in $(find "$1" -name '*.vim'); do
|
||||
LINE_NUMBER=0
|
||||
|
||||
while read; do
|
||||
LINE_NUMBER=$(expr $LINE_NUMBER + 1)
|
||||
|
||||
check_line "$REPLY"
|
||||
done < "$FILENAME"
|
||||
done
|
||||
|
||||
exit $RETURN_CODE
|
@ -79,7 +79,7 @@ endif
|
||||
let g:ale_set_loclist = get(g:, 'ale_set_loclist', 1)
|
||||
let g:ale_set_quickfix = get(g:, 'ale_set_quickfix', 0)
|
||||
|
||||
" This flag dictates if ale open the configured loclist
|
||||
" This flag dictates if ale open the configured loclist
|
||||
let g:ale_open_list = get(g:, 'ale_open_list', 0)
|
||||
|
||||
" This flag dictates if ale keeps open loclist even if there is no error in loclist
|
||||
@ -154,10 +154,10 @@ augroup END
|
||||
|
||||
" Backwards Compatibility
|
||||
|
||||
function! ALELint(delay)
|
||||
function! ALELint(delay) abort
|
||||
call ale#Queue(a:delay)
|
||||
endfunction
|
||||
|
||||
function! ALEGetStatusLine()
|
||||
function! ALEGetStatusLine() abort
|
||||
return ale#statusline#Status()
|
||||
endfunction
|
||||
|
Loading…
Reference in New Issue
Block a user