Compare commits

...
This repository has been archived on 2024-07-19. You can view files and clone it, but cannot push or open issues or pull requests.

9 commits

14 changed files with 159 additions and 27 deletions

View file

@ -4,6 +4,7 @@
call ale#Set('cpp_flawfinder_executable', 'flawfinder')
call ale#Set('cpp_flawfinder_options', '')
call ale#Set('cpp_flawfinder_minlevel', 1)
call ale#Set('c_flawfinder_error_severity', 6)
function! ale_linters#cpp#flawfinder#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'cpp_flawfinder_executable')

View file

@ -24,7 +24,7 @@ function! ale_linters#python#pylint#Handle(buffer, lines) abort
" Matches patterns like the following:
"
" test.py:4:4: W0101 (unreachable) Unreachable code
let l:pattern = '\v^[^:]+:(\d+):(\d+): ([[:alnum:]]+) \(([^(]*)\) (.*)$'
let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):(\d+): ([[:alnum:]]+) \(([^(]*)\) (.*)$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)

View file

@ -33,6 +33,10 @@ endfunction
" Return 1 if a file is too large for ALE to handle.
function! ale#FileTooLarge() abort
if !exists('g:ale_maximum_file_size')
return 0
endif
let l:max = ale#Var(bufnr(''), 'maximum_file_size')
return l:max > 0 ? (line2byte(line('$') + 1) > l:max) : 0
@ -46,13 +50,18 @@ function! ale#ShouldDoNothing(buffer) abort
" The checks are split into separate if statements to make it possible to
" profile each check individually with Vim's profiling tools.
" Do nothing if ALE is disabled.
if !getbufvar(a:buffer, 'ale_enabled', get(g:, 'ale_enabled', 0))
return 1
endif
" Don't perform any checks when newer NeoVim versions are exiting.
if get(v:, 'exiting', v:null) isnot v:null
return 1
endif
" Do nothing for blacklisted files
if index(g:ale_filetype_blacklist, getbufvar(a:buffer, '&filetype')) >= 0
if index(get(g:, 'ale_filetype_blacklist', []), getbufvar(a:buffer, '&filetype')) >= 0
return 1
endif
@ -72,11 +81,6 @@ function! ale#ShouldDoNothing(buffer) abort
return 1
endif
" Do nothing if ALE is disabled.
if !ale#Var(a:buffer, 'enabled')
return 1
endif
" Do nothing if the file is too large.
if ale#FileTooLarge()
return 1

View file

@ -1,4 +1,4 @@
" Author: eborden <evan@evan-borden.com>
" Author: eborden <evan@evan-borden.com>, ifyouseewendy <ifyouseewendy@gmail.com>, aspidiets <emarshall85@gmail.com>
" Description: Integration of brittany with ALE.
call ale#Set('haskell_brittany_executable', 'brittany')
@ -8,6 +8,7 @@ function! ale#fixers#brittany#Fix(buffer) abort
return {
\ 'command': ale#Escape(l:executable)
\ . ' --write-mode inplace'
\ . ' %t',
\ 'read_temporary_file': 1,
\}

View file

@ -13,23 +13,14 @@ function! ale#handlers#textlint#GetExecutable(buffer) abort
endfunction
function! ale#handlers#textlint#GetCommand(buffer) abort
let l:cmd_path = ale#path#FindNearestFile(a:buffer, '.textlintrc')
let l:executable = ale#handlers#textlint#GetExecutable(a:buffer)
let l:options = ale#Var(a:buffer, 'textlint_options')
if !empty(l:cmd_path)
return 'textlint'
\ . ' -c '
\ . l:cmd_path
return ale#node#Executable(a:buffer, l:executable)
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' -f json %t'
endif
return 'textlint'
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' -f json %t'
\ . ' -f json --stdin --stdin-filename %s'
endfunction
function! ale#handlers#textlint#HandleTextlintOutput(buffer, lines) abort
let l:res = get(ale#util#FuzzyJSONDecode(a:lines, []), 0, {'messages': []})
let l:output = []

View file

@ -208,7 +208,7 @@ function! ale#job#PrepareCommand(buffer, command) abort
return 'cmd /s/c "' . l:command . '"'
endif
if &shell =~? 'fish$'
if &shell =~? 'fish$\|pwsh$'
return ['/bin/sh', '-c', l:command]
endif

View file

@ -0,0 +1,85 @@
" Author: januswel, w0rp
Before:
Save g:ale_textlint_executable
Save g:ale_textlint_use_global
Save g:ale_textlint_options
unlet! g:ale_textlint_executable
unlet! b:ale_textlint_executable
unlet! g:ale_textlint_use_global
unlet! b:ale_textlint_use_global
unlet! g:ale_textlint_options
unlet! b:ale_textlint_options
runtime autoload/ale/handlers/textlint.vim
call ale#test#SetDirectory('/testplugin/test/command_callback')
After:
Restore
unlet! b:command_tail
unlet! b:ale_textlint_executable
unlet! b:ale_textlint_use_global
unlet! b:ale_textlint_options
call ale#test#RestoreDirectory()
call ale#linter#Reset()
Execute(The executable should be configurable):
AssertEqual 'textlint', ale#handlers#textlint#GetExecutable(bufnr(''))
let b:ale_textlint_executable = 'foobar'
AssertEqual 'foobar', ale#handlers#textlint#GetExecutable(bufnr(''))
Execute(The executable should be used in the command):
AssertEqual
\ ale#Escape('textlint') . ' -f json --stdin --stdin-filename %s',
\ ale#handlers#textlint#GetCommand(bufnr(''))
let b:ale_textlint_executable = 'foobar'
AssertEqual
\ ale#Escape('foobar') . ' -f json --stdin --stdin-filename %s',
\ ale#handlers#textlint#GetCommand(bufnr(''))
\
Execute(The options should be configurable):
let b:ale_textlint_options = '--something'
AssertEqual
\ ale#Escape('textlint') . ' --something -f json --stdin --stdin-filename %s',
\ ale#handlers#textlint#GetCommand(bufnr(''))
Execute(The local executable from .bin should be used if available):
call ale#test#SetFilename('textlint_paths/with_bin_path/foo.txt')
AssertEqual
\ ale#path#Simplify(g:dir . '/textlint_paths/with_bin_path/node_modules/.bin/textlint'),
\ ale#handlers#textlint#GetExecutable(bufnr(''))
AssertEqual
\ ale#Escape(ale#path#Simplify(g:dir . '/textlint_paths/with_bin_path/node_modules/.bin/textlint'))
\ . ' -f json --stdin --stdin-filename %s',
\ ale#handlers#textlint#GetCommand(bufnr(''))
Execute(The local executable from textlint/bin should be used if available):
call ale#test#SetFilename('textlint_paths/with_textlint_bin_path/foo.txt')
AssertEqual
\ ale#path#Simplify(g:dir . '/textlint_paths/with_textlint_bin_path/node_modules/textlint/bin/textlint.js'),
\ ale#handlers#textlint#GetExecutable(bufnr(''))
if has('win32')
AssertEqual
\ ale#Escape('node.exe') . ' ' . ale#Escape(ale#path#Simplify(g:dir . '/textlint_paths/with_textlint_bin_path/node_modules/textlint/bin/textlint.js'))
\ . ' -f json --stdin --stdin-filename %s',
\ ale#handlers#textlint#GetCommand(bufnr(''))
else
AssertEqual
\ ale#Escape(ale#path#Simplify(g:dir . '/textlint_paths/with_textlint_bin_path/node_modules/textlint/bin/textlint.js'))
\ . ' -f json --stdin --stdin-filename %s',
\ ale#handlers#textlint#GetCommand(bufnr(''))
endif

View file

@ -18,6 +18,7 @@ Execute(The brittany callback should return the correct default values):
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('xxxinvalid')
\ . ' --write-mode inplace'
\ . ' %t',
\ },
\ ale#fixers#brittany#Fix(bufnr(''))

