- replaced null-ls with none-ls

- added deprecated formatters and diagnostics
This commit is contained in:
2025-03-30 02:19:08 -05:00
parent 5e9fef9a01
commit dd0925b166
4 changed files with 182 additions and 34 deletions
+8 -32
View File
@@ -315,38 +315,18 @@ function M.null_ls()
local null_ls = require("null-ls")
local config = lsp_config_defaults()
local h = require("null-ls.helpers")
local methods = require("null-ls.methods")
local FORMATTING = methods.internal.FORMATTING
local templ_fmt = h.make_builtin({
name = "templ",
method = FORMATTING,
filetypes = { "templ" },
generator_opts = {
command = "templ",
args = { "fmt" },
to_stdin = true,
},
factory = h.formatter_factory,
})
local builtins = require("plugins.null_ls_builtins")
local formatters = builtins.formatters
local diagnostics = builtins.diagnostics
-- ORDER IN TABLE DETERMINES EXECUTION ORDER
local sources = {
-- python
null_ls.builtins.diagnostics.ruff.with({
args = { "check", "-n", "-e", "--stdin-filename", "$FILENAME", "-" },
}),
null_ls.builtins.formatting.ruff.with({
args = { "format", "--stdin-filename", "$FILENAME", "-" },
}),
null_ls.builtins.formatting.ruff.with({
args = { "check", "--select", "I", "--fix", "--stdin-filename", "$FILENAME", "-" },
}),
diagnostics.ruff(),
formatters.ruff_imports(),
formatters.ruff_code(),
-- js
null_ls.builtins.diagnostics.eslint,
null_ls.builtins.code_actions.eslint,
null_ls.builtins.formatting.prettier.with({
extra_filetypes = { "svelte" },
extra_args = { "--tab-width", "4" },
@@ -357,8 +337,7 @@ function M.null_ls()
-- bash
null_ls.builtins.formatting.shfmt,
null_ls.builtins.diagnostics.shellcheck,
null_ls.builtins.code_actions.shellcheck,
diagnostics.shellcheck(),
-- cpp
null_ls.builtins.formatting.clang_format,
@@ -366,7 +345,7 @@ function M.null_ls()
-- golang
--null_ls.builtins.diagnostics.golangci_lint,
null_ls.builtins.formatting.gofmt,
templ_fmt,
formatters.templ(),
-- sql
-- null_ls.builtins.diagnostics.sqlfluff.with(sqlfluff_args),
@@ -378,9 +357,6 @@ function M.null_ls()
null_ls.builtins.diagnostics.credo,
null_ls.builtins.formatting.mix,
-- zig
null_ls.builtins.formatting.zigfmt,
-- c_sharp
null_ls.builtins.formatting.csharpier,
}
+1 -1
View File
@@ -61,7 +61,7 @@ function M.install_plugins()
},
"nvim-treesitter/nvim-treesitter-context",
"nvim-treesitter/playground",
"jose-elias-alvarez/null-ls.nvim",
"nvimtools/none-ls.nvim",
"windwp/nvim-autopairs",
{
+172
View File
@@ -0,0 +1,172 @@
local M = {}
local h = require("null-ls.helpers")
local methods = require("null-ls.methods")
local DIAGNOSTICS = methods.internal.DIAGNOSTICS
local FORMATTING = methods.internal.FORMATTING
M.diagnostics = {
ruff = function()
local custom_end_col = {
end_col = function(entries, line)
if not line then
return
end
local start_col = entries["col"]
local message = entries["message"]
local code = entries["code"]
local default_position = start_col + 1
local pattern = nil
local trimmed_line = line:sub(start_col, -1)
if code == "F841" or code == "F823" then
pattern = [[Local variable %`(.*)%`]]
elseif code == "F821" or code == "F822" then
pattern = [[Undefined name %`(.*)%`]]
elseif code == "F401" then
pattern = [[%`(.*)%` imported but unused]]
elseif code == "F841" then
pattern = [[Local variable %`(.*)%` is assigned to but never used]]
end
if not pattern then
return default_position
end
local results = message:match(pattern)
local _, end_col = trimmed_line:find(results, 1, true)
if not end_col then
return default_position
end
end_col = end_col + start_col
if end_col > tonumber(start_col) then
return end_col
end
return default_position
end,
}
return h.make_builtin({
name = "ruff",
meta = {
url = "https://github.com/charliermarsh/ruff/",
description = "An extremely fast Python linter, written in Rust.",
},
method = DIAGNOSTICS,
filetypes = { "python" },
generator_opts = {
command = "ruff",
args = { "check", "-n", "-e", "--stdin-filename", "$FILENAME", "-" },
format = "line",
check_exit_code = function(code)
return code == 0
end,
to_stdin = true,
ignore_stderr = true,
on_output = h.diagnostics.from_pattern(
[[(%d+):(%d+): ((%u)%w+) (.*)]],
{ "row", "col", "code", "severity", "message" },
{
adapters = {
custom_end_col,
},
severities = {
E = h.diagnostics.severities["error"], -- pycodestyle errors
W = h.diagnostics.severities["warning"], -- pycodestyle warnings
F = h.diagnostics.severities["information"], -- pyflakes
A = h.diagnostics.severities["information"], -- flake8-builtins
B = h.diagnostics.severities["warning"], -- flake8-bugbear
C = h.diagnostics.severities["warning"], -- flake8-comprehensions
T = h.diagnostics.severities["information"], -- flake8-print
U = h.diagnostics.severities["information"], -- pyupgrade
D = h.diagnostics.severities["information"], -- pydocstyle
M = h.diagnostics.severities["information"], -- Meta
},
}
),
},
factory = h.generator_factory,
})
end,
shellcheck = function()
return h.make_builtin({
name = "shellcheck",
meta = {
url = "https://www.shellcheck.net/",
description = "A shell script static analysis tool.",
},
method = DIAGNOSTICS,
filetypes = { "sh" },
generator_opts = {
command = "shellcheck",
args = { "--format", "json1", "--source-path=$DIRNAME", "--external-sources", "-" },
to_stdin = true,
format = "json",
check_exit_code = function(code)
return code <= 1
end,
on_output = function(params)
local parser = h.diagnostics.from_json({
attributes = { code = "code" },
severities = {
info = h.diagnostics.severities["information"],
style = h.diagnostics.severities["hint"],
},
})
return parser({ output = params.output.comments })
end,
},
factory = h.generator_factory,
})
end,
}
M.formatters = {
templ = function()
return h.make_builtin({
name = "templ",
method = FORMATTING,
filetypes = { "templ" },
generator_opts = {
command = "templ",
args = { "fmt" },
to_stdin = true,
},
factory = h.formatter_factory,
})
end,
ruff_code = function()
return h.make_builtin({
name = "ruff",
method = FORMATTING,
filetypes = { "python" },
generator_opts = {
command = "ruff",
args = { "format", "--stdin-filename", "$FILENAME", "-" },
to_stdin = true,
},
factory = h.formatter_factory,
})
end,
ruff_imports = function()
return h.make_builtin({
name = "ruff",
method = FORMATTING,
filetypes = { "python" },
generator_opts = {
command = "ruff",
args = { "check", "--select", "I", "--fix", "--stdin-filename", "$FILENAME", "-" },
to_stdin = true,
},
factory = h.formatter_factory,
})
end,
}
return M