✨ feat(lint): configure nvim-lint with codespell, editorconfig-checker and file-specific configs
This commit is contained in:
4 files changed
+52
-15
No files matched your search
@@ -14,7 +14,8 @@ conform.setup({
|
|||||||
html = { 'prettier' },
|
html = { 'prettier' },
|
||||||
json = { 'prettier' },
|
json = { 'prettier' },
|
||||||
yaml = { 'prettier' },
|
yaml = { 'prettier' },
|
||||||
sh = { 'shfmt' },
|
sh = { 'shfmt', 'shellcheck' },
|
||||||
|
['_'] = { 'trim_whitespace', lsp_format = 'prefer' },
|
||||||
},
|
},
|
||||||
|
|
||||||
-- Autoformat on save
|
-- Autoformat on save
|
||||||
|
|||||||
@@ -14,23 +14,52 @@ lint.linters_by_ft = {
|
|||||||
yaml = { 'actionlint' },
|
yaml = { 'actionlint' },
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Trigger linting on save and buffer events
|
table.insert(
|
||||||
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
|
require('lint').linters.codespell.args,
|
||||||
callback = function()
|
1,
|
||||||
local lint = require('lint')
|
'--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 function lint(bufnr)
|
||||||
local ft = vim.bo.filetype
|
local linters =
|
||||||
local linters = lint.linters_by_ft[ft] or {}
|
vim.list_extend({ 'codespell', 'editorconfig-checker' }, require('lint')._resolve_linter_by_ft(vim.bo.filetype))
|
||||||
|
|
||||||
-- Add cspell if it's not already included
|
local ctx = { filename = vim.api.nvim_buf_get_name(bufnr or 0) }
|
||||||
if not vim.tbl_contains(linters, 'cspell') then
|
ctx.dirname = vim.fn.fnamemodify(ctx.filename, ':h')
|
||||||
table.insert(linters, 'cspell')
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Run them all
|
linters = vim.tbl_filter(function(name)
|
||||||
lint.try_lint(linters)
|
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,
|
end,
|
||||||
|
desc = 'Lint (nvim-lint)',
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Setup mason-nvim-lint to auto-install linters
|
-- Setup mason-nvim-lint to auto-install linters
|
||||||
|
|||||||
@@ -126,6 +126,11 @@ local plugins = {
|
|||||||
{
|
{
|
||||||
'mfussenegger/nvim-lint',
|
'mfussenegger/nvim-lint',
|
||||||
dependencies = { 'rshkarin/mason-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'),
|
config = load_config('lang.nvim-lint'),
|
||||||
event = { 'BufReadPost', 'BufNewFile' },
|
event = { 'BufReadPost', 'BufNewFile' },
|
||||||
},
|
},
|
||||||
@@ -454,6 +459,8 @@ local linter_sources = {
|
|||||||
'hadolint',
|
'hadolint',
|
||||||
'actionlint',
|
'actionlint',
|
||||||
'vint',
|
'vint',
|
||||||
|
'codespell',
|
||||||
|
'editorconfig-checker',
|
||||||
}
|
}
|
||||||
|
|
||||||
local formatter_sources = {
|
local formatter_sources = {
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ local normal_mappings = {
|
|||||||
{ '<leader>cc', ':CccHighlighterToggle<cr>', desc = 'Highlight Colors' },
|
{ '<leader>cc', ':CccHighlighterToggle<cr>', desc = 'Highlight Colors' },
|
||||||
{ '<leader>cd', ':RootDir<cr>', desc = 'Root Directory' },
|
{ '<leader>cd', ':RootDir<cr>', desc = 'Root Directory' },
|
||||||
{ '<leader>ce', ':%SnipRun<cr>', desc = 'Execute File' },
|
{ '<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>cl', '::g/^\\s*$/d<cr>', desc = 'Clean Empty Lines' },
|
||||||
{ '<leader>cm', ':MarkdownPreviewToggle<cr>', desc = 'Markdown Preview' },
|
{ '<leader>cm', ':MarkdownPreviewToggle<cr>', desc = 'Markdown Preview' },
|
||||||
{ '<leader>co', ':Dashboard<cr>', desc = 'Dashboard' },
|
{ '<leader>co', ':Dashboard<cr>', desc = 'Dashboard' },
|
||||||
|
|||||||
Reference in new issue
Block a user