Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to ignore a list of linters during install #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Using this configuration, linters specified in `ensure_installed` will be instal
```lua
require ('mason-nvim-lint').setup({
ensure_installed = { 'bacon' }, -- bacon linter for rust is not available in nvim-lint, so it's specified to be directly installed from the mason's registry
ignore_install = { 'custom-linter' }, -- avoid trying to install an unknown linter
})
```

Expand Down
36 changes: 24 additions & 12 deletions lua/mason-nvim-lint/auto_install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,35 @@ local nvim_lint = require "lint"
local mapping = require "mason-nvim-lint.mapping"
local settings = require "mason-nvim-lint.settings"

local function linters_to_install(linters_by_ft)
local kept_linters = {}

for _, linter_names in pairs(linters_by_ft) do
for _, linter_name in ipairs(linter_names) do
if not vim.tbl_contains(settings.current.ignore_install, linter_name) then
table.insert(kept_linters, linter_name)
end
end
end

return ipairs(kept_linters)
end

--@return unknown_linters string[]
local function auto_install()
local unknown_linters = {}
local installing_linters = {}

for _, linter_names in pairs(nvim_lint.linters_by_ft) do
for _, linter_name in ipairs(linter_names) do
local mason_linter_identifier = mapping.nvimlint_to_package[linter_name]
if mason_linter_identifier then
if not vim.tbl_contains(installing_linters, mason_linter_identifier) then
table.insert(installing_linters, mason_linter_identifier)
require "mason-nvim-lint.install".try_install(mason_linter_identifier)
end
else
if not vim.tbl_contains(unknown_linters, linter_name) then
table.insert(unknown_linters, linter_name)
end
for _, linter_name in linters_to_install(nvim_lint.linters_by_ft) do
local mason_linter_identifier = mapping.nvimlint_to_package[linter_name]
if mason_linter_identifier then
if not vim.tbl_contains(installing_linters, mason_linter_identifier) then
table.insert(installing_linters, mason_linter_identifier)
require "mason-nvim-lint.install".try_install(mason_linter_identifier)
end
else
if not vim.tbl_contains(unknown_linters, linter_name) then
table.insert(unknown_linters, linter_name)
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions lua/mason-nvim-lint/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ local DEFAULT_SETTINGS = {
-- Disables warning notifications about misconfigurations such as invalid linter entries and incorrect plugin load order.
---@type boolean
quiet_mode = false,

-- A list of linters to not install using Mason.
-- This setting has no relation with the`ensure_installed` setting.
-- It will only impacts linters set up via nvim-lint.
ignore_install = {},
}

M._DEFAULT_SETTINGS = DEFAULT_SETTINGS
Expand Down