fixes eslint config
This commit is contained in:
parent
1964da885c
commit
eb96f296f4
1 changed files with 48 additions and 1 deletions
|
|
@ -5,11 +5,58 @@ return {
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
local null_ls = require("null-ls")
|
local null_ls = require("null-ls")
|
||||||
|
local utils = require("dnsc.utils")
|
||||||
|
|
||||||
|
local string_starts_with = function(str, start)
|
||||||
|
return string.sub(str, 1, #start) == start
|
||||||
|
end
|
||||||
|
|
||||||
|
local create_runtime_condition = function(config_names)
|
||||||
|
local bufnr_cache = {}
|
||||||
|
local config_path_cache = {}
|
||||||
|
|
||||||
|
return function(params)
|
||||||
|
if bufnr_cache[params.bufnr] ~= nil then
|
||||||
|
return bufnr_cache[params.bufnr]
|
||||||
|
else
|
||||||
|
for _, cached_config_path in ipairs(config_path_cache) do
|
||||||
|
if string_starts_with(params.bufname, cached_config_path) then
|
||||||
|
bufnr_cache[params.bufnr] = true
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local config_path = utils.root_pattern(config_names)(params.bufname)
|
||||||
|
|
||||||
|
local has_config = config_path ~= nil
|
||||||
|
if has_config then
|
||||||
|
table.insert(config_path_cache, config_path)
|
||||||
|
end
|
||||||
|
bufnr_cache[params.bufnr] = has_config
|
||||||
|
|
||||||
|
return has_config
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local eslint_runtime_condition = create_runtime_condition({
|
||||||
|
".eslintrc.cjs",
|
||||||
|
".eslintrc.js",
|
||||||
|
".eslintrc.json",
|
||||||
|
".eslintrc.yaml",
|
||||||
|
".eslintrc.yml",
|
||||||
|
"eslint.config.mjs",
|
||||||
|
"eslint.config.js",
|
||||||
|
"eslint.config.ts",
|
||||||
|
"eslint.config.mts",
|
||||||
|
})
|
||||||
|
|
||||||
null_ls.setup({
|
null_ls.setup({
|
||||||
sources = {
|
sources = {
|
||||||
require("none-ls.code_actions.eslint_d"),
|
require("none-ls.code_actions.eslint_d"),
|
||||||
require("none-ls.diagnostics.eslint_d"),
|
require("none-ls.diagnostics.eslint_d").with({
|
||||||
|
runtime_condition = eslint_runtime_condition,
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue