feat(plugins): integrate ruff via mason-tool-installer and configure Python formatting

This commit is contained in:
Prad Nukala committed 2026-08-24 15:21:55 -04:00
1 parent 96d6dc2270
commit c442ad6ac9
1 file changed
+16
+16
View File
@@ -79,6 +79,15 @@ end
---@type LazySpec ---@type LazySpec
return { return {
-- ruff is both the import sorter and the formatter used for python below
{
"WhoIsSethDaniel/mason-tool-installer.nvim",
optional = true,
opts = function(_, opts)
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, { "ruff" })
end,
},
{
"stevearc/conform.nvim", "stevearc/conform.nvim",
init = function() init = function()
vim.api.nvim_create_autocmd("BufWritePre", { vim.api.nvim_create_autocmd("BufWritePre", {
@@ -92,6 +101,12 @@ return {
}) })
end, end,
opts = function(_, opts) opts = function(_, opts)
-- Python: ruff sorts imports (I001), then reformats. ruff always emits
-- 4-space indentation, so mixed tab/space indentation is normalized on
-- save instead of surviving to raise TabError at runtime.
if not opts.formatters_by_ft then opts.formatters_by_ft = {} end
opts.formatters_by_ft.python = { "ruff_organize_imports", "ruff_format" }
-- Skip format-on-save for JavaScript buffers (.js/.mjs/.cjs); manual -- Skip format-on-save for JavaScript buffers (.js/.mjs/.cjs); manual
-- :Format / <Leader>lf still works. Wraps the astrocommunity pack's -- :Format / <Leader>lf still works. Wraps the astrocommunity pack's
-- format_on_save so its autoformat toggle handling is preserved. -- format_on_save so its autoformat toggle handling is preserved.
@@ -102,4 +117,5 @@ return {
return pack_format_on_save return pack_format_on_save
end end
end, end,
},
} }