summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/ale/fixers/prettier.vim17
-rw-r--r--test/fixers/test_prettier_fixer_callback.vader11
-rw-r--r--test/prettier-test-files/with_prettierignore/.prettierignore0
-rw-r--r--test/prettier-test-files/with_prettierignore/src/testfile.js0
4 files changed, 27 insertions, 1 deletions
diff --git a/autoload/ale/fixers/prettier.vim b/autoload/ale/fixers/prettier.vim
index 23120777..e0f4972e 100644
--- a/autoload/ale/fixers/prettier.vim
+++ b/autoload/ale/fixers/prettier.vim
@@ -34,6 +34,21 @@ function! ale#fixers#prettier#ProcessPrettierDOutput(buffer, output) abort
return a:output
endfunction
+function! ale#fixers#prettier#GetProjectRoot(buffer) abort
+ let l:config = ale#path#FindNearestFile(a:buffer, '.prettierignore')
+
+ if !empty(l:config)
+ return fnamemodify(l:config, ':h')
+ endif
+
+ " Fall back to the directory of the buffer
+ return fnamemodify(bufname(a:buffer), ':p:h')
+endfunction
+
+function! ale#fixers#prettier#CdProjectRoot(buffer) abort
+ return ale#path#CdString(ale#fixers#prettier#GetProjectRoot(a:buffer))
+endfunction
+
function! ale#fixers#prettier#ApplyFixForVersion(buffer, version) abort
let l:executable = ale#fixers#prettier#GetExecutable(a:buffer)
let l:options = ale#Var(a:buffer, 'javascript_prettier_options')
@@ -97,7 +112,7 @@ function! ale#fixers#prettier#ApplyFixForVersion(buffer, version) abort
" 1.4.0 is the first version with --stdin-filepath
if ale#semver#GTE(a:version, [1, 4, 0])
return {
- \ 'command': ale#path#BufferCdString(a:buffer)
+ \ 'command': ale#fixers#prettier#CdProjectRoot(a:buffer)
\ . ale#Escape(l:executable)
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' --stdin-filepath %s --stdin',
diff --git a/test/fixers/test_prettier_fixer_callback.vader b/test/fixers/test_prettier_fixer_callback.vader
index 1087a160..fdd97df3 100644
--- a/test/fixers/test_prettier_fixer_callback.vader
+++ b/test/fixers/test_prettier_fixer_callback.vader
@@ -297,6 +297,17 @@ Execute(Should set --parser for experimental language, Handlebars):
\ . ' --stdin-filepath %s --stdin',
\ }
+Execute(Changes to directory where .prettierignore is found):
+ call ale#test#SetFilename('../prettier-test-files/with_prettierignore/src/testfile.js')
+
+ GivenCommandOutput ['1.6.0']
+ AssertFixer
+ \ {
+ \ 'command': ale#path#CdString(expand('%:p:h:h'))
+ \ . ale#Escape(g:ale_javascript_prettier_executable)
+ \ . ' --stdin-filepath %s --stdin',
+ \ }
+
Execute(The prettier_d post-processor should permit regular JavaScript content):
AssertEqual
\ [
diff --git a/test/prettier-test-files/with_prettierignore/.prettierignore b/test/prettier-test-files/with_prettierignore/.prettierignore
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/prettier-test-files/with_prettierignore/.prettierignore
diff --git a/test/prettier-test-files/with_prettierignore/src/testfile.js b/test/prettier-test-files/with_prettierignore/src/testfile.js
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/prettier-test-files/with_prettierignore/src/testfile.js