Skip to content

Commit

Permalink
Install all linters (#309)
Browse files Browse the repository at this point in the history
* fix(nvim-lint): add/correct some linters

Squashed commit of the following:

commit 5d6c844978b0b7a8acfc607cbfdab3dfb63d8392
Author: Leonardo Mora <[email protected]>
Date:   Mon Jul 8 12:09:01 2024 -0600

    feat(nvim-lint): add snyk and htmlhint

    See: rshkarin/mason-nvim-lint#8

commit 984d655b220a3b235b81fcbcc6c3eb0c3d9a0e0c
Author: Leonardo Mora <[email protected]>
Date:   Mon Jul 8 11:57:02 2024 -0600

    fix(nvim-lint): correct ansible-lint mapping

    See: rshkarin/mason-nvim-lint#9

commit 806b42fa650f97a8bac445bd727552261dee81ec
Author: Leonardo Mora <[email protected]>
Date:   Mon Jul 8 11:55:03 2024 -0600

    feat(nvim-lint): add checkmake

    Linter for Makefiles. See: rshkarin/mason-nvim-lint#10

commit a376b63f49fd02f3502b006108fc373b1efb5611
Author: Leonardo Mora <[email protected]>
Date:   Sun Jul 7 19:41:15 2024 -0600

    refactor(formatters): better name

* fix(MasonInstallAll): fix linters installation. Fixes #308

* refactor(get_pkgs): expose this function

I find this extremely useful. So added this to have access to this
table.

* refactor(get_pkgs): consider data when handling duplicates

The way it was, you could end up with duplicates introduced by the
incoming data list.

* refactor: no need to re-assign the source table when using
vim.list_extend
  • Loading branch information
LeonardoMor authored Jul 9, 2024
1 parent 8374b29 commit 0430df7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
16 changes: 8 additions & 8 deletions lua/nvchad/mason/init.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
local M = {}
local masonames = require "nvchad.mason.names"

local get_pkgs = function(data)
M.get_pkgs = function(data)
local tools = {}

local lsps = require("lspconfig.util").available_servers()
tools = vim.list_extend(tools, lsps)
vim.list_extend(tools, lsps)

local conform_exists, conform = pcall(require, "conform")

if conform_exists then
local formatters = conform.list_all_formatters()

local formatters_names = vim.tbl_map(function(formatter)
local formatter_names = vim.tbl_map(function(formatter)
return formatter.name
end, formatters)

tools = vim.list_extend(tools, formatters_names)
vim.list_extend(tools, formatter_names)
end

local lint_exists, lint = pcall(require, "lint")
Expand All @@ -25,11 +25,11 @@ local get_pkgs = function(data)
local linters = lint.linters_by_ft

for _, v in pairs(linters) do
table.insert(tools, v[1])
vim.list_extend(tools, v)
end
end

local pkgs = {}
local pkgs = data or {}

-- rm duplicates
for _, v in pairs(tools) do
Expand All @@ -38,7 +38,7 @@ local get_pkgs = function(data)
end
end

return vim.list_extend(pkgs, data or {})
return pkgs
end

M.install_all = function(data)
Expand All @@ -47,7 +47,7 @@ M.install_all = function(data)
local mr = require "mason-registry"

mr.refresh(function()
for _, tool in ipairs(get_pkgs(data)) do
for _, tool in ipairs(M.get_pkgs(data)) do
local p = mr.get_package(tool)

if not p:is_installed() then
Expand Down
5 changes: 4 additions & 1 deletion lua/nvchad/mason/names.lua
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ return {

-- nvim-lint
actionlint = "actionlint",
ansible_lint = "ansible_lint",
ansible_lint = "ansible-lint",
buf_lint = "buf",
["cfn_lint"] = "cfn-lint",
checkstyle = "checkstyle",
Expand All @@ -346,6 +346,7 @@ return {
gdlint = "gdtoolkit",
golangcilint = "golangci-lint",
hadolint = "hadolint",
htmlhint = "htmlhint",
jsonlint = "jsonlint",
luacheck = "luacheck",
mypy = "mypy",
Expand All @@ -358,11 +359,13 @@ return {
revive = "revive",
rstcheck = "rstcheck",
selene = "selene",
snyk = "snyk",
solhint = "solhint",
tfsec = "tfsec",
trivy = "trivy",
vale = "vale",
vint = "vint",
vulture = "vulture",
yamllint = "yamllint",
checkmake = "checkmake",
}

0 comments on commit 0430df7

Please sign in to comment.