Skip to content

question: trim_whitespace when no formatter and no LSP #682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
0xDmtri opened this issue Mar 31, 2025 · 2 comments
Closed

question: trim_whitespace when no formatter and no LSP #682

0xDmtri opened this issue Mar 31, 2025 · 2 comments

Comments

@0xDmtri
Copy link

0xDmtri commented Mar 31, 2025

Hi, heres my current config:

-- Setup Conform formatter
require("conform").setup({
    formatters_by_ft = {
        -- Set specific formatters per language
        lua = { "stylua" },
        python = { "ruff_format", "ruff_organize_imports" },
        javascript = { "prettier" },
        typescript = { "prettier" },
        solidity = { "forge_fmt" },

        -- Use LSP formatting if no specific formatters configured
        default_format_opts = {
            lsp_format = "fallback",
        },

        -- Trim whitespace if no other formatters configured,
        -- and no LSP formatters found
        ["_"] = { "trim_whitespace" },
    },
    format_on_save = {
        timeout_ms = 500,
    },
})

Can't get my head around how could I set to trigger trim_whitespace only if theres no formatter configured and no LSP formatter is available. So that the priority list works in the following order:

configured formatter -> lsp formatter -> trim_whitespace

Many thanks!

@0xDmtri 0xDmtri changed the title qustion: trim_whitespace when no formatter and no LSP question: trim_whitespace when no formatter and no LSP Mar 31, 2025
@stevearc
Copy link
Owner

stevearc commented Mar 31, 2025

Try setting

["_"] = { "trim_whitespace", lsp_format = "prefer" }

Note: you'll need to be on the most recent master commit

@0xDmtri
Copy link
Author

0xDmtri commented Mar 31, 2025

Try setting

["_"] = { "trim_whitespace", lsp_format = "prefer" }
Note: you'll need to be on the most recent master commit

Perfect, that works great! Thanks a lot!

@0xDmtri 0xDmtri closed this as completed Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants