Fix #577 Add an option preventing linting of large files

This commit is contained in:
w0rp 2017-05-26 21:21:15 +01:00
parent 28a62aab28
commit 00d3141962
5 changed files with 81 additions and 44 deletions

View File

@ -6,6 +6,13 @@ let s:lint_timer = -1
let s:queued_buffer_number = -1 let s:queued_buffer_number = -1
let s:should_lint_file_for_buffer = {} let s:should_lint_file_for_buffer = {}
" Return 1 if a file is too large for ALE to handle.
function! ale#FileTooLarge() abort
let l:max = ale#Var(bufnr(''), 'maximum_file_size')
return l:max > 0 ? (line2byte(line('$') + 1) > l:max) : 0
endfunction
" A function for checking various conditions whereby ALE just shouldn't " A function for checking various conditions whereby ALE just shouldn't
" attempt to do anything, say if particular buffer types are open in Vim. " attempt to do anything, say if particular buffer types are open in Vim.
function! ale#ShouldDoNothing() abort function! ale#ShouldDoNothing() abort
@ -14,6 +21,8 @@ function! ale#ShouldDoNothing() abort
return index(g:ale_filetype_blacklist, &filetype) >= 0 return index(g:ale_filetype_blacklist, &filetype) >= 0
\ || (exists('*getcmdwintype') && !empty(getcmdwintype())) \ || (exists('*getcmdwintype') && !empty(getcmdwintype()))
\ || ale#util#InSandbox() \ || ale#util#InSandbox()
\ || !ale#Var(bufnr(''), 'enabled')
\ || ale#FileTooLarge()
endfunction endfunction
" (delay, [linting_flag]) " (delay, [linting_flag])
@ -29,11 +38,6 @@ function! ale#Queue(delay, ...) abort
throw "linting_flag must be either '' or 'lint_file'" throw "linting_flag must be either '' or 'lint_file'"
endif endif
" Stop here if ALE is disabled.
if !ale#Var(bufnr(''), 'enabled')
return
endif
if ale#ShouldDoNothing() if ale#ShouldDoNothing()
return return
endif endif

View File

@ -66,11 +66,6 @@ function! s:StopCursorTimer() abort
endfunction endfunction
function! ale#cursor#EchoCursorWarning(...) abort function! ale#cursor#EchoCursorWarning(...) abort
" Stop here if ALE is disabled.
if !ale#Var(bufnr(''), 'enabled')
return
endif
if ale#ShouldDoNothing() if ale#ShouldDoNothing()
return return
endif endif
@ -98,11 +93,6 @@ let s:cursor_timer = -1
let s:last_pos = [0, 0, 0] let s:last_pos = [0, 0, 0]
function! ale#cursor#EchoCursorWarningWithDelay() abort function! ale#cursor#EchoCursorWarningWithDelay() abort
" Stop here if ALE is disabled.
if !ale#Var(bufnr(''), 'enabled')
return
endif
if ale#ShouldDoNothing() if ale#ShouldDoNothing()
return return
endif endif
@ -122,6 +112,10 @@ function! ale#cursor#EchoCursorWarningWithDelay() abort
endfunction endfunction
function! ale#cursor#ShowCursorDetail() abort function! ale#cursor#ShowCursorDetail() abort
if ale#ShouldDoNothing()
return
endif
" Only echo the warnings in normal mode, otherwise we will get problems. " Only echo the warnings in normal mode, otherwise we will get problems.
if mode() !=# 'n' if mode() !=# 'n'
return return

View File

@ -514,6 +514,15 @@ g:ale_max_buffer_history_size *g:ale_max_buffer_history_size*
History can be disabled completely with |g:ale_history_enabled|. History can be disabled completely with |g:ale_history_enabled|.
g:ale_maximum_file_size *g:ale_maximum_file_size*
*b:ale_maximum_file_size*
Type: |Number|
Default: `0`
A maximum file size in bytes for ALE to check. If set to any positive
number, ALE will skip checking files larger than the given size.
g:ale_open_list *g:ale_open_list* g:ale_open_list *g:ale_open_list*
Type: |Number| Type: |Number|

View File

@ -167,6 +167,9 @@ let g:ale_history_log_output = get(g:, 'ale_history_log_output', 0)
call ale#Set('pattern_options', {}) call ale#Set('pattern_options', {})
call ale#Set('pattern_options_enabled', !empty(g:ale_pattern_options)) call ale#Set('pattern_options_enabled', !empty(g:ale_pattern_options))
" A maximum file size for checking for errors.
call ale#Set('maximum_file_size', 0)
function! ALEInitAuGroups() abort function! ALEInitAuGroups() abort
" This value used to be a Boolean as a Number, and is now a String. " This value used to be a Boolean as a Number, and is now a String.
let l:text_changed = '' . g:ale_lint_on_text_changed let l:text_changed = '' . g:ale_lint_on_text_changed

