dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.55k stars 1.43k forks source link

Is there anyway to use global linter for all filetype for simple warning like trailing space? #748

Closed wizzup closed 7 years ago

wizzup commented 7 years ago

vim-airline is warned about trailing space but only after the file is saved and it only show the first one.

2017-07-10-204659_249x50_scrot

I am using set list in my config but it easy to miss, when code is big.

Is there anyway to have these kind of linters that can be use on any filetype.

w0rp commented 7 years ago

I personally use a function which automatically removes trailing spaces, and I draw tab characters.

set listchars=tab:>~
set list

fun! TrimWhitespace()
    let line_no = line('.')
    let col_no = col('.')

    %s/\s*$//

    call cursor(line_no, col_no)
endf

" Do auto whitespace trimming.
autocmd FileWritePre * :call TrimWhitespace()
autocmd FileAppendPre * :call TrimWhitespace()
autocmd FilterWritePre * :call TrimWhitespace()
autocmd BufWritePre * :call TrimWhitespace()

I wrote those lines a long, long time ago, and I've been using that for ages.

w0rp commented 7 years ago

A mix of tabs and spaces isn't necessarily an error for every type of file. It might be required for some formats.

wizzup commented 7 years ago

autocommand is a good solution.