From a0e42d5506739009c4755830b380a122eefab400 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Sun, 4 Aug 2024 01:02:30 +0300 Subject: feat(nvim): migrated from none-ls to conform (formatter) + nvim-lint --- .config/nvim/lua/custom/plugins/conform.lua | 38 +++++++++++++++++++++++++++ .config/nvim/lua/custom/plugins/none-ls.lua | 12 --------- .config/nvim/lua/custom/plugins/nvim-lint.lua | 20 ++++++++++++++ 3 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 .config/nvim/lua/custom/plugins/conform.lua delete mode 100644 .config/nvim/lua/custom/plugins/none-ls.lua create mode 100644 .config/nvim/lua/custom/plugins/nvim-lint.lua (limited to '.config/nvim/lua/custom') diff --git a/.config/nvim/lua/custom/plugins/conform.lua b/.config/nvim/lua/custom/plugins/conform.lua new file mode 100644 index 0000000..759f5ba --- /dev/null +++ b/.config/nvim/lua/custom/plugins/conform.lua @@ -0,0 +1,38 @@ +return { + 'stevearc/conform.nvim', + event = { 'BufWritePre' }, + cmd = { 'ConformInfo' }, + keys = { + { 'ft', 'FormatToggle', desc = '[F]ormat [T]oggle Globally' }, + { 'fT', 'FormatToggle!', desc = '[F]ormat [T]oggle Locally' }, + { 'ff', 'Format', desc = '[F]ormat [F]ile' }, + { 'f', 'Format', desc = '[F]ormat', mode = 'v' }, + }, + ---@module "conform" + ---@type conform.setupOpts + opts = { + formatters_by_ft = { + ['lua'] = { 'stylua' }, + ['c'] = { 'clang-format' }, + ['python'] = { 'isort', 'black' }, + ['rust'] = { 'rustfmt' }, + ['go'] = { 'gofumpt' }, + ['markdown'] = { 'prettierd', 'prettier', stop_after_first = true }, + ['yaml'] = { 'prettierd' }, + ['json'] = { 'jq' }, + ['html'] = { 'prettierd', 'prettier', stop_after_first = true }, + ['css'] = { 'prettierd', 'prettier', stop_after_first = true }, + ['javascript'] = { 'prettierd', 'prettier', stop_after_first = true }, + ['typescript'] = { 'prettierd', 'prettier', stop_after_first = true }, + }, + format_on_save = function(bufnr) + -- Disable with a global or buffer local variable + if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then + return + end + return { timeout_ms = 500, lsp_fallback = true } + end, + notify_on_error = true, + lsp_fallback = true, + }, +} diff --git a/.config/nvim/lua/custom/plugins/none-ls.lua b/.config/nvim/lua/custom/plugins/none-ls.lua deleted file mode 100644 index 763172f..0000000 --- a/.config/nvim/lua/custom/plugins/none-ls.lua +++ /dev/null @@ -1,12 +0,0 @@ -return { - 'nvimtools/none-ls.nvim', - event = 'LspAttach', - config = function() - local null_ls = require('null-ls') - null_ls.setup({ - sources = { - null_ls.builtins.formatting.stylua, - }, - }) - end, -} diff --git a/.config/nvim/lua/custom/plugins/nvim-lint.lua b/.config/nvim/lua/custom/plugins/nvim-lint.lua new file mode 100644 index 0000000..0ff280c --- /dev/null +++ b/.config/nvim/lua/custom/plugins/nvim-lint.lua @@ -0,0 +1,20 @@ +return { + 'mfussenegger/nvim-lint', + event = { 'BufReadPre', 'BufNewFile' }, + config = function() + local lint = require('lint') + lint.linters_by_ft = { + go = { 'golangci-lint' }, + python = { 'flake8' }, + json = { 'jsonlint' }, + bash = { 'shellcheck' }, + } + + vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost', 'InsertLeave', 'TextChanged', 'TextChangedI' }, { + group = vim.api.nvim_create_augroup('nvim-lint', { clear = true }), + callback = function() + require('lint').try_lint() + end, + }) + end, +} -- cgit v1.3.1