Skip to content

Commit

Permalink
Merge pull request #2660 from YPCrumble/master
Browse files Browse the repository at this point in the history
Add StandardJS linter for TypeScript
  • Loading branch information
w0rp authored Nov 14, 2019
2 parents 66a8df0 + ea91209 commit 7665559
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 1 deletion.
1 change: 1 addition & 0 deletions ale_linters/javascript/standard.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ call ale#Set('javascript_standard_options', '')

function! ale_linters#javascript#standard#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'javascript_standard', [
\ 'node_modules/standardx/bin/cmd.js',
\ 'node_modules/standard/bin/cmd.js',
\ 'node_modules/semistandard/bin/cmd.js',
\ 'node_modules/.bin/standard',
Expand Down
31 changes: 31 additions & 0 deletions ale_linters/typescript/standard.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
" Author: Ahmed El Gabri <@ahmedelgabri>
" Description: standardjs for typescript files

call ale#Set('typescript_standard_executable', 'standard')
call ale#Set('typescript_standard_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('typescript_standard_options', '')

function! ale_linters#typescript#standard#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'typescript_standard', [
\ 'node_modules/standardx/bin/cmd.js',
\ 'node_modules/standard/bin/cmd.js',
\ 'node_modules/.bin/standard',
\])
endfunction

function! ale_linters#typescript#standard#GetCommand(buffer) abort
let l:executable = ale_linters#typescript#standard#GetExecutable(a:buffer)
let l:options = ale#Var(a:buffer, 'typescript_standard_options')

return ale#node#Executable(a:buffer, l:executable)
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' --stdin %s'
endfunction

" standard uses eslint and the output format is the same
call ale#linter#Define('typescript', {
\ 'name': 'standard',
\ 'executable': function('ale_linters#typescript#standard#GetExecutable'),
\ 'command': function('ale_linters#typescript#standard#GetCommand'),
\ 'callback': 'ale#handlers#eslint#Handle',
\})
10 changes: 9 additions & 1 deletion autoload/ale/fixers/standard.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ call ale#Set('javascript_standard_options', '')

function! ale#fixers#standard#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'javascript_standard', [
\ 'node_modules/standardx/bin/cmd.js',
\ 'node_modules/standard/bin/cmd.js',
\ 'node_modules/.bin/standard',
\])
endfunction

function! ale#fixers#standard#Fix(buffer) abort
let l:executable = ale#fixers#standard#GetExecutable(a:buffer)
let l:options = ale#Var(a:buffer, 'javascript_standard_options')
let l:filetype = getbufvar(a:buffer, '&filetype')
let l:options_type = 'javascript_standard_options'

if l:filetype =~# 'typescript'
let l:options_type = 'typescript_standard_options'
endif

let l:options = ale#Var(a:buffer, l:options_type)

return {
\ 'command': ale#node#Executable(a:buffer, l:executable)
Expand Down
1 change: 1 addition & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ Notes:
* `eslint`
* `fecs`
* `prettier`
* `standard`
* `tslint`
* `tsserver`
* `typecheck`
Expand Down
27 changes: 27 additions & 0 deletions doc/ale-typescript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,33 @@ prettier *ale-typescript-prettier*
See |ale-javascript-prettier| for information about the available options.


===============================================================================
standard *ale-typescript-standard*

g:ale_typescript_standard_executable *g:ale_typescript_standard_executable*
*b:ale_typescript_standard_executable*
Type: |String|
Default: `'standard'`

See |ale-integrations-local-executables|


g:ale_typescript_standard_options *g:ale_typescript_standard_options*
*b:ale_typescript_standard_options*
Type: |String|
Default: `''`

This variable can be set to pass additional options to standard.


g:ale_typescript_standard_use_global *g:ale_typescript_standard_use_global*
*b:ale_typescript_standard_use_global*
Type: |Number|
Default: `get(g:, 'ale_use_global_executables', 0)`

See |ale-integrations-local-executables|


===============================================================================
tslint *ale-typescript-tslint*

Expand Down
1 change: 1 addition & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2524,6 +2524,7 @@ documented in additional help files.
typescript..............................|ale-typescript-options|
eslint................................|ale-typescript-eslint|
prettier..............................|ale-typescript-prettier|
standard..............................|ale-typescript-standard|
tslint................................|ale-typescript-tslint|
tsserver..............................|ale-typescript-tsserver|
vala....................................|ale-vala-options|
Expand Down
1 change: 1 addition & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ formatting.
* [eslint](http://eslint.org/)
* [fecs](http://fecs.baidu.com/)
* [prettier](https://github.com/prettier/prettier)
* [standard](http://standardjs.com/)
* [tslint](https://github.com/palantir/tslint)
* [tsserver](https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29)
* typecheck
Expand Down
43 changes: 43 additions & 0 deletions test/command_callback/test_standardts_command_callback.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Before:
call ale#assert#SetUpLinterTest('typescript', 'standard')
call ale#test#SetFilename('testfile.js')
unlet! b:executable

After:
call ale#assert#TearDownLinterTest()

Execute(bin/cmd.js paths should be preferred):
call ale#test#SetFilename('standard-test-files/with-cmd/testfile.js')

let b:executable = ale#path#Simplify(
\ g:dir
\ . '/standard-test-files/with-cmd/node_modules/standard/bin/cmd.js'
\)

AssertLinter b:executable,
\ (has('win32') ? 'node.exe ' : '')
\ . ale#Escape(b:executable)
\ . ' --stdin %s'

Execute(.bin directories should be used too):
call ale#test#SetFilename('standard-test-files/with-bin/testfile.js')

let b:executable = ale#path#Simplify(
\ g:dir
\ . '/standard-test-files/with-bin/node_modules/.bin/standard'
\)

AssertLinter b:executable, ale#Escape(b:executable) . ' --stdin %s'

Execute(The global executable should be used otherwise):
AssertLinter 'standard', ale#Escape('standard') . ' --stdin %s'

Execute(The global executable should be configurable):
let b:ale_typescript_standard_executable = 'foobar'

AssertLinter 'foobar', ale#Escape('foobar') . ' --stdin %s'

Execute(The options should be configurable):
let b:ale_typescript_standard_options = '--wat'

AssertLinter 'standard', ale#Escape('standard') . ' --wat --stdin %s'

0 comments on commit 7665559

Please sign in to comment.