Skip to content

Commit

Permalink
nvim: fix linter and formatter install
Browse files Browse the repository at this point in the history
  • Loading branch information
chris468 committed Jun 24, 2024
1 parent 25ff227 commit 3b65b53
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ local function format()
conform.format({ lsp_fallback = true, timeout_ms = 1500 })
end

--- @type { [string]: chris468.util.mason.Tool}
--- @type chris468.util.mason.ToolsForFiletype
local formatters_by_ft = {
lua = { "stylua" },
python = { "black" },
javascript = { { "prettierd", "prettier" } },
javascript = { "prettierd" },
}

return {
Expand Down
28 changes: 15 additions & 13 deletions dotfiles/private_dot_config/nvim/lua/chris468/plugins/nvim-lint.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local tools = require("chris468.config.lang").tools

--- @return chris468.util.mason.ToolsForFiletype
function get_linters()
local function get_linters()
local result = {}
for ft, t in pairs(tools) do
result[ft] = t.lint
Expand Down Expand Up @@ -32,20 +32,22 @@ return {
{
"williamboman/mason.nvim",
opts = function(_, opts)
local linters_to_install = {}
for ft, linters in pairs(linters_by_ft) do
linters_to_install[ft] = {}
for _, l in ipairs(linters) do
linters_to_install[ft][#linters_to_install[ft] + 1] = {
l,
callback = function()
local lint = require("lint")
lint.try_lint()
end,
}
end
local function try_lint()
local lint = require("lint")
lint.try_lint()
end

--- @type chris468.util.mason.ToolsForFiletype
local linters_to_install = vim.tbl_map(function(linters)
return vim.tbl_map(function(linter)
--- @type chris468.util.mason.Tool
return {
package_name = linter,
callback = try_lint,
}
end, linters)
end, linters_by_ft)

opts.install_for_filetype = vim.tbl_extend("error", opts.install_for_filetype or {}, {
linter = linters_to_install,
})
Expand Down

0 comments on commit 3b65b53

Please sign in to comment.