Fix #668 - Support eslint for TypeScript

This commit is contained in:
w0rp
2017-06-20 10:50:38 +01:00
parent b96f5845ed
commit a105aa90a5
11 changed files with 180 additions and 103 deletions

View File

@@ -1,5 +1,5 @@
Before:
runtime ale_linters/javascript/eslint.vim
After:
unlet! g:config_error_lines
Execute(The eslint handler should parse lines correctly):
AssertEqual
@@ -23,7 +23,7 @@ Execute(The eslint handler should parse lines correctly):
\ 'type': 'E',
\ },
\ ],
\ ale_linters#javascript#eslint#Handle(347, [
\ ale#handlers#eslint#Handle(347, [
\ 'This line should be ignored completely',
\ '/path/to/some-filename.js:47:14: Missing trailing comma. [Warning/comma-dangle]',
\ '/path/to/some-filename.js:56:41: Missing semicolon. [Error/semi]',
@@ -51,7 +51,7 @@ Execute(The eslint handler should print a message about a missing configuration
\ 'text': 'eslint configuration error (type :ALEDetail for more information)',
\ 'detail': join(g:config_error_lines, "\n"),
\ }],
\ ale_linters#javascript#eslint#Handle(347, g:config_error_lines[:])
\ ale#handlers#eslint#Handle(347, g:config_error_lines[:])
Execute(The eslint handler should print a message for config parsing errors):
let g:config_error_lines = [
@@ -79,11 +79,7 @@ Execute(The eslint handler should print a message for config parsing errors):
\ 'text': 'eslint configuration error (type :ALEDetail for more information)',
\ 'detail': join(g:config_error_lines, "\n"),
\ }],
\ ale_linters#javascript#eslint#Handle(347, g:config_error_lines[:])
After:
unlet! g:config_error_lines
call ale#linter#Reset()
\ ale#handlers#eslint#Handle(347, g:config_error_lines[:])
Execute(The eslint handler should print a message for invalid configuration settings):
let g:config_error_lines = [
@@ -113,7 +109,7 @@ Execute(The eslint handler should print a message for invalid configuration sett
\ 'text': 'eslint configuration error (type :ALEDetail for more information)',
\ 'detail': join(g:config_error_lines, "\n"),
\ }],
\ ale_linters#javascript#eslint#Handle(347, g:config_error_lines[:])
\ ale#handlers#eslint#Handle(347, g:config_error_lines[:])
Execute(The eslint handler should output end_col values where appropriate):
AssertEqual
@@ -161,7 +157,7 @@ Execute(The eslint handler should output end_col values where appropriate):
\ 'type': 'E',
\ },
\ ],
\ ale_linters#javascript#eslint#Handle(347, [
\ ale#handlers#eslint#Handle(347, [
\ 'app.js:4:3: Parsing error: Unexpected token ''some string'' [Error]',
\ 'app.js:70:3: ''foo'' is not defined. [Error/no-undef]',
\ 'app.js:71:2: Unexpected `await` inside a loop. [Error/no-await-in-loop]',
@@ -169,3 +165,20 @@ Execute(The eslint handler should output end_col values where appropriate):
\ 'app.js:73:4: Unexpected console statement [Error/no-console]',
\ 'app.js:74:4: Unexpected ''debugger'' statement. [Error/no-debugger]',
\ ])
Execute(The eslint hint about using typescript-eslint-parser):
silent! noautocmd file foo.ts
AssertEqual
\ [
\ {
\ 'lnum': 451,
\ 'col': 2,
\ 'end_col': 2,
\ 'text': 'Parsing error (You may need configure typescript-eslint-parser): Unexpected token ) [Error]',
\ 'type': 'E',
\ },
\ ],
\ ale#handlers#eslint#Handle(bufnr(''), [
\ 'foo.ts:451:2: Parsing error: Unexpected token ) [Error]',
\ ])

View File

@@ -74,4 +74,4 @@ Execute(eslint.js executables should be run with node on Windows):
\ 'node '''
\ . g:dir . '/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'
\ . ''' -f unix --stdin --stdin-filename %s',
\ ale_linters#javascript#eslint#GetCommand(bufnr(''))
\ ale#handlers#eslint#GetCommand(bufnr(''))

View File

@@ -106,3 +106,22 @@ Execute (The local alias option shouldn't completely replace the global one):
Execute (Linters should be loaded from disk appropriately):
AssertEqual [{'name': 'testlinter', 'output_stream': 'stdout', 'executable': 'testlinter', 'command': 'testlinter', 'callback': 'testCB', 'read_buffer': 1, 'lint_file': 0, 'aliases': [], 'lsp': ''}], ale#linter#Get('testft')
Execute (Linters for later filetypes should replace the former ones):
call ale#linter#Define('javascript', {
\ 'name': 'eslint',
\ 'executable': 'y',
\ 'command': 'y',
\ 'callback': 'y',
\})
call ale#linter#Define('typescript', {
\ 'name': 'eslint',
\ 'executable': 'x',
\ 'command': 'x',
\ 'callback': 'x',
\})
AssertEqual [
\ {'output_stream': 'stdout', 'lint_file': 0, 'read_buffer': 1, 'name': 'eslint', 'executable': 'x', 'lsp': '', 'aliases': [], 'command': 'x', 'callback': 'x'}
\], ale#linter#Get('javascript.typescript')