✨ feat(lint): configure nvim-lint with codespell, editorconfig-checker and file-specific configs

This commit is contained in:
sankalp committed 2025-07-25 14:54:18 +05:45
1 parent a473b50c4c
commit 76697b1381
4 files changed
+52 -15

No files matched your search

+2 -1
View File
@@ -14,7 +14,8 @@ conform.setup({
html = { 'prettier' },
json = { 'prettier' },
yaml = { 'prettier' },
sh = { 'shfmt' },
sh = { 'shfmt', 'shellcheck' },
['_'] = { 'trim_whitespace', lsp_format = 'prefer' },
},
-- Autoformat on save
+42 -13
View File
@@ -14,23 +14,52 @@ lint.linters_by_ft = {
yaml = { 'actionlint' },
}
-- Trigger linting on save and buffer events
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
callback = function()
local lint = require('lint')
table.insert(
require('lint').linters.codespell.args,
1,
'--config=' .. vim.fs.joinpath(require('dotfyls.files').config_dir, 'codespell', '.codespellrc')
)
table.insert(require('lint').linters.vala_lint.args, 1, '--config=vala-lint.conf')
table.insert(
require('lint').linters.yamllint.args,
1,
'--config-file=' .. vim.fs.joinpath(require('dotfyls.files').config_dir, 'yamllint', 'config.yaml')
)
-- Get the filetype-specific linters
local ft = vim.bo.filetype
local linters = lint.linters_by_ft[ft] or {}
local function lint(bufnr)
local linters =
vim.list_extend({ 'codespell', 'editorconfig-checker' }, require('lint')._resolve_linter_by_ft(vim.bo.filetype))
-- Add cspell if it's not already included
if not vim.tbl_contains(linters, 'cspell') then
table.insert(linters, 'cspell')
end
local ctx = { filename = vim.api.nvim_buf_get_name(bufnr or 0) }
ctx.dirname = vim.fn.fnamemodify(ctx.filename, ':h')
-- Run them all
lint.try_lint(linters)
linters = vim.tbl_filter(function(name)
local linter = require('lint').linters[name]
return vim.fn.executable(linter.cmd) == 1
---@diagnostic disable-next-line: undefined-field
and not (type(linter) == 'table' and linter.condition and not linter.condition(ctx))
end, linters)
if #linters > 0 then
require('lint').try_lint(linters)
end
end
lint()
local timer = assert(vim.uv.new_timer())
vim.api.nvim_create_autocmd({ 'BufReadPost', 'BufWritePost', 'InsertLeave' }, {
group = require('dotfyls.interop').group,
callback = function(args)
timer:start(100, 0, function()
timer:stop()
vim.schedule(function()
lint(args.buf)
end)
end)
end,
desc = 'Lint (nvim-lint)',
})
-- Setup mason-nvim-lint to auto-install linters
+7
View File
@@ -126,6 +126,11 @@ local plugins = {
{
'mfussenegger/nvim-lint',
dependencies = { 'rshkarin/mason-nvim-lint' },
init = function()
if vim.fn.executable('codespell') == 1 then
vim.o.spell = false
end
end,
config = load_config('lang.nvim-lint'),
event = { 'BufReadPost', 'BufNewFile' },
},
@@ -454,6 +459,8 @@ local linter_sources = {
'hadolint',
'actionlint',
'vint',
'codespell',
'editorconfig-checker',
}
local formatter_sources = {
+1 -1
View File
@@ -63,7 +63,7 @@ local normal_mappings = {
{ '<leader>cc', ':CccHighlighterToggle<cr>', desc = 'Highlight Colors' },
{ '<leader>cd', ':RootDir<cr>', desc = 'Root Directory' },
{ '<leader>ce', ':%SnipRun<cr>', desc = 'Execute File' },
{ '<leader>cf', ':lua vim.lsp.buf.format({async = true})<cr>', desc = 'Format File' },
-- { '<leader>cf', ':lua vim.lsp.buf.format({async = true})<cr>', desc = 'Format File' },
{ '<leader>cl', '::g/^\\s*$/d<cr>', desc = 'Clean Empty Lines' },
{ '<leader>cm', ':MarkdownPreviewToggle<cr>', desc = 'Markdown Preview' },
{ '<leader>co', ':Dashboard<cr>', desc = 'Dashboard' },