Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typecheck linter for typescript #170

Merged
merged 2 commits into from
Nov 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions ale_linters/typescript/typecheck.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
" Author: Prashanth Chandra https://github.com/prashcr, Aleh Kashnikau https://github.com/mkusher
" Description: type checker for TypeScript files

function! ale_linters#typescript#typecheck#Handle(buffer, lines)
" Matches patterns like the following:
"
" hello.ts[7, 41]: Property 'a' does not exist on type 'A'
" hello.ts[16, 7]: Type 'A' is not assignable to type 'B'
"
let l:pattern = '.\+.ts\[\(\d\+\), \(\d\+\)\]: \(.\+\)'
let l:output = []

for l:line in a:lines
let l:match = matchlist(l:line, l:pattern)

if len(l:match) == 0
continue
endif

let l:line = l:match[1] + 0
let l:column = l:match[2] + 0
let l:type = 'E'
let l:text = l:match[3]

" vcol is Needed to indicate that the column is a character.
call add(l:output, {
\ 'bufnr': a:buffer,
\ 'lnum': l:line,
\ 'vcol': 0,
\ 'col': l:column,
\ 'text': l:text,
\ 'type': l:type,
\ 'nr': -1,
\})
endfor

return l:output
endfunction

call ale#linter#Define('typescript', {
\ 'name': 'typecheck',
\ 'executable': 'typecheck',
\ 'command': 'typecheck %s',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will be running the command on the file as it is on disk, not the text you are editing as you type. You'll either need to use an option to use stdin data for the file, or use the stdin_wrapper file, probably with an argument to include the directory you are editing the file in or something similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, typecheck uses stdin by default

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it still use stdin if a filename is given? The '%s' here will be replaced with the filename.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, typecheck needs file name to find tsconfig.json, but it will read file contents from stdin

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sounds good to me, then. Sounds similar to the --stdin-filename option for eslint, but as a positional argument.

\ 'callback': 'ale_linters#typescript#typecheck#Handle',
\})