From 8d4aa4ebbc597837a4d40c9c244e62c282a7d991 Mon Sep 17 00:00:00 2001 From: Vincent Capelle Date: Sun, 17 Nov 2024 02:06:35 -0500 Subject: [PATCH] feat: add linting Neovim configuration --- vim/lazy-lock.json | 1 + vim/lua/plugins/lint.lua | 33 +++++++++++++++++++++++++++++++++ vim/lua/plugins/lsp.lua | 1 + 3 files changed, 35 insertions(+) create mode 100644 vim/lua/plugins/lint.lua diff --git a/vim/lazy-lock.json b/vim/lazy-lock.json index ab4cb58..3de2d07 100644 --- a/vim/lazy-lock.json +++ b/vim/lazy-lock.json @@ -20,6 +20,7 @@ "mini.icons": { "branch": "main", "commit": "a2742459f0ee32806c2438ca06b4d8b331f3f4d4" }, "nvim-cmp": { "branch": "main", "commit": "983453e32cb35533a119725883c04436d16c0120" }, "nvim-highlight-colors": { "branch": "main", "commit": "e967e2ba13fd4ca731b41d0e5cc1ac2edcd6e25e" }, + "nvim-lint": { "branch": "master", "commit": "36da8dd0ddc4f88e0beae234c20e75397326f143" }, "nvim-lspconfig": { "branch": "master", "commit": "056f569f71e4b726323b799b9cfacc53653bceb3" }, "nvim-solarized-lua": { "branch": "master", "commit": "d69a263c97cbc765ca442d682b3283aefd61d4ac" }, "nvim-treesitter": { "branch": "master", "commit": "cfc6f2c117aaaa82f19bcce44deec2c194d900ab" }, diff --git a/vim/lua/plugins/lint.lua b/vim/lua/plugins/lint.lua new file mode 100644 index 0000000..d0c0f4e --- /dev/null +++ b/vim/lua/plugins/lint.lua @@ -0,0 +1,33 @@ +return { + { + "mfussenegger/nvim-lint", + event = { "BufReadPre", "BufNewFile" }, + config = function() + local lint = require("lint") + lint.linters_by_ft = { + dockerfile = { "hadolint" }, + json = { "jsonlint" }, + markdown = { "markdownlint" }, + terraform = { "tflint" }, + } + + -- 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.opt_local.modifiable:get() then + lint.try_lint() + end + end, + } + ) + end, + }, +} diff --git a/vim/lua/plugins/lsp.lua b/vim/lua/plugins/lsp.lua index 6a14fc4..3192471 100644 --- a/vim/lua/plugins/lsp.lua +++ b/vim/lua/plugins/lsp.lua @@ -169,6 +169,7 @@ return { "stylua", -- Lua --linters "flake8", -- Python + "hadolint", -- Dockerfile "jsonlint", -- Json "markdownlint", -- Markdown "tflint", -- Terraform