#0: Don't try to load prettier config if formatOnSave is false #2284
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR details
I noticed while trying to
retrieve
query
I was getting an error aroundprettier
configurations, even though I hadformatOnSave
set tofalse
.While the retrieval still continued, the program exits with code
1
(due to theUtil.logger.error
function callingUtil.signalFatalError
which setsprocess.exitCode = 1
) so this caused needing a bit of a workaround to get it working programatically inside another application.What changes did you make? (Give an overview)
If the
formatOnSave
option isfalse
then theinitPrettier
function will early exit without trying to find theprettierrc
config.Further details (optional)
I tried to add tests around the
initPrettier
function but couldn't see a straightforward way. I wanted to mock theUtil
module in order to check thatUtil.logger.error
wasn't called, but it appears that module mocking is only supported as an experimental feature innode:test
at the moment. I didn't want to go too far overboard with re-structuring things (especially in a first contribution), and given the tests appear to primarily be around the types or an end-to-end process, I thought it might squeak by....
Checklist