-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
w0rp
merged 2 commits into
dense-analysis:master
from
mkusher:typescript_typecheck_linter
Nov 10, 2016
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
\ 'callback': 'ale_linters#typescript#typecheck#Handle', | ||
\}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 foreslint
, but as a positional argument.