diff options
-rw-r--r-- | ale_linters/graphql/gqlint.vim | 8 | ||||
-rw-r--r-- | ale_linters/tex/lacheck.vim | 14 | ||||
-rw-r--r-- | autoload/ale/fix.vim | 4 | ||||
-rw-r--r-- | autoload/ale/fixers/generic.vim | 4 | ||||
-rw-r--r-- | autoload/ale/fixers/generic_python.vim | 4 | ||||
-rw-r--r-- | autoload/ale/fixers/help.vim | 2 | ||||
-rw-r--r-- | autoload/ale/fixers/standard.vim | 2 | ||||
-rw-r--r-- | doc/ale.txt | 12 | ||||
-rw-r--r-- | test/command_callback/test_graphql_gqlint_command_callbacks.vader | 11 | ||||
-rw-r--r-- | test/command_callback/test_tex_lacheck_command_callback.vader | 13 | ||||
-rw-r--r-- | test/command_callback/tex_paths/sample1.tex | 0 | ||||
-rw-r--r-- | test/command_callback/tex_paths/sample2.tex | 0 | ||||
-rw-r--r-- | test/fix/test_ale_fix.vader | 18 | ||||
-rw-r--r-- | test/fixers/test_break_up_long_lines_python_fixer.vader | 4 | ||||
-rw-r--r-- | test/fixers/test_standard_fixer_callback.vader | 14 | ||||
-rw-r--r-- | test/fixers/test_trim_whitespace.vader | 18 | ||||
-rw-r--r-- | test/handler/test_lacheck_handler.vader | 36 | ||||
-rw-r--r-- | test/test_no_linting_on_write_quit.vader | 2 |
18 files changed, 129 insertions, 37 deletions
diff --git a/ale_linters/graphql/gqlint.vim b/ale_linters/graphql/gqlint.vim index 882cc697..e45bf4c8 100644 --- a/ale_linters/graphql/gqlint.vim +++ b/ale_linters/graphql/gqlint.vim @@ -1,9 +1,15 @@ " Author: Michiel Westerbeek <happylinks@gmail.com> " Description: Linter for GraphQL Schemas +function! ale_linters#graphql#gqlint#GetCommand(buffer) abort + return ale#path#BufferCdString(a:buffer) + \ . 'gqlint' + \ . ' --reporter=simple %t' +endfunction + call ale#linter#Define('graphql', { \ 'name': 'gqlint', \ 'executable': 'gqlint', -\ 'command': 'gqlint --reporter=simple %t', +\ 'command_callback': 'ale_linters#graphql#gqlint#GetCommand', \ 'callback': 'ale#handlers#unix#HandleAsWarning', \}) diff --git a/ale_linters/tex/lacheck.vim b/ale_linters/tex/lacheck.vim index 5e5a94f1..ee09fb41 100644 --- a/ale_linters/tex/lacheck.vim +++ b/ale_linters/tex/lacheck.vim @@ -8,20 +8,26 @@ function! ale_linters#tex#lacheck#Handle(buffer, lines) abort " " "book.tex", line 37: possible unwanted space at "{" " "book.tex", line 38: missing `\ ' after "etc." - let l:pattern = '^".\+", line \(\d\+\): \(.\+\)$' + let l:pattern = '^"\(.\+\)", line \(\d\+\): \(.\+\)$' let l:output = [] for l:match in ale#util#GetMatches(a:lines, l:pattern) " lacheck follows `\input{}` commands. If the cwd is not the same as the " file in the buffer then it will fail to find the inputed items. We do not " want warnings from those items anyway - if !empty(matchstr(l:match[2], '^Could not open ".\+"$')) + if !empty(matchstr(l:match[3], '^Could not open ".\+"$')) + continue + endif + + " lacheck follows `\input{}` commands. We are only interested in + " reporting errors for the current buffer only. + if empty(matchstr(fnamemodify(l:match[1], ':t'), fnamemodify(bufname(a:buffer), ':t'))) continue endif call add(l:output, { - \ 'lnum': l:match[1] + 0, - \ 'text': l:match[2], + \ 'lnum': l:match[2] + 0, + \ 'text': l:match[3], \ 'type': 'W', \}) endfor diff --git a/autoload/ale/fix.vim b/autoload/ale/fix.vim index 03652ecf..423e85be 100644 --- a/autoload/ale/fix.vim +++ b/autoload/ale/fix.vim @@ -315,10 +315,10 @@ function! s:RunFixer(options) abort \ ? call(l:Function, [l:buffer, a:options.output]) \ : call(l:Function, [l:buffer, a:options.output, copy(l:input)]) else - " Chained commands accept (buffer, [input]) + " Chained commands accept (buffer, [done, input]) let l:result = ale#util#FunctionArgCount(l:Function) == 1 \ ? call(l:Function, [l:buffer]) - \ : call(l:Function, [l:buffer, copy(l:input)]) + \ : call(l:Function, [l:buffer, v:null, copy(l:input)]) endif if type(l:result) is v:t_number && l:result == 0 diff --git a/autoload/ale/fixers/generic.vim b/autoload/ale/fixers/generic.vim index cb8865b4..1d88553e 100644 --- a/autoload/ale/fixers/generic.vim +++ b/autoload/ale/fixers/generic.vim @@ -1,7 +1,7 @@ " Author: w0rp <devw0rp@gmail.com> " Description: Generic functions for fixing files with. -function! ale#fixers#generic#RemoveTrailingBlankLines(buffer, lines) abort +function! ale#fixers#generic#RemoveTrailingBlankLines(buffer, done, lines) abort let l:end_index = len(a:lines) - 1 while l:end_index > 0 && empty(a:lines[l:end_index]) @@ -12,7 +12,7 @@ function! ale#fixers#generic#RemoveTrailingBlankLines(buffer, lines) abort endfunction " Remove all whitespaces at the end of lines -function! ale#fixers#generic#TrimWhitespace(buffer, lines) abort +function! ale#fixers#generic#TrimWhitespace(buffer, done, lines) abort let l:index = 0 let l:lines_new = range(len(a:lines)) diff --git a/autoload/ale/fixers/generic_python.vim b/autoload/ale/fixers/generic_python.vim index d55a23c3..9a929b96 100644 --- a/autoload/ale/fixers/generic_python.vim +++ b/autoload/ale/fixers/generic_python.vim @@ -2,7 +2,7 @@ " Description: Generic fixer functions for Python. " Add blank lines before control statements. -function! ale#fixers#generic_python#AddLinesBeforeControlStatements(buffer, lines) abort +function! ale#fixers#generic_python#AddLinesBeforeControlStatements(buffer, done, lines) abort let l:new_lines = [] let l:last_indent_size = 0 let l:last_line_is_blank = 0 @@ -41,7 +41,7 @@ endfunction " This function breaks up long lines so that autopep8 or other tools can " fix the badly-indented code which is produced as a result. -function! ale#fixers#generic_python#BreakUpLongLines(buffer, lines) abort +function! ale#fixers#generic_python#BreakUpLongLines(buffer, done, lines) abort " Default to a maximum line length of 79 let l:max_line_length = 79 let l:conf = ale#path#FindNearestFile(a:buffer, 'setup.cfg') diff --git a/autoload/ale/fixers/help.vim b/autoload/ale/fixers/help.vim index b20740fe..9fb0717b 100644 --- a/autoload/ale/fixers/help.vim +++ b/autoload/ale/fixers/help.vim @@ -1,7 +1,7 @@ " Author: w0rp <devw0rp@gmail.com> " Description: Generic fixer functions for Vim help documents. -function! ale#fixers#help#AlignTags(buffer, lines) abort +function! ale#fixers#help#AlignTags(buffer, done, lines) abort let l:new_lines = [] for l:line in a:lines diff --git a/autoload/ale/fixers/standard.vim b/autoload/ale/fixers/standard.vim index 2b1f6f92..77712d40 100644 --- a/autoload/ale/fixers/standard.vim +++ b/autoload/ale/fixers/standard.vim @@ -14,9 +14,11 @@ endfunction function! ale#fixers#standard#Fix(buffer) abort let l:executable = ale#fixers#standard#GetExecutable(a:buffer) + let l:options = ale#Var(a:buffer, 'javascript_standard_options') return { \ 'command': ale#node#Executable(a:buffer, l:executable) + \ . (!empty(l:options) ? ' ' . l:options : '') \ . ' --fix %t', \ 'read_temporary_file': 1, \} diff --git a/doc/ale.txt b/doc/ale.txt index e5951745..99aa8f01 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -675,10 +675,14 @@ The values for `g:ale_fixers` can be a list of |String|, |Funcref|, or for a function set in the ALE fixer registry. Each function for fixing errors must accept either one argument `(buffer)` or -two arguments `(buffer, lines)`, representing the buffer being fixed and the -lines to fix. The functions must return either `0`, for changing nothing, a -|List| for new lines to set, or a |Dictionary| for describing a command to be -run in the background. +three arguments `(buffer, done, lines)`, representing the buffer being fixed, +a function to call with results, and the lines to fix. The functions must +return either `0`, for changing nothing, a |List| for new lines to set, a +|Dictionary| for describing a command to be run in the background, or `v:true` +for indicating that results will be provided asynchronously via the `done` +callback. + +NOTE: The `done` function has not been implemented yet. Functions receiving a variable number of arguments will not receive the second argument `lines`. Functions should name two arguments if the `lines` argument diff --git a/test/command_callback/test_graphql_gqlint_command_callbacks.vader b/test/command_callback/test_graphql_gqlint_command_callbacks.vader new file mode 100644 index 00000000..0f4e9770 --- /dev/null +++ b/test/command_callback/test_graphql_gqlint_command_callbacks.vader @@ -0,0 +1,11 @@ +Before: + call ale#assert#SetUpLinterTest('graphql', 'gqlint') + +After: + call ale#assert#TearDownLinterTest() + +Execute(The linter should run from the directory of the file in the buffer): + AssertLinter 'gqlint', + \ ale#path#CdString(expand('%:p:h')) + \ . 'gqlint --reporter=simple' + \ . ' %t' diff --git a/test/command_callback/test_tex_lacheck_command_callback.vader b/test/command_callback/test_tex_lacheck_command_callback.vader new file mode 100644 index 00000000..b404cc78 --- /dev/null +++ b/test/command_callback/test_tex_lacheck_command_callback.vader @@ -0,0 +1,13 @@ +Before: + call ale#assert#SetUpLinterTest('tex', 'lacheck') + +After: + call ale#assert#TearDownLinterTest() + +Execute(Executable should default to lacheck): + AssertLinter 'lacheck', ale#Escape('lacheck') . ' %t' + +Execute(Should be able to set a custom executable): + let g:ale_tex_lacheck_executable = 'bin/foo' + + AssertLinter 'bin/foo' , ale#Escape('bin/foo') . ' %t' diff --git a/test/command_callback/tex_paths/sample1.tex b/test/command_callback/tex_paths/sample1.tex new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/tex_paths/sample1.tex diff --git a/test/command_callback/tex_paths/sample2.tex b/test/command_callback/tex_paths/sample2.tex new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/tex_paths/sample2.tex diff --git a/test/fix/test_ale_fix.vader b/test/fix/test_ale_fix.vader index 90407681..1b1891ce 100644 --- a/test/fix/test_ale_fix.vader +++ b/test/fix/test_ale_fix.vader @@ -33,21 +33,21 @@ Before: call ale#test#SetFilename('test.txt') call ale#linter#PreventLoading('testft') - function AddCarets(buffer, lines) abort + function AddCarets(buffer, done, lines) abort " map() is applied to the original lines here. " This way, we can ensure that defensive copies are made. return map(a:lines, '''^'' . v:val') endfunction - function AddDollars(buffer, lines) abort + function AddDollars(buffer, done, lines) abort return map(a:lines, '''$'' . v:val') endfunction - function DoNothing(buffer, lines) abort + function DoNothing(buffer, done, lines) abort return 0 endfunction - function CatLine(buffer, lines) abort + function CatLine(buffer, done, lines) abort return {'command': 'cat - <(echo d)'} endfunction @@ -55,11 +55,11 @@ Before: return {'command': 'cat - <(echo d)'} endfunction - function ReplaceWithTempFile(buffer, lines) abort + function ReplaceWithTempFile(buffer, done, lines) abort return {'command': 'echo x > %t', 'read_temporary_file': 1} endfunction - function RemoveLastLine(buffer, lines) abort + function RemoveLastLine(buffer, done, lines) abort return ['a', 'b'] endfunction @@ -122,11 +122,11 @@ Before: endfunction " echo will output a single blank line, and we should ingore it. - function! IgnoredEmptyOutput(buffer, output) + function! IgnoredEmptyOutput(buffer, done, output) return {'command': has('win32') ? 'echo(' : 'echo'} endfunction - function! EchoLineNoPipe(buffer, output) + function! EchoLineNoPipe(buffer, done, output) return {'command': 'echo new line', 'read_buffer': 0} endfunction @@ -399,7 +399,7 @@ Execute(ALEFix should accept lambdas): " to make the test pass. call setline(1, ['a', 'b', 'c', 'd']) else - let g:ale_fixers.testft = [{buffer, lines -> lines + ['d']}] + let g:ale_fixers.testft = [{buffer, done, lines -> lines + ['d']}] ALEFix endif diff --git a/test/fixers/test_break_up_long_lines_python_fixer.vader b/test/fixers/test_break_up_long_lines_python_fixer.vader index 5fd991f0..847d3358 100644 --- a/test/fixers/test_break_up_long_lines_python_fixer.vader +++ b/test/fixers/test_break_up_long_lines_python_fixer.vader @@ -16,7 +16,7 @@ Execute(Long lines with basic function calls should be broken up correctly): \ ' bar,', \ '))', \ ], - \ ale#fixers#generic_python#BreakUpLongLines(bufnr(''), [ + \ ale#fixers#generic_python#BreakUpLongLines(bufnr(''), v:null, [ \ 'def foo():', \ ' some_variable = this_is_a_longer_function(first_argument, second_argument, third_with_function_call(foo, bar))', \ ]) @@ -33,7 +33,7 @@ Execute(Longer lines should be permitted if a configuration file allows it): \ ' a_third_long_word,', \ ')' \ ], - \ ale#fixers#generic_python#BreakUpLongLines(bufnr(''), [ + \ ale#fixers#generic_python#BreakUpLongLines(bufnr(''), v:null, [ \ 'x = this_line_is_between_79_and_90_characters(first, second, third, fourth, fifth)', \ 'y = this_line_is_longer_than_90_characters(much_longer_word, another_longer_word, a_third_long_word)', \ ]) diff --git a/test/fixers/test_standard_fixer_callback.vader b/test/fixers/test_standard_fixer_callback.vader index 38f2d54a..db9f20f6 100644 --- a/test/fixers/test_standard_fixer_callback.vader +++ b/test/fixers/test_standard_fixer_callback.vader @@ -1,6 +1,9 @@ Before: call ale#test#SetDirectory('/testplugin/test/fixers') + unlet! b:ale_javascript_standard_executable + unlet! b:ale_javascript_standard_options + After: call ale#test#RestoreDirectory() @@ -15,3 +18,14 @@ Execute(The executable path should be correct): \ . ' --fix %t', \ }, \ ale#fixers#standard#Fix(bufnr('')) + +Execute(Custom options should be supported): + let b:ale_javascript_standard_use_global = 1 + let b:ale_javascript_standard_options = '--foo-bar' + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape('standard') . ' --foo-bar --fix %t', + \ }, + \ ale#fixers#standard#Fix(bufnr('')) diff --git a/test/fixers/test_trim_whitespace.vader b/test/fixers/test_trim_whitespace.vader index 2ffbcb04..10070374 100644 --- a/test/fixers/test_trim_whitespace.vader +++ b/test/fixers/test_trim_whitespace.vader @@ -16,13 +16,13 @@ Execute(Should delete all whitespace at the end of different lines): \ ' bar,', \ '))', \ ], - \ ale#fixers#generic#TrimWhitespace(bufnr(''), [ - \ 'def foo():', - \ ' some_variable = this_is_a_longer_function(', - \ 'first_argument,', - \ ' second_argument,', - \ ' third_with_function_call(', - \ 'foo,', - \ ' bar,', - \ '))', + \ ale#fixers#generic#TrimWhitespace(bufnr(''), v:null, [ + \ 'def foo():', + \ ' some_variable = this_is_a_longer_function(', + \ 'first_argument,', + \ ' second_argument,', + \ ' third_with_function_call(', + \ 'foo,', + \ ' bar,', + \ '))', \ ]) diff --git a/test/handler/test_lacheck_handler.vader b/test/handler/test_lacheck_handler.vader new file mode 100644 index 00000000..0bcc3be8 --- /dev/null +++ b/test/handler/test_lacheck_handler.vader @@ -0,0 +1,36 @@ +Before: + runtime ale_linters/tex/lacheck.vim + call ale#test#SetDirectory('/testplugin/test') + +After: + call ale#linter#Reset() + call ale#test#RestoreDirectory() + +Execute(The lacheck handler should parse lines correctly): + + call ale#test#SetFilename('command_callback/tex_paths/sample1.tex') + + AssertEqual + \ [ + \ { + \ 'lnum': 1, + \ 'type': 'W', + \ 'text': 'perhaps you should insert a `~'' before "\ref"' + \ } + \ ], + \ ale_linters#tex#lacheck#Handle(bufnr(''), [ + \ "** sample1:", + \ "\"sample1.tex\", line 1: perhaps you should insert a `~' before \"\\ref\"" + \ ]) + +Execute(The lacheck handler should ignore errors from input files): + + call ale#test#SetFilename('ale_test.tex') + + AssertEqual + \ [ + \ ], + \ ale_linters#tex#lacheck#Handle(255, [ + \ "** ale_input:", + \ "\"ale_input.tex\", line 1: perhaps you should insert a `~' before \"\\ref\"" + \ ]) diff --git a/test/test_no_linting_on_write_quit.vader b/test/test_no_linting_on_write_quit.vader index 12ef38ed..75de06a4 100644 --- a/test/test_no_linting_on_write_quit.vader +++ b/test/test_no_linting_on_write_quit.vader @@ -23,7 +23,7 @@ Before: return [{'lnum': 1, 'col': 1, 'text': 'xxx'}] endfunction - function AddLine(buffer, lines) abort + function AddLine(buffer, done, lines) abort return a:lines + ['x'] endfunction |