summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorCarlos Ramos <carakan@gmail.com>2017-10-12 04:27:24 -0400
committerw0rp <w0rp@users.noreply.github.com>2017-10-12 09:27:24 +0100
commit844354cfed8179181cf69ff8a38937ec4245abbb (patch)
tree6539ef7a79b5b8df7783f5fd178e847dc445efaa /autoload
parent02c8793c533dccf4b2f13d998135c9b8d7a944fd (diff)
downloadale-844354cfed8179181cf69ff8a38937ec4245abbb.zip
Add new fixer: TrimWhitespace (#991)
add a new fixer: trim_whitespace
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/generic.vim13
2 files changed, 18 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 9569d215..93c0860d 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -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'],
diff --git a/autoload/ale/fixers/generic.vim b/autoload/ale/fixers/generic.vim
index fdc8eab1..cb8865b4 100644
--- a/autoload/ale/fixers/generic.vim
+++ b/autoload/ale/fixers/generic.vim
@@ -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