From 52de0f9163f4079767ad0472619ebc731105d1cb Mon Sep 17 00:00:00 2001 From: Christian Nieves Date: Tue, 1 Aug 2023 23:08:02 +0000 Subject: [PATCH] formater --- vim/.vim/lua/plugins/formatter.lua | 90 +++++++++++++++++++++++++++++ vim/.vim/lua/plugins/lint.lua | 10 ++++ vim/.vim/lua/plugins/null-ls.lua | 93 ------------------------------ 3 files changed, 100 insertions(+), 93 deletions(-) create mode 100644 vim/.vim/lua/plugins/formatter.lua create mode 100644 vim/.vim/lua/plugins/lint.lua delete mode 100644 vim/.vim/lua/plugins/null-ls.lua diff --git a/vim/.vim/lua/plugins/formatter.lua b/vim/.vim/lua/plugins/formatter.lua new file mode 100644 index 0000000..0573553 --- /dev/null +++ b/vim/.vim/lua/plugins/formatter.lua @@ -0,0 +1,90 @@ +return { + "mhartington/formatter.nvim", + config = function() + -- Utilities for creating configurations + local util = require("formatter.util") + + -- Provides the Format, FormatWrite, FormatLock, and FormatWriteLock commands + require("formatter").setup({ + -- Enable or disable logging + logging = true, + -- Set the log level + log_level = vim.log.levels.WARN, + -- All formatter configurations are opt-in + filetype = { + -- Formatter configurations for filetype "lua" go here + -- and will be executed in order + lua = { + -- "formatter.filetypes.lua" defines default configurations for the + -- "lua" filetype + -- require("formatter.filetypes.lua").stylua, + -- You can also define your own configuration + function() + -- Supports conditional formatting + if util.get_current_buffer_file_name() == "special.lua" then + return nil + end + + -- Full specification of configurations is down below and in Vim help + -- files + return { + exe = "stylua", + args = { + "--search-parent-directories", + "--stdin-filepath", + util.escape_path(util.get_current_buffer_file_path()), + "--", + "-", + }, + stdin = true, + } + end, + }, + + html = { + require("formatter.defaults").prettier, + }, + xml = { + function() + return { + exe = "tidy", + args = { + "-quiet", + "-xml", + "--indent yes", + "--indent-spaces 2", + "--sort-attributes alpha", + -- "--verical-space yes", + "--literal-attributes yes", + "--tidy-mark no", + }, + stdin = true, + try_node_modules = true, + } + end, + }, + -- java = { + -- function() + -- return { + -- exe = "google-java-format", + -- } + -- end, + -- }, + + -- Use the special "*" filetype for defining formatter configurations on + -- any filetype + ["*"] = { + -- "formatter.filetypes.any" defines default configurations for any + -- filetype + require("formatter.filetypes.any").remove_trailing_whitespace, + }, + }, + }) + vim.cmd([[ + augroup FormatAutogroup + autocmd! + autocmd BufWritePost * FormatWrite + augroup END + ]]) + end, +} diff --git a/vim/.vim/lua/plugins/lint.lua b/vim/.vim/lua/plugins/lint.lua new file mode 100644 index 0000000..d9d470c --- /dev/null +++ b/vim/.vim/lua/plugins/lint.lua @@ -0,0 +1,10 @@ +return { + "mfussenegger/nvim-lint", + config = function() + vim.api.nvim_create_autocmd({ "BufWritePost" }, { + callback = function() + require("lint").try_lint() + end, + }) + end, +} diff --git a/vim/.vim/lua/plugins/null-ls.lua b/vim/.vim/lua/plugins/null-ls.lua deleted file mode 100644 index 9a2ad6f..0000000 --- a/vim/.vim/lua/plugins/null-ls.lua +++ /dev/null @@ -1,93 +0,0 @@ -return { - "jose-elias-alvarez/null-ls.nvim", - event = "VimEnter", - config = function() - local null_ls = require("null-ls") - local use_google = require("utils").use_google - local TableConcat = require("utils").TableConcat - - local sources = { - -- * - null_ls.builtins.formatting.trim_whitespace, - -- Catch insensitive, inconsiderate writing. - null_ls.builtins.diagnostics.alex, - - -- Codespell finds common misspellings in text files. - null_ls.builtins.diagnostics.codespell, - -- null_ls.builtins.diagnostics.cspell, null_ls.builtins.code_actions.cspell, - - -- An English prose linter. Can fix some issues via code actions. - null_ls.builtins.code_actions.proselint, - - -- Reformats Java source code according to Google Java Style. - null_ls.builtins.formatting.google_java_format, - - -- XML - -- null_ls.builtins.diagnostics.tidy, - -- null_ls.builtins.formatting.xmlformat, - -- null_ls.builtins.formatting.xq, - -- null_ls.builtins.formatting.xmllint.with({ extra_args = { "--pretty", "2" } }), - null_ls.builtins.formatting.tidy.with({ - filetypes = { "xml" }, - args = { - "-xml", - "-quiet", - "-wrap", - "--tidy-mark", - "no", - "--indent", - "yes", - "--indent-spaces", - "2", - "--indent-attributes", - "yes", - "--sort-attributes", - "alpha", - "--wrap-attributes", - "yes", - "--vertical-space", - "yes", - "-", - }, - }), - null_ls.builtins.formatting.stylua, - } - - if not use_google then - TableConcat(sources, { - -- Bazel - null_ls.builtins.diagnostics.buildifier, - null_ls.builtins.formatting.buildifier, - -- Golang - null_ls.builtins.diagnostics.golangci_lint, - null_ls.builtins.formatting.gofmt, - null_ls.builtins.formatting.goimports_reviser, - -- Misc - null_ls.builtins.formatting.htmlbeautifier, - null_ls.builtins.formatting.jq, - null_ls.builtins.formatting.mdformat, - }) - end - - local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) - null_ls.setup({ - on_init = function(new_client, _) - new_client.offset_encoding = "utf-8" - end, - sources = sources, - -- you can reuse a shared lspconfig on_attach callback here - on_attach = function(client, bufnr) - if client.supports_method("textDocument/formatting") then - vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) - vim.api.nvim_create_autocmd("BufWritePre", { - group = augroup, - buffer = bufnr, - callback = function() - vim.lsp.buf.format({ async = false }) - end, - }) - end - end, - }) - end, -}