-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: make
conform.nvim
and nvim-lint
the default formatters/lin…
…ters
- Loading branch information
Showing
13 changed files
with
148 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
local Util = require("lazyvim.util") | ||
|
||
return { | ||
-- none-ls | ||
{ | ||
"nvimtools/none-ls.nvim", | ||
event = "LazyFile", | ||
dependencies = { "mason.nvim" }, | ||
init = function() | ||
Util.on_very_lazy(function() | ||
-- register the formatter with LazyVim | ||
require("lazyvim.util").format.register({ | ||
name = "none-ls.nvim", | ||
priority = 200, -- set higher than conform, the builtin formatter | ||
primary = true, | ||
format = function(buf) | ||
return Util.lsp.format({ | ||
bufnr = buf, | ||
filter = function(client) | ||
return client.name == "null-ls" | ||
end, | ||
}) | ||
end, | ||
sources = function(buf) | ||
local ret = require("null-ls.sources").get_available(vim.bo[buf].filetype, "NULL_LS_FORMATTING") or {} | ||
return vim.tbl_map(function(source) | ||
return source.name | ||
end, ret) | ||
end, | ||
}) | ||
end) | ||
end, | ||
opts = function(_, opts) | ||
local nls = require("null-ls") | ||
opts.root_dir = opts.root_dir | ||
or require("null-ls.utils").root_pattern(".null-ls-root", ".neoconf.json", "Makefile", ".git") | ||
opts.sources = vim.list_extend(opts.sources or {}, { | ||
nls.builtins.formatting.fish_indent, | ||
nls.builtins.diagnostics.fish, | ||
nls.builtins.formatting.stylua, | ||
nls.builtins.formatting.shfmt, | ||
}) | ||
end, | ||
}, | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
return { | ||
{ | ||
"mfussenegger/nvim-lint", | ||
event = "LazyFile", | ||
opts = { | ||
-- Event to trigger linters | ||
events = { "BufWritePost", "BufReadPost", "InsertLeave" }, | ||
linters_by_ft = { | ||
fish = { "fish" }, | ||
}, | ||
-- LazyVim extension to easily override linter options | ||
-- or add custom linters. | ||
---@type table<string,table> | ||
linters = { | ||
-- -- Example of using selene only when a selene.toml file is present | ||
-- selene = { | ||
-- -- `condition` is another LazyVim extension that allows you to | ||
-- -- dynamically enable/disable linters based on the context. | ||
-- condition = function(ctx) | ||
-- return vim.fs.find({ "selene.toml" }, { path = ctx.filename, upward = true })[1] | ||
-- end, | ||
-- }, | ||
}, | ||
}, | ||
config = function(_, opts) | ||
local M = {} | ||
|
||
local lint = require("lint") | ||
for name, linter in pairs(opts.linters) do | ||
if type(linter) == "table" and type(lint.linters) == "table" then | ||
lint.linters[name] = vim.tbl_deep_extend("force", lint.linters[name], linter) | ||
end | ||
end | ||
lint.linters_by_ft = opts.linters_by_ft | ||
|
||
function M.debounce(ms, fn) | ||
local timer = vim.loop.new_timer() | ||
return function(...) | ||
local argv = { ... } | ||
timer:start(ms, 0, function() | ||
timer:stop() | ||
vim.schedule_wrap(fn)(unpack(argv)) | ||
end) | ||
end | ||
end | ||
|
||
function M.lint() | ||
local names = lint.linters_by_ft[vim.bo.filetype] or {} | ||
local ctx = { filename = vim.api.nvim_buf_get_name(0) } | ||
ctx.dirname = vim.fn.fnamemodify(ctx.filename, ":h") | ||
names = vim.tbl_filter(function(name) | ||
local linter = lint.linters[name] | ||
return linter and not (type(linter) == "table" and linter.condition and not linter.condition(ctx)) | ||
end, names) | ||
|
||
if #names > 0 then | ||
lint.try_lint(names) | ||
end | ||
end | ||
|
||
vim.api.nvim_create_autocmd(opts.events, { | ||
group = vim.api.nvim_create_augroup("nvim-lint", { clear = true }), | ||
callback = M.debounce(100, M.lint), | ||
}) | ||
end, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters