Skip to content

Commit

Permalink
fix: Adjust conform.nvim formatter configs
Browse files Browse the repository at this point in the history
  • Loading branch information
MysticalDevil committed Nov 10, 2023
1 parent f26f0da commit bc71b13
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 41 deletions.
59 changes: 18 additions & 41 deletions lua/devil/format/conform.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@ local opts = {
-- Map of filetype to formatters
formatters_by_ft = {
bash = { "beautysh" },
go = { "gofumpt", "goimports", "golines" },
lua = { "stylua" },
c = { "clang_format" },
clojure = { "zprint" },
cmake = { "cmake_format" },
cpp = { "clang_format" },
cs = { "charpier" },
dart = { "dart_format" },
elixir = { "mix" },
fish = { "fish_indent" },
go = { "gofumpt", "goimports-reviser", "golines" },
java = { "google-java-format" },
javascript = { { "prettierd", "prettier" } },
json = { "jq" },
kotlin = { "ktlint" },
lua = { "stylua" },
perl = { "perlimports", "perltidy" },
python = { "isort", "black" },
ruby = { "standardrb" },
rust = { "rustfmt" },
scala = { "scalafmt" },
sh = { "beautysh" },
toml = { "taplo" },
xml = { "xmlformat" },
yaml = { "yamlfmt" },
Expand Down Expand Up @@ -45,50 +58,14 @@ local opts = {
notify_on_error = true,
-- Define custom formatters here
formatters = {
my_formatter = {
-- This can be a string or a function that returns a string
command = "my_cmd",
-- OPTIONAL - all fields below this are optional
-- A list of strings, or a function that returns a list of strings
-- Return a single string instead to run the command in a shell
args = { "--stdin-from-filename", "$FILENAME" },
-- If the formatter supports range formatting, create the range arguments here
range_args = function(ctx)
return { "--line-start", ctx.range.start[1], "--line-end", ctx.range["end"][1] }
end,
-- Send file contents to stdin, read new contents from stdout (default true)
-- When false, will create a temp file (will appear in "$FILENAME" args). The temp
-- file is assumed to be modified in-place by the format command.
prettier = {
command = require("conform.util").find_executable({ "node_modules/.bin/prettier" }, "prettier"),
args = { "--no-semi" },
stdin = true,
-- A function that calculates the directory to run the command in
cwd = require("conform.util").root_file({ ".editorconfig", "package.json" }),
-- When cwd is not found, don't run the formatter (default false)
require_cwd = true,
-- When returns false, the formatter will not be used
condition = function(ctx)
return vim.fs.basename(ctx.filename) ~= "README.md"
end,
-- Exit codes that indicate success (default {0})
exit_codes = { 0, 1 },
-- Environment variables. This can also be a function that returns a table.
env = {
VAR = "value",
},
},
-- These can also be a function that returns the formatter
other_formatter = function()
return {
command = "my_cmd",
}
end,
},
}

conform.setup(opts)

vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*",
callback = function(args)
require("conform").format({ bufnr = args.buf })
end,
})
1 change: 1 addition & 0 deletions lua/devil/plugins/languages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ return {
"mfussenegger/nvim-dap",
"mfussenegger/nvim-lint",
"mhartington/formatter.nvim",
"stevearc/conform.nvim",
"nvimtools/none-ls.nvim",
},
},
Expand Down

0 comments on commit bc71b13

Please sign in to comment.