Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 6025

I am trying to utilize `prettier` for formatting certain types of files, but my `formatter.lua` setup does not seem to work, what could be the issue?

$
0
0

I am new to NeoVim ecosystem. I set up my config based from the ThePrimeage's video. After that I tried to install additional formatting using formatter.nvim package for NeoVim.

This is how my formatter.lua file looks like:

vim.cmd([[nnoremap <silent> <leader>fm :Format<CR>]])local util = require("formatter.util")local function prettier()    return {        exe = "prettier",        args = {"--write","--config-precedence","prefer-file","--single-quote","--no-bracket-spacing","--prose-wrap","always","--arrow-parens","always","--trailing-comma","all","--no-semi","--end-of-line","lf","--print-width",            vim.bo.textwidth,"--stdin-filepath",            vim.fn.shellescape(vim.api.nvim_buf_get_name(0)),        },        stdin = true,    }endrequire("formatter").setup({    logging = true,    log_level = vim.log.levels.WARN,    filetype = {        javascript = { prettier },        typescript = { prettier },        javascriptreact = { prettier },        typescriptreact = { prettier },        vue = { prettier },        ["javascript.jsx"] = { prettier },        ["typescript.tsx"] = { prettier },        markdown = { prettier },        css = { prettier },        json = { prettier },        jsonc = { prettier },        scss = { prettier },        less = { prettier },        yaml = { prettier },        graphql = { prettier },        html = { prettier },        reason = {            function()                return {                    exe = "refmt",                    stdin = true,                }            end,        },        lua = {            require("formatter.filetypes.lua").stylua,            function()                if util.get_current_buffer_file_name() == "special.lua" then                    return nil                end                return {                    exe = "stylua",                    args = {"--search-parent-directories","--stdin-filepath",                        util.escape_path(util.get_current_buffer_file_path()),"--","-",                    },                    stdin = true,                }            end,        },        go = {            function()                return {                    exe = "gofmt",                    args = { "-s", "-w", vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)) },                    stdin = false,                }            end,        },        c = {            function()                return {                    exe = "clang-format",                    args = { "-i", vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)) },                    stdin = false,                }            end,        },        rust = {            function()                return {                    exe = "rustfmt",                    args = { "--emit=stdout", "--edition=2018", vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)) },                    stdin = false,                }            end,        },    },})

I have prettier installed globally on my system: /usr/local/bin/prettier.

When I try to provide a relative path to the prettier executable instead of just writing prettier it does not find the formatter.

I have default prettier configuration file in my project directory (.prettierrc.json)

Note: I've tried other formats for config too, but without any results.

Note: Formatting for other files does work (Go, Rust, C). Only prettier seems to have a problem.

Note: I had prettier installed using Mason too, but it did not fix the issue, just changed the prettier path while executing the formatting (this command - print(vim.inspect(vim.fn["systemlist"]("which prettier"))))

What can I do to successfully utilize prettier formatting in my NeoVim setup?


Viewing all articles
Browse latest Browse all 6025

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>