Merge pull request #2660 from YPCrumble/master

Add StandardJS linter for TypeScript
This commit is contained in:
w0rp 2019-11-14 14:47:19 +00:00 committed by GitHub
commit 7665559d0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 114 additions and 1 deletions

View File

@ -7,6 +7,7 @@ call ale#Set('javascript_standard_options', '')
function! ale_linters#javascript#standard#GetExecutable(buffer) abort function! ale_linters#javascript#standard#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'javascript_standard', [ return ale#node#FindExecutable(a:buffer, 'javascript_standard', [
\ 'node_modules/standardx/bin/cmd.js',
\ 'node_modules/standard/bin/cmd.js', \ 'node_modules/standard/bin/cmd.js',
\ 'node_modules/semistandard/bin/cmd.js', \ 'node_modules/semistandard/bin/cmd.js',
\ 'node_modules/.bin/standard', \ 'node_modules/.bin/standard',

View File

@ -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',
\})

View File

@ -7,6 +7,7 @@ call ale#Set('javascript_standard_options', '')
function! ale#fixers#standard#GetExecutable(buffer) abort function! ale#fixers#standard#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'javascript_standard', [ return ale#node#FindExecutable(a:buffer, 'javascript_standard', [
\ 'node_modules/standardx/bin/cmd.js',
\ 'node_modules/standard/bin/cmd.js', \ 'node_modules/standard/bin/cmd.js',
\ 'node_modules/.bin/standard', \ 'node_modules/.bin/standard',
\]) \])
@ -14,7 +15,14 @@ endfunction
function! ale#fixers#standard#Fix(buffer) abort function! ale#fixers#standard#Fix(buffer) abort
let l:executable = ale#fixers#standard#GetExecutable(a:buffer) 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 { return {
\ 'command': ale#node#Executable(a:buffer, l:executable) \ 'command': ale#node#Executable(a:buffer, l:executable)

View File

@ -468,6 +468,7 @@ Notes:
* `eslint` * `eslint`
* `fecs` * `fecs`
* `prettier` * `prettier`
* `standard`
* `tslint` * `tslint`
* `tsserver` * `tsserver`
* `typecheck` * `typecheck`

View File

@ -16,6 +16,33 @@ prettier *ale-typescript-prettier*
See |ale-javascript-prettier| for information about the available options. 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* tslint *ale-typescript-tslint*

View File

@ -2524,6 +2524,7 @@ documented in additional help files.
typescript..............................|ale-typescript-options| typescript..............................|ale-typescript-options|
eslint................................|ale-typescript-eslint| eslint................................|ale-typescript-eslint|
prettier..............................|ale-typescript-prettier| prettier..............................|ale-typescript-prettier|
standard..............................|ale-typescript-standard|
tslint................................|ale-typescript-tslint| tslint................................|ale-typescript-tslint|
tsserver..............................|ale-typescript-tsserver| tsserver..............................|ale-typescript-tsserver|
vala....................................|ale-vala-options| vala....................................|ale-vala-options|

View File

@ -477,6 +477,7 @@ formatting.
* [eslint](http://eslint.org/) * [eslint](http://eslint.org/)
* [fecs](http://fecs.baidu.com/) * [fecs](http://fecs.baidu.com/)
* [prettier](https://github.com/prettier/prettier) * [prettier](https://github.com/prettier/prettier)
* [standard](http://standardjs.com/)
* [tslint](https://github.com/palantir/tslint) * [tslint](https://github.com/palantir/tslint)
* [tsserver](https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29) * [tsserver](https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29)
* typecheck * typecheck

View File

@ -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'