summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2019-11-14 14:47:19 +0000
committerGitHub <noreply@github.com>2019-11-14 14:47:19 +0000
commit7665559d0e6102c9eccf39a119afd9c7a1a0af82 (patch)
tree537557408cb17220a2b9541c398c9226970fed00
parent66a8df081e57b18ab79b71c77d628c56aa4d8344 (diff)
parentea91209a6685faa0275dc5f8735836ced8b08e4b (diff)
downloadale-7665559d0e6102c9eccf39a119afd9c7a1a0af82.zip
Merge pull request #2660 from YPCrumble/master
Add StandardJS linter for TypeScript
-rw-r--r--ale_linters/javascript/standard.vim1
-rw-r--r--ale_linters/typescript/standard.vim31
-rw-r--r--autoload/ale/fixers/standard.vim10
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale-typescript.txt27
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md1
-rw-r--r--test/command_callback/test_standardts_command_callback.vader43
8 files changed, 114 insertions, 1 deletions
diff --git a/ale_linters/javascript/standard.vim b/ale_linters/javascript/standard.vim
index 203a803e..1990adce 100644
--- a/ale_linters/javascript/standard.vim
+++ b/ale_linters/javascript/standard.vim
@@ -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',
diff --git a/ale_linters/typescript/standard.vim b/ale_linters/typescript/standard.vim
new file mode 100644
index 00000000..da8f14eb
--- /dev/null
+++ b/ale_linters/typescript/standard.vim
@@ -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',
+\})
diff --git a/autoload/ale/fixers/standard.vim b/autoload/ale/fixers/standard.vim
index 77712d40..cffa9f9d 100644
--- a/autoload/ale/fixers/standard.vim
+++ b/autoload/ale/fixers/standard.vim
@@ -7,6 +7,7 @@ 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',
\])
@@ -14,7 +15,14 @@ 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)
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index b7542177..de1be1a2 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -468,6 +468,7 @@ Notes:
* `eslint`
* `fecs`
* `prettier`
+ * `standard`
* `tslint`
* `tsserver`
* `typecheck`
diff --git a/doc/ale-typescript.txt b/doc/ale-typescript.txt
index 7dc59820..2c50d119 100644
--- a/doc/ale-typescript.txt
+++ b/doc/ale-typescript.txt
@@ -17,6 +17,33 @@ 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*
This linter isn't recommended, because TSLint can't be used for checking for
diff --git a/doc/ale.txt b/doc/ale.txt
index f1c2efbb..515c5f2c 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -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|
diff --git a/supported-tools.md b/supported-tools.md
index 324e2000..5a3376d4 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -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
diff --git a/test/command_callback/test_standardts_command_callback.vader b/test/command_callback/test_standardts_command_callback.vader
new file mode 100644
index 00000000..d769e712
--- /dev/null
+++ b/test/command_callback/test_standardts_command_callback.vader
@@ -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'