View file

@ -94,3 +94,22 @@ Execute(Ignoring trailing whitespace messages should work):
\ '------------------------------------------------------------------',
\ 'Your code has been rated at 0.00/10 (previous run: 2.50/10, -2.50)',
\ ])
Execute(The pylint handler should parse Windows filenames):
AssertEqual
\ [
\ {
\ 'lnum': 13,
\ 'col': 6,
\ 'text': 'Undefined variable ''x''',
\ 'code': 'undefined-variable',
\ 'type': 'E',
\ },
\ ],
\ ale_linters#python#pylint#Handle(bufnr(''), [
\ '************* Module test',
\ 'D:\acm\github\vim\tools\test.py:13:5: E0602 (undefined-variable) Undefined variable ''x''',
\ '',
\ '------------------------------------------------------------------',
\ 'Your code has been rated at 5.83/10 (previous run: 5.83/10, +0.00)',
\ ])

View file

@ -1,11 +1,13 @@
Before:
Save g:ale_filetype_blacklist
runtime autoload/ale.vim
" Delete some variable which should be defined.
unlet! g:ale_filetype_blacklist
" Replace one of the key ALE functions and make it throw.
function! ale#FileTooLarge() abort
throw 'broken'
endfunction
After:
Restore
runtime autoload/ale.vim
call ale#ResetErrorDelays()

View file

@ -22,6 +22,23 @@ Execute(sh should be used when the shell is fish):
AssertEqual ['/bin/sh', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), 'foobar')
endif
Execute(sh should be used when the shell is powershell):
if !has('win32')
" Set something else, so we will replace that too.
let &shellcmdflag = '-f'
let &shell = 'pwsh'
AssertEqual ['/bin/sh', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), 'foobar')
let &shell = '/usr/bin/pwsh'
AssertEqual ['/bin/sh', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), 'foobar')
let &shell = '/usr/local/bin/pwsh'
AssertEqual ['/bin/sh', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), 'foobar')
endif
Execute(Other shells should be used when set):
if !has('win32')
let &shell = '/bin/bash'

View file

@ -1,4 +1,7 @@
Before:
Save g:ale_filetype_blacklist
Save g:ale_maximum_file_size
Save g:ale_enabled
Save &l:statusline
call ale#test#SetDirectory('/testplugin/test')
@ -12,6 +15,8 @@ Before:
endif
After:
Restore
call ale#test#RestoreDirectory()
if b:funky_command_created
@ -21,8 +26,6 @@ After:
unlet! b:funky_command_created
Restore
Execute(ALE shouldn't do much of anything for ctrlp-funky buffers):
Assert !ale#ShouldDoNothing(bufnr('')), 'The preliminary check failed'
@ -39,3 +42,11 @@ Execute(ALE shouldn't try to check buffers with '.' as the filename):
silent! noautocmd file .
Assert ale#ShouldDoNothing(bufnr(''))
Execute(The DoNothing check should work if the ALE globals aren't defined):
unlet! g:ale_filetype_blacklist
unlet! g:ale_maximum_file_size
unlet! g:ale_enabled
" This shouldn't throw exceptions.
call ale#ShouldDoNothing(bufnr(''))