Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

conditionally enable/disable prettier based on .pretierrc existance in root #629

Answered by jose-elias-alvarez
psiho asked this question in Q&A
Discussion options

You must be logged in to vote

This is mentioned in the documentation, but condition will only run once. Your best bet is to use runtime_condition, which does run on each invocation and so can be used to check the current buffer's root directory. Note that in your case, params.root will still reflect the original root, so you'd have to do something like this:

local prettier = null_ls.builtins.formatting.prettier.with({
    runtime_condition = function(params)
        local utils = require("null-ls.utils")
        -- use whatever root markers you want to check - these are the defaults
        local root = utils.root_pattern(".null-ls-root", "Makefile", ".git")(params.bufname)
        return root and utils.path.exists(utils

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@psiho
Comment options

@jose-elias-alvarez
Comment options

@psiho
Comment options

Answer selected by psiho
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants