From 5c803c01753b86c4dab7c35ab0150d1ef1e3227e Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Fri, 25 Jul 2025 14:27:36 +0545 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20nvim-lint=20for=20cod?= =?UTF-8?q?e=20linting=20and=20update=20auto-install=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 ++++++--- lua/plugins/lang/blink.lua | 27 ++++++++++++------- lua/plugins/lang/conform.lua | 4 +-- lua/plugins/lang/nvim-lint.lua | 31 ++++++++++++++++++++++ lua/plugins/list.lua | 48 ++++++++++++++++++++++------------ lua/plugins/lock.json | 3 +++ 6 files changed, 92 insertions(+), 33 deletions(-) create mode 100644 lua/plugins/lang/nvim-lint.lua diff --git a/README.md b/README.md index 39e8c6a..4df5425 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Handcrafted Neovim setup for the ultimate CLI dev experience. - **Pretty colors**: Comes with treesitter and onedark preconfigured with full transparency support - **Tmux integration**: Works with your tmux configurations out of the box - **Dev tools**: Comes with debugging, testing, database and REPL support, pick and choose -- **Auto install**: All necessary LSPs, Null LS sources, Treesitter Parsers etc. are auto installed +- **Auto install**: All necessary LSPs, Formatter, Linters, Treesitter Parsers etc. are auto installed - **User module**: Configure keycodex according to your needs by using the `user` module! - and some more @@ -70,8 +70,11 @@ local user = { user_lsp_servers = { -- Auto installed LSPs defined by user }, - user_null_ls_sources = { - -- Auto installed Null LS sources defined by user + user_formatter_sources = { + -- Auto installed formatter sources defined by user + }, + user_linter_sources = { + -- Auto installed lintere sources defined by user }, user_treesitter_parsers = { -- Auto installed Treesitter parsers defined by user @@ -120,4 +123,5 @@ You can check out the [plugins list file](./lua/plugins/list.lua) file to see th ## 🙏 Acknowledgments -This project builds upon [nvim2k](https://github.com/2KAbhishek/nvim2k) by [2KAbhishek](https://github.com/2KAbhishek/), enhancing it with additional features and optimizations. \ No newline at end of file +This project builds upon [nvim2k](https://github.com/2KAbhishek/nvim2k) by [2KAbhishek](https://github.com/2KAbhishek/), enhancing it with additional features and optimizations. + diff --git a/lua/plugins/lang/blink.lua b/lua/plugins/lang/blink.lua index efd5d67..de36bd8 100644 --- a/lua/plugins/lang/blink.lua +++ b/lua/plugins/lang/blink.lua @@ -59,18 +59,25 @@ blink.setup({ score_offset = 100, }, spell = { - name = 'spell', - module = 'blink.compat.source', - max_items = 10, - score_offset = -20, + name = 'Spell', + module = 'blink-cmp-spell', opts = { - keep_all_entries = true, -- don't filter it - -- enable_in_context = function() - -- return require("cmp.config.context").in_treesitter_capture "spell" - -- end, - preselect_correct_word = false, + -- EXAMPLE: Only enable source in `@spell` captures, and disable it + -- in `@nospell` captures. + enable_in_context = function() + local curpos = vim.api.nvim_win_get_cursor(0) + local captures = vim.treesitter.get_captures_at_pos(0, curpos[1] - 1, curpos[2] - 1) + local in_spell_capture = false + for _, cap in ipairs(captures) do + if cap.capture == 'spell' then + in_spell_capture = true + elseif cap.capture == 'nospell' then + return false + end + end + return in_spell_capture + end, }, - kind = 'Spell', }, }, }, diff --git a/lua/plugins/lang/conform.lua b/lua/plugins/lang/conform.lua index 0ec560b..448d108 100644 --- a/lua/plugins/lang/conform.lua +++ b/lua/plugins/lang/conform.lua @@ -15,8 +15,6 @@ conform.setup({ json = { 'prettier' }, yaml = { 'prettier' }, sh = { 'shfmt' }, - elixir = { 'mix' }, - -- ruby = { "rubocop" }, -- optional }, -- Autoformat on save @@ -28,7 +26,7 @@ conform.setup({ -- Setup mason-conform local auto_install = require('lib.util').get_user_config('auto_install', true) -local installed_formatters = require('plugins.list').null_ls_sources or {} +local installed_formatters = require('plugins.list').formatter_sources or {} require('mason-conform').setup({ ensure_installed = installed_formatters, diff --git a/lua/plugins/lang/nvim-lint.lua b/lua/plugins/lang/nvim-lint.lua new file mode 100644 index 0000000..41c9f50 --- /dev/null +++ b/lua/plugins/lang/nvim-lint.lua @@ -0,0 +1,31 @@ +local lint = require('lint') + +-- Filetype to linters mapping +lint.linters_by_ft = { + javascript = { 'eslint_d' }, + typescript = { 'eslint_d' }, + javascriptreact = { 'eslint_d' }, + typescriptreact = { 'eslint_d' }, + dockerfile = { 'hadolint' }, + vim = { 'vint' }, + markdown = { 'write_good', 'markdownlint' }, + text = { 'write_good' }, + sh = { 'shellcheck' }, + yaml = { 'actionlint' }, +} + +-- Trigger linting on save and buffer events +vim.api.nvim_create_autocmd({ 'BufWritePost', 'BufReadPost', 'InsertLeave' }, { + callback = function() + lint.try_lint() + end, +}) + +-- Setup mason-nvim-lint to auto-install linters +local auto_install = require('lib.util').get_user_config('auto_install', true) +local installed_linters = require('plugins.list').linter_sources or {} + +require('mason-nvim-lint').setup({ + ensure_installed = installed_linters, + automatic_installation = auto_install, +}) diff --git a/lua/plugins/list.lua b/lua/plugins/list.lua index b8121c2..fed19f2 100644 --- a/lua/plugins/list.lua +++ b/lua/plugins/list.lua @@ -130,14 +130,18 @@ local plugins = { config = load_config('lang.conform'), event = { 'BufReadPre', 'BufNewFile' }, }, - + { + 'mfussenegger/nvim-lint', + dependencies = { 'rshkarin/mason-nvim-lint' }, + config = load_config('lang.nvim-lint'), + event = { 'BufReadPost', 'BufNewFile' }, + }, { 'saghen/blink.cmp', dependencies = { 'rafamadriz/friendly-snippets', 'Kaiser-Yang/blink-cmp-avante', - 'windwp/nvim-ts-autotag', - 'f3fora/cmp-spell', + 'ribru17/blink-cmp-spell', { 'L3MON4D3/LuaSnip', config = function() @@ -245,6 +249,13 @@ local plugins = { }, }, }, + { + 'windwp/nvim-ts-autotag', + event = { 'BufReadPre', 'BufNewFile' }, + config = function() + require('nvim-ts-autotag').setup() + end, + }, { 'gbprod/substitute.nvim', event = { 'BufReadPre', 'BufNewFile' }, @@ -442,8 +453,20 @@ local treesitter_parsers = { 'yaml', } -local null_ls_sources = { +local linter_sources = { 'shellcheck', + 'write_good', + 'markdownlint', + 'eslint_d', + 'hadolint', + 'actionlint', + 'vint', +} + +local formatter_sources = { + 'prettier', + 'shfmt', + 'stylua', } local lsp_servers = { @@ -453,7 +476,7 @@ local lsp_servers = { 'vimls', 'lua_ls', 'qmlls', - 'tailwindcss', -- Add Tailwind CSS LSP + 'tailwindcss', } if util.is_present('npm') then @@ -461,11 +484,6 @@ if util.is_present('npm') then table.insert(lsp_servers, 'ts_ls') end -if util.is_present('gem') then - table.insert(lsp_servers, 'solargraph') - table.insert(lsp_servers, 'rubocop') -end - if util.is_present('go') then table.insert(lsp_servers, 'gopls') end @@ -484,22 +502,20 @@ if util.is_present('pip') then table.insert(lsp_servers, 'pylsp') end -if util.is_present('mix') then - table.insert(lsp_servers, 'elixirls') -end - if util.is_present('cargo') then table.insert(lsp_servers, 'rust_analyzer') end plugins = vim.tbl_extend('force', plugins, util.get_user_config('user_plugins', {})) lsp_servers = vim.tbl_extend('force', lsp_servers, util.get_user_config('user_lsp_servers', {})) -null_ls_sources = vim.tbl_extend('force', null_ls_sources, util.get_user_config('user_null_ls_sources', {})) +formatter_sources = vim.tbl_extend('force', formatter_sources, util.get_user_config('user_formatter_sources', {})) +linter_sources = vim.tbl_extend('force', linter_sources, util.get_user_config('user_linter_sources', {})) treesitter_parsers = vim.tbl_extend('force', treesitter_parsers, util.get_user_config('user_tresitter_parsers', {})) return { plugins = plugins, lsp_servers = lsp_servers, - null_ls_sources = null_ls_sources, + formatter_sources = formatter_sources, + linter_sources = linter_sources, ts_parsers = treesitter_parsers, } diff --git a/lua/plugins/lock.json b/lua/plugins/lock.json index ff79d07..2b8ad2a 100644 --- a/lua/plugins/lock.json +++ b/lua/plugins/lock.json @@ -5,6 +5,7 @@ "base46": { "branch": "v3.0", "commit": "cee12a263602cc97652d3dd55f0fc5e171012967" }, "blink-cmp-avante": { "branch": "master", "commit": "4f494c6e124acbe31a8f5d58effa0c14aa38a6d5" }, "blink-cmp-copilot": { "branch": "main", "commit": "439cff78780c033aa23cf061d7315314b347e3c1" }, + "blink-cmp-spell": { "branch": "master", "commit": "2bd0e0d5e7735c047e72b6918a0458f3e8fadaba" }, "blink.cmp": { "branch": "main", "commit": "bae4bae0eedd1fa55f34b685862e94a222d5c6f8" }, "ccc.nvim": { "branch": "main", "commit": "9d1a256e006decc574789dfc7d628ca11644d4c2" }, "codesnap.nvim": { "branch": "main", "commit": "be6d6b9a3b5e6999edbda76b16dace03d9bfcd3d" }, @@ -23,6 +24,7 @@ "markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" }, "mason-conform.nvim": { "branch": "main", "commit": "f3b96fa2217fcb1513301eefbe10ea0e765e33eb" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "bb3a17efc797c34c054463174e5522442576ebd8" }, + "mason-nvim-lint": { "branch": "main", "commit": "767b8ccdddaa977bec8987fd7507b9865a279235" }, "mason.nvim": { "branch": "main", "commit": "8024d64e1330b86044fed4c8494ef3dcd483a67c" }, "mdx.nvim": { "branch": "main", "commit": "464a74be368dce212cff02f6305845dc7f209ab3" }, "mini.ai": { "branch": "main", "commit": "e139eb1101beb0250fea322f8c07a42f0f175688" }, @@ -34,6 +36,7 @@ "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, "nvim-dap": { "branch": "master", "commit": "99807078c5089ed30e0547aa4b52c5867933f426" }, "nvim-dbee": { "branch": "master", "commit": "9656fc59841291e9dbd2f3b50b1cb4c77d9fea79" }, + "nvim-lint": { "branch": "master", "commit": "9c6207559297b24f0b7c32829f8e45f7d65b991f" }, "nvim-lspconfig": { "branch": "master", "commit": "4d3b3bb8815fbe37bcaf3dbdb12a22382bc11ebe" }, "nvim-spectre": { "branch": "master", "commit": "72f56f7585903cd7bf92c665351aa585e150af0f" }, "nvim-spider": { "branch": "main", "commit": "6da0307421bc4be6fe02815faabde51007c4ea1a" },