mirror of https://github.com/dense-analysis/ale
parent
02c8793c53
commit
844354cfed
|
@ -57,6 +57,11 @@ let s:default_registry = {
|
|||
\ 'suggested_filetypes': [],
|
||||
\ 'description': 'Remove all blank lines at the end of a file.',
|
||||
\ },
|
||||
\ 'trim_whitespace': {
|
||||
\ 'function': 'ale#fixers#generic#TrimWhitespace',
|
||||
\ 'suggested_filetypes': [],
|
||||
\ 'description': 'Remove all trailing whitespace characters at the end of every line.',
|
||||
\ },
|
||||
\ 'yapf': {
|
||||
\ 'function': 'ale#fixers#yapf#Fix',
|
||||
\ 'suggested_filetypes': ['python'],
|
||||
|
|
|
@ -10,3 +10,16 @@ function! ale#fixers#generic#RemoveTrailingBlankLines(buffer, lines) abort
|
|||
|
||||
return a:lines[:l:end_index]
|
||||
endfunction
|
||||
|
||||
" Remove all whitespaces at the end of lines
|
||||
function! ale#fixers#generic#TrimWhitespace(buffer, lines) abort
|
||||
let l:index = 0
|
||||
let l:lines_new = range(len(a:lines))
|
||||
|
||||
for l:line in a:lines
|
||||
let l:lines_new[l:index] = substitute(l:line, '\s\+$', '', 'g')
|
||||
let l:index = l:index + 1
|
||||
endfor
|
||||
|
||||
return l:lines_new
|
||||
endfunction
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
Before:
|
||||
call ale#test#SetDirectory('/testplugin/test/fixers')
|
||||
|
||||
After:
|
||||
call ale#test#RestoreDirectory()
|
||||
|
||||
Execute(Should delete all whitespace at the end of different lines):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ 'def foo():',
|
||||
\ ' some_variable = this_is_a_longer_function(',
|
||||
\ 'first_argument,',
|
||||
\ ' second_argument,',
|
||||
\ ' third_with_function_call(',
|
||||
\ 'foo,',
|
||||
\ ' 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,',
|
||||
\ '))',
|
||||
\ ])
|
Loading…
Reference in New Issue