summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authoraliou <aliou@users.noreply.github.com>2017-08-29 17:05:19 +0200
committerw0rp <w0rp@users.noreply.github.com>2017-08-29 16:05:19 +0100
commitb36882e72e14673a62bcc129f00e58caa5f0c9d3 (patch)
tree2f2d2324c95de9f6b016bf4d164a0e31d8293ed2 /autoload
parent87fb72346ac2353000c987cbc24326301d95a343 (diff)
downloadale-b36882e72e14673a62bcc129f00e58caa5f0c9d3.zip
Add support for prettier configuration file. (#886)
* Add support for prettier configuration file. As of version 1.6.0, prettier allows passing a `--config` argument with a path to a configuration file. * Add test prettier configuration file. * Add option to use local prettier configuration. * Add description for new prettier option. * Also check if the config is present before using it.
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/fixers/prettier.vim25
1 files changed, 24 insertions, 1 deletions
diff --git a/autoload/ale/fixers/prettier.vim b/autoload/ale/fixers/prettier.vim
index 7f82ecfd..581536e6 100644
--- a/autoload/ale/fixers/prettier.vim
+++ b/autoload/ale/fixers/prettier.vim
@@ -4,8 +4,27 @@
call ale#Set('javascript_prettier_executable', 'prettier')
call ale#Set('javascript_prettier_use_global', 0)
+call ale#Set('javascript_prettier_use_local_config', 0)
call ale#Set('javascript_prettier_options', '')
+function! s:FindConfig(buffer) abort
+ for l:filename in [
+ \ '.prettierrc',
+ \ 'prettier.config.js',
+ \ 'package.json',
+ \ ]
+
+ let l:config = ale#path#FindNearestFile(a:buffer, l:filename)
+
+ if !empty(l:config)
+ return l:config
+ endif
+ endfor
+
+ return ''
+endfunction
+
+
function! ale#fixers#prettier#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'javascript_prettier', [
\ 'node_modules/.bin/prettier_d',
@@ -16,11 +35,15 @@ endfunction
function! ale#fixers#prettier#Fix(buffer) abort
let l:options = ale#Var(a:buffer, 'javascript_prettier_options')
+ let l:config = s:FindConfig(a:buffer)
+ let l:use_config = ale#Var(a:buffer, 'javascript_prettier_use_local_config')
+ \ && !empty(l:config)
return {
\ 'command': ale#Escape(ale#fixers#prettier#GetExecutable(a:buffer))
\ . ' %t'
- \ . ' ' . l:options
+ \ . (!empty(l:options) ? ' ' . l:options : '')
+ \ . (l:use_config ? ' --config ' . ale#Escape(l:config) : '')
\ . ' --write',
\ 'read_temporary_file': 1,
\}