View File

@ -1,5 +1,27 @@
Before: Before:
Save g:ale_buffer_info, g:ale_enabled, b:ale_enabled Save g:ale_buffer_info
Save g:ale_enabled
Save b:ale_enabled
Save g:ale_maximum_file_size
Save b:ale_maximum_file_size
function! SetUpCursorData()
let g:ale_buffer_info = {
\ bufnr('%'): {
\ 'loclist': [
\ {
\ 'lnum': 2,
\ 'col': 10,
\ 'linter_name': 'testlinter',
\ 'type': 'W',
\ 'text': 'X'
\ },
\ ],
\ },
\}
call cursor(2, 16)
endfunction
function! TestCallback(buffer, output) function! TestCallback(buffer, output)
return [] return []
@ -29,6 +51,7 @@ After:
call ale#linter#Reset() call ale#linter#Reset()
delfunction TestCallback delfunction TestCallback
delfunction GetLastMessage delfunction GetLastMessage
delfunction SetUpCursorData
Given foobar (Some imaginary filetype): Given foobar (Some imaginary filetype):
foo foo
@ -43,6 +66,14 @@ Execute(Linting shouldn't happen when ALE is disabled globally):
AssertEqual {}, g:ale_buffer_info AssertEqual {}, g:ale_buffer_info
Execute(Linting shouldn't happen when the file is too large with a global options):
let g:ale_maximum_file_size = 12
let g:ale_buffer_info = {}
call ale#Queue(0)
AssertEqual {}, g:ale_buffer_info
Execute(Linting shouldn't happen when ALE is disabled locally): Execute(Linting shouldn't happen when ALE is disabled locally):
let b:ale_enabled = 0 let b:ale_enabled = 0
let g:ale_buffer_info = {} let g:ale_buffer_info = {}
@ -51,42 +82,38 @@ Execute(Linting shouldn't happen when ALE is disabled locally):
AssertEqual {}, g:ale_buffer_info AssertEqual {}, g:ale_buffer_info
Execute(Linting shouldn't happen when the file is too large with a local options):
let b:ale_maximum_file_size = 12
let g:ale_buffer_info = {}
call ale#Queue(0)
AssertEqual {}, g:ale_buffer_info
Execute(Cursor warnings shouldn't be echoed when ALE is disabled globally): Execute(Cursor warnings shouldn't be echoed when ALE is disabled globally):
let g:ale_enabled = 0 let g:ale_enabled = 0
let g:ale_buffer_info = {
\ bufnr('%'): {
\ 'loclist': [
\ {
\ 'lnum': 2,
\ 'col': 10,
\ 'linter_name': 'testlinter',
\ 'type': 'W',
\ 'text': 'X'
\ },
\ ],
\ },
\}
call cursor(2, 16) call SetUpCursorData()
call ale#cursor#EchoCursorWarning()
AssertEqual '', GetLastMessage()
Execute(Cursor warnings shouldn't be echoed when the file is too large with global options):
let g:ale_maximum_file_size = 12
call SetUpCursorData()
call ale#cursor#EchoCursorWarning() call ale#cursor#EchoCursorWarning()
AssertEqual '', GetLastMessage() AssertEqual '', GetLastMessage()
Execute(Cursor warnings shouldn't be echoed when ALE is disabled locally): Execute(Cursor warnings shouldn't be echoed when ALE is disabled locally):
let b:ale_enabled = 0 let b:ale_enabled = 0
let g:ale_buffer_info = {
\ bufnr('%'): {
\ 'loclist': [
\ {
\ 'lnum': 2,
\ 'col': 10,
\ 'linter_name': 'testlinter',
\ 'type': 'W',
\ 'text': 'X'
\ },
\ ],
\ },
\}
call cursor(2, 16) call SetUpCursorData()
call ale#cursor#EchoCursorWarning()
AssertEqual '', GetLastMessage()
Execute(Cursor warnings shouldn't be echoed when the file is too large with local options):
let b:ale_maximum_file_size = 12
call SetUpCursorData()
call ale#cursor#EchoCursorWarning() call ale#cursor#EchoCursorWarning()
AssertEqual '', GetLastMessage() AssertEqual '', GetLastMessage()