summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-09-06 11:17:21 +0100
committerw0rp <devw0rp@gmail.com>2017-09-06 11:17:21 +0100
commitc277cdef8cb24512583093d7a9b7d68a14e6d82b (patch)
treea60c7b9c08f1e1249ab45c90ef21c896e99d7ffc
parentad1bd424fa33a60fd437ff1488f5bcd925a0be10 (diff)
downloadale-c277cdef8cb24512583093d7a9b7d68a14e6d82b.zip
Add an option for ignoring the output of TSLint if a file contains a single blank line
-rw-r--r--ale_linters/typescript/tslint.vim7
-rw-r--r--doc/ale-typescript.txt12
-rw-r--r--test/handler/test_tslint_handler.vader119
3 files changed, 138 insertions, 0 deletions
diff --git a/ale_linters/typescript/tslint.vim b/ale_linters/typescript/tslint.vim
index 18f9e08c..c3852b89 100644
--- a/ale_linters/typescript/tslint.vim
+++ b/ale_linters/typescript/tslint.vim
@@ -5,6 +5,7 @@ call ale#Set('typescript_tslint_executable', 'tslint')
call ale#Set('typescript_tslint_config_path', '')
call ale#Set('typescript_tslint_rules_dir', '')
call ale#Set('typescript_tslint_use_global', 0)
+call ale#Set('typescript_tslint_ignore_empty_files', 0)
function! ale_linters#typescript#tslint#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'typescript_tslint', [
@@ -13,6 +14,12 @@ function! ale_linters#typescript#tslint#GetExecutable(buffer) abort
endfunction
function! ale_linters#typescript#tslint#Handle(buffer, lines) abort
+ " Do not output any errors for empty files if the option is on.
+ if ale#Var(a:buffer, 'typescript_tslint_ignore_empty_files')
+ \&& getbufline(a:buffer, 1, '$') == ['']
+ return []
+ endif
+
let l:dir = expand('#' . a:buffer . ':p:h')
let l:output = []
diff --git a/doc/ale-typescript.txt b/doc/ale-typescript.txt
index 794240ec..949b80de 100644
--- a/doc/ale-typescript.txt
+++ b/doc/ale-typescript.txt
@@ -30,6 +30,18 @@ g:ale_typescript_tslint_config_path *g:ale_typescript_tslint_config_path*
such path exists, this variable will be used instead.
+g:ale_typescript_tslint_ignore_empty_files
+ *g:ale_typescript_tslint_ignore_empty_files*
+ *b:ale_typescript_tslint_ignore_empty_files*
+ Type: |Number|
+ Default: `0`
+
+ When set to `1`, ALE will not report any problems for empty files with
+ TSLint. ALE will still execute TSLint for the files, but ignore any problems
+ reported. This stops ALE from complaining about newly created files,
+ and files where lines have been added and then removed.
+
+
g:ale_typescript_tslint_rules_dir *g:ale_typescript_tslint_rules_dir*
*b:ale_typescript_tslint_rules_dir*
Type: |String|
diff --git a/test/handler/test_tslint_handler.vader b/test/handler/test_tslint_handler.vader
index 5c8679a4..47233f5c 100644
--- a/test/handler/test_tslint_handler.vader
+++ b/test/handler/test_tslint_handler.vader
@@ -1,9 +1,18 @@
Before:
+ Save g:ale_typescript_tslint_ignore_empty_files
+
+ unlet! g:ale_typescript_tslint_ignore_empty_files
+ unlet! b:ale_typescript_tslint_ignore_empty_files
+
runtime ale_linters/typescript/tslint.vim
call ale#test#SetDirectory('/testplugin/test/handler')
After:
+ Restore
+
+ unlet! b:ale_typescript_tslint_ignore_empty_files
+
call ale#test#RestoreDirectory()
call ale#linter#Reset()
@@ -133,3 +142,113 @@ Execute(The tslint handler should handle empty output):
AssertEqual
\ [],
\ ale_linters#typescript#tslint#Handle(bufnr(''), [])
+
+Execute(The tslint handler report errors for empty files by default):
+ call ale#test#SetFilename('app/test.ts')
+
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 2,
+ \ 'col': 1,
+ \ 'filename': expand('%:p:h') . '/test.ts',
+ \ 'end_lnum': 2,
+ \ 'type': 'E',
+ \ 'end_col': 1,
+ \ 'text': 'no-consecutive-blank-lines: Consecutive blank lines are forbidden',
+ \ },
+ \ ],
+ \ ale_linters#typescript#tslint#Handle(bufnr(''), [json_encode([{
+ \ 'endPosition': {
+ \ 'character': 0,
+ \ 'line': 1,
+ \ 'position': 1
+ \ },
+ \ 'failure': 'Consecutive blank lines are forbidden',
+ \ 'fix': [{
+ \ 'innerStart': 0,
+ \ 'innerLength': 1,
+ \ 'innerText': ''
+ \ }],
+ \ 'name': 'test.ts',
+ \ 'ruleName': 'no-consecutive-blank-lines',
+ \ 'ruleSeverity': 'ERROR',
+ \ 'startPosition': {
+ \ 'character': 0,
+ \ 'line': 1,
+ \ 'position': 1
+ \ }
+ \ }])])
+
+Execute(The tslint handler should not report errors for empty files when the ignore option is on):
+ let b:ale_typescript_tslint_ignore_empty_files = 1
+ call ale#test#SetFilename('app/test.ts')
+
+ AssertEqual
+ \ [
+ \ ],
+ \ ale_linters#typescript#tslint#Handle(bufnr(''), [json_encode([{
+ \ 'endPosition': {
+ \ 'character': 0,
+ \ 'line': 1,
+ \ 'position': 1
+ \ },
+ \ 'failure': 'Consecutive blank lines are forbidden',
+ \ 'fix': [{
+ \ 'innerStart': 0,
+ \ 'innerLength': 1,
+ \ 'innerText': ''
+ \ }],
+ \ 'name': 'test.ts',
+ \ 'ruleName': 'no-consecutive-blank-lines',
+ \ 'ruleSeverity': 'ERROR',
+ \ 'startPosition': {
+ \ 'character': 0,
+ \ 'line': 1,
+ \ 'position': 1
+ \ }
+ \ }])])
+
+Given typescript(A file with extra blank lines):
+ const x = 3
+
+
+ const y = 4
+
+Execute(The tslint handler should report errors when the ignore option is on, but the file is not empty):
+ let b:ale_typescript_tslint_ignore_empty_files = 1
+ call ale#test#SetFilename('app/test.ts')
+
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 2,
+ \ 'col': 1,
+ \ 'filename': expand('%:p:h') . '/test.ts',
+ \ 'end_lnum': 2,
+ \ 'type': 'E',
+ \ 'end_col': 1,
+ \ 'text': 'no-consecutive-blank-lines: Consecutive blank lines are forbidden',
+ \ },
+ \ ],
+ \ ale_linters#typescript#tslint#Handle(bufnr(''), [json_encode([{
+ \ 'endPosition': {
+ \ 'character': 0,
+ \ 'line': 1,
+ \ 'position': 1
+ \ },
+ \ 'failure': 'Consecutive blank lines are forbidden',
+ \ 'fix': [{
+ \ 'innerStart': 0,
+ \ 'innerLength': 1,
+ \ 'innerText': ''
+ \ }],
+ \ 'name': 'test.ts',
+ \ 'ruleName': 'no-consecutive-blank-lines',
+ \ 'ruleSeverity': 'ERROR',
+ \ 'startPosition': {
+ \ 'character': 0,
+ \ 'line': 1,
+ \ 'position': 1
+ \ }
+ \ }])])