mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-09-06 10:21:31 +00:00
nvim_lint: moved the function into a separate option "lint_function"
This commit is contained in:
parent
8961142817
commit
f830553166
3 changed files with 58 additions and 38 deletions
|
@ -289,8 +289,9 @@
|
||||||
[rice-cracker-dev](https://github.com/rice-cracker-dev):
|
[rice-cracker-dev](https://github.com/rice-cracker-dev):
|
||||||
|
|
||||||
- `eslint_d` now checks for configuration files to load.
|
- `eslint_d` now checks for configuration files to load.
|
||||||
- Fixed an error where `eslint_d` fails to load.
|
- Fix an error where `eslint_d` fails to load.
|
||||||
- Added required files support for linters under `vim.diagnostics.nvim-lint.linters.*.required_files`.
|
- Add required files support for linters under `vim.diagnostics.nvim-lint.linters.*.required_files`.
|
||||||
|
- Add global function `nvf_lint` under `vim.diagnostics.nvim-lint.lint_function`.
|
||||||
|
|
||||||
[Sc3l3t0n](https://github.com/Sc3l3t0n):
|
[Sc3l3t0n](https://github.com/Sc3l3t0n):
|
||||||
|
|
||||||
|
|
|
@ -29,40 +29,7 @@ in {
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function nvf_lint(buf)
|
nvf_lint = ${toLuaObject cfg.lint_function}
|
||||||
local ft = vim.api.nvim_get_option_value("filetype", { buf = buf })
|
|
||||||
local linters = require("lint").linters
|
|
||||||
local linters_from_ft = require("lint").linters_by_ft[ft]
|
|
||||||
|
|
||||||
-- if no linter is configured for this filetype, stops linting
|
|
||||||
if linters_from_ft == nil then return end
|
|
||||||
|
|
||||||
for _, name in ipairs(linters_from_ft) do
|
|
||||||
local linter = linters[name]
|
|
||||||
assert(linter, 'Linter with name `' .. name .. '` not available')
|
|
||||||
|
|
||||||
if type(linter) == "function" then
|
|
||||||
linter = linter()
|
|
||||||
end
|
|
||||||
-- for require("lint").lint() to work, linter.name must be set
|
|
||||||
linter.name = linter.name or name
|
|
||||||
local cwd = linter.required_files
|
|
||||||
|
|
||||||
-- if no configuration files are configured, lint
|
|
||||||
if cwd == nil then
|
|
||||||
require("lint").lint(linter)
|
|
||||||
else
|
|
||||||
-- if configuration files are configured and present in the project, lint
|
|
||||||
for _, fn in ipairs(cwd) do
|
|
||||||
local path = vim.fs.joinpath(linter.cwd or vim.fn.getcwd(), fn);
|
|
||||||
if vim.uv.fs_stat(path) then
|
|
||||||
require("lint").lint(linter)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
{lib, ...}: let
|
{lib, ...}: let
|
||||||
inherit (lib.options) mkOption mkEnableOption;
|
inherit (lib.options) mkOption mkEnableOption literalExpression;
|
||||||
inherit (lib.types) nullOr attrsOf listOf str either submodule bool enum;
|
inherit (lib.types) nullOr attrsOf listOf str either submodule bool enum;
|
||||||
inherit (lib.nvim.types) luaInline;
|
inherit (lib.nvim.types) luaInline;
|
||||||
|
inherit (lib.generators) mkLuaInline;
|
||||||
|
|
||||||
linterType = submodule {
|
linterType = submodule {
|
||||||
options = {
|
options = {
|
||||||
|
@ -73,8 +74,11 @@
|
||||||
required_files = mkOption {
|
required_files = mkOption {
|
||||||
type = nullOr (listOf str);
|
type = nullOr (listOf str);
|
||||||
default = null;
|
default = null;
|
||||||
description = "Required files to lint. These files must exist relative to the cwd of the linter or else this linter will be skipped";
|
|
||||||
example = ["eslint.config.js"];
|
example = ["eslint.config.js"];
|
||||||
|
description = ''
|
||||||
|
Required files to lint. These files must exist relative to the cwd
|
||||||
|
of the linter or else this linter will be skipped
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -124,5 +128,53 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
lint_after_save = mkEnableOption "autocmd to lint after each save" // {default = true;};
|
lint_after_save = mkEnableOption "autocmd to lint after each save" // {default = true;};
|
||||||
|
|
||||||
|
lint_function = mkOption {
|
||||||
|
type = luaInline;
|
||||||
|
default = mkLuaInline ''
|
||||||
|
function(buf)
|
||||||
|
local ft = vim.api.nvim_get_option_value("filetype", { buf = buf })
|
||||||
|
local linters = require("lint").linters
|
||||||
|
local linters_from_ft = require("lint").linters_by_ft[ft]
|
||||||
|
|
||||||
|
-- if no linter is configured for this filetype, stops linting
|
||||||
|
if linters_from_ft == nil then return end
|
||||||
|
|
||||||
|
for _, name in ipairs(linters_from_ft) do
|
||||||
|
local linter = linters[name]
|
||||||
|
assert(linter, 'Linter with name `' .. name .. '` not available')
|
||||||
|
|
||||||
|
if type(linter) == "function" then
|
||||||
|
linter = linter()
|
||||||
|
end
|
||||||
|
-- for require("lint").lint() to work, linter.name must be set
|
||||||
|
linter.name = linter.name or name
|
||||||
|
local cwd = linter.required_files
|
||||||
|
|
||||||
|
-- if no configuration files are configured, lint
|
||||||
|
if cwd == nil then
|
||||||
|
require("lint").lint(linter)
|
||||||
|
else
|
||||||
|
-- if configuration files are configured and present in the project, lint
|
||||||
|
for _, fn in ipairs(cwd) do
|
||||||
|
local path = vim.fs.joinpath(linter.cwd or vim.fn.getcwd(), fn);
|
||||||
|
if vim.uv.fs_stat(path) then
|
||||||
|
require("lint").lint(linter)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
example = literalExpression ''
|
||||||
|
mkLuaInline '''
|
||||||
|
function(buf)
|
||||||
|
require("lint").try_lint()
|
||||||
|
end
|
||||||
|
'''
|
||||||
|
'';
|
||||||
|
description = "Define the global function nvf_lint which is used by nvf to lint.";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue