added importjs fixer
- added tests for fixer functions - added docs
This commit is contained in:
parent
2f9869de44
commit
fba3c57872
6 changed files with 74 additions and 0 deletions
|
@ -54,6 +54,11 @@ let s:default_registry = {
|
||||||
\ 'description': 'Apply prettier-eslint to a file.',
|
\ 'description': 'Apply prettier-eslint to a file.',
|
||||||
\ 'aliases': ['prettier-eslint'],
|
\ 'aliases': ['prettier-eslint'],
|
||||||
\ },
|
\ },
|
||||||
|
\ 'importjs': {
|
||||||
|
\ 'function': 'ale#fixers#importjs#Fix',
|
||||||
|
\ 'suggested_filetypes': ['javascript'],
|
||||||
|
\ 'description': 'automatic imports for javascript',
|
||||||
|
\ },
|
||||||
\ 'puppetlint': {
|
\ 'puppetlint': {
|
||||||
\ 'function': 'ale#fixers#puppetlint#Fix',
|
\ 'function': 'ale#fixers#puppetlint#Fix',
|
||||||
\ 'suggested_filetypes': ['puppet'],
|
\ 'suggested_filetypes': ['puppet'],
|
||||||
|
|
24
autoload/ale/fixers/importjs.vim
Normal file
24
autoload/ale/fixers/importjs.vim
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
" Author: Jeff Willette <jrwillette88@gmail.com>
|
||||||
|
" Description: Integration of importjs with ALE.
|
||||||
|
|
||||||
|
call ale#Set('js_importjs_executable', 'importjs')
|
||||||
|
|
||||||
|
function! ale#fixers#importjs#ProcessOutput(buffer, output) abort
|
||||||
|
let l:result = ale#util#FuzzyJSONDecode(a:output, [])
|
||||||
|
return split(get(l:result, 'fileContent', ''), "\n")
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! ale#fixers#importjs#Fix(buffer) abort
|
||||||
|
let l:executable = ale#Var(a:buffer, 'js_importjs_executable')
|
||||||
|
|
||||||
|
if !executable(l:executable)
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
return {
|
||||||
|
\ 'command': ale#Escape(l:executable)
|
||||||
|
\ . ' fix'
|
||||||
|
\ . ' %s',
|
||||||
|
\ 'process_with': 'ale#fixers#importjs#ProcessOutput',
|
||||||
|
\}
|
||||||
|
endfunction
|
|
@ -103,6 +103,15 @@ g:ale_javascript_flow_use_global *g:ale_javascript_flow_use_global*
|
||||||
See |ale-integrations-local-executables|
|
See |ale-integrations-local-executables|
|
||||||
|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
importjs *ale-javascript-importjs*
|
||||||
|
|
||||||
|
g:ale_javascript_importjs_executable *g:ale_javascript_importjs_executable*
|
||||||
|
*b:ale_javascript_importjs_executable*
|
||||||
|
Type: |String|
|
||||||
|
Default: `'importjs'`
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
jscs *ale-javascript-jscs*
|
jscs *ale-javascript-jscs*
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,7 @@ CONTENTS *ale-contents*
|
||||||
javascript............................|ale-javascript-options|
|
javascript............................|ale-javascript-options|
|
||||||
eslint..............................|ale-javascript-eslint|
|
eslint..............................|ale-javascript-eslint|
|
||||||
flow................................|ale-javascript-flow|
|
flow................................|ale-javascript-flow|
|
||||||
|
importjs............................|ale-javascript-importjs|
|
||||||
jscs................................|ale-javascript-jscs|
|
jscs................................|ale-javascript-jscs|
|
||||||
jshint..............................|ale-javascript-jshint|
|
jshint..............................|ale-javascript-jshint|
|
||||||
prettier............................|ale-javascript-prettier|
|
prettier............................|ale-javascript-prettier|
|
||||||
|
|
35
test/fixers/test_importjs_fixer_callback.vader
Normal file
35
test/fixers/test_importjs_fixer_callback.vader
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
Before:
|
||||||
|
Save g:ale_js_importjs_executable
|
||||||
|
|
||||||
|
" Use an invalid global executable, so we don't match it.
|
||||||
|
let g:ale_js_importjs_executable = 'xxxinvalid'
|
||||||
|
|
||||||
|
call ale#test#SetDirectory('/testplugin/test/fixers')
|
||||||
|
call ale#test#SetFilename('../javascript_files/test.js')
|
||||||
|
|
||||||
|
After:
|
||||||
|
Restore
|
||||||
|
|
||||||
|
call ale#test#RestoreDirectory()
|
||||||
|
|
||||||
|
Execute(The importjs callback should return 0 when the executable isn't executable):
|
||||||
|
AssertEqual
|
||||||
|
\ 0,
|
||||||
|
\ ale#fixers#importjs#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The importjs callback should run the command when the executable test passes):
|
||||||
|
let g:ale_js_importjs_executable = has('win32') ? 'cmd' : 'echo'
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'process_with': 'ale#fixers#importjs#ProcessOutput',
|
||||||
|
\ 'command': ale#Escape(g:ale_js_importjs_executable) . ' fix %s'
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#importjs#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The ProcessOutput callback should return the expected output):
|
||||||
|
let g:testOutput = '{"messages":[],"fileContent":"one\ntwo","unresolvedImports":{}}'
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ ['one', 'two'],
|
||||||
|
\ ale#fixers#importjs#ProcessOutput(bufnr(''), g:testOutput)
|
0
test/javascript_files/test.js
Normal file
0
test/javascript_files/test.js
Normal file
Reference in a new issue