diff options
Diffstat (limited to 'dot_config/nvim/lua/plugins/lint.lua')
| -rw-r--r-- | dot_config/nvim/lua/plugins/lint.lua | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/dot_config/nvim/lua/plugins/lint.lua b/dot_config/nvim/lua/plugins/lint.lua new file mode 100644 index 0000000..7d337ac --- /dev/null +++ b/dot_config/nvim/lua/plugins/lint.lua @@ -0,0 +1,80 @@ +return { + { + 'mfussenegger/nvim-lint', + event = { 'BufReadPre', 'BufNewFile' }, + config = function() + require('lint').linters.mdl = { + cmd = 'mdl', + stdin = false, + args = { '-s', '~/.config/mdl/style.rb' }, + stream = 'stdout', + ignore_exitcode = true, + parser = require('lint.parser').from_errorformat('%f:%l: %m', { + source = 'mdl', + severity = vim.diagnostic.severity.WARN, + }), + } + local lint = require 'lint' + lint.linters_by_ft = { + markdown = { 'mdl' }, + } + + -- Create autocommand which carries out the actual linting + -- on the specified events. + local lint_augroup = vim.api.nvim_create_augroup('lint', { clear = true }) + vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost', 'InsertLeave' }, { + group = lint_augroup, + callback = function() + -- Only run the linter in buffers that you can modify in order to + -- avoid superfluous noise, notably within the handy LSP pop-ups that + -- describe the hovered symbol using Markdown. + if vim.bo.modifiable then + lint.try_lint() + end + end, + }) + end, + }, + + -- Autoformat + { + 'stevearc/conform.nvim', + event = { 'BufWritePre' }, + cmd = { 'ConformInfo' }, + keys = { + { + '<leader>f', + function() + require('conform').format { async = true, lsp_format = 'fallback' } + end, + mode = '', + desc = '[F]ormat buffer', + }, + }, + opts = { + notify_on_error = false, + format_on_save = function(bufnr) + -- Disable "format_on_save lsp_fallback" for languages that don't + -- have a well standardized coding style. You can add additional + -- languages here or re-enable it for the disabled ones. + local disable_filetypes = { c = true, cpp = true } + if disable_filetypes[vim.bo[bufnr].filetype] then + return nil + else + return { + timeout_ms = 500, + lsp_format = 'fallback', + } + end + end, + formatters_by_ft = { + lua = { 'stylua' }, + -- Conform can also run multiple formatters sequentially + -- python = { "isort", "black" }, + -- + -- You can use 'stop_after_first' to run the first available formatter from the list + -- javascript = { "prettierd", "prettier", stop_after_first = true }, + }, + }, + }, +} |