diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index a3f4fce3..a349cb07 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -37,7 +37,7 @@ jobs: uses: DeterminateSystems/nix-installer-action@main - name: Check formatting via Alejandra - run: nix run nixpkgs#alejandra -- --check . --exclude npins + run: nix run nixpkgs#alejandra -- -c . check-typos: name: "Check source tree for typos" diff --git a/docs/release-notes/rl-0.8.md b/docs/release-notes/rl-0.8.md index b8c51358..d5190855 100644 --- a/docs/release-notes/rl-0.8.md +++ b/docs/release-notes/rl-0.8.md @@ -289,9 +289,8 @@ [rice-cracker-dev](https://github.com/rice-cracker-dev): - `eslint_d` now checks for configuration files to load. -- Fix an error where `eslint_d` fails to load. -- 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`. +- Fixed an error where `eslint_d` fails to load. +- Added required files support for linters under `vim.diagnostics.nvim-lint.linters.*.required_files`. [Sc3l3t0n](https://github.com/Sc3l3t0n): diff --git a/flake.lock b/flake.lock index 540715e9..e31038ab 100644 --- a/flake.lock +++ b/flake.lock @@ -38,11 +38,11 @@ }, "mnw": { "locked": { - "lastModified": 1744592022, - "narHash": "sha256-QuWrCRiF3CUM99sgj3gXbIzB1IAVWS5IEfFHadbMA2g=", + "lastModified": 1744497692, + "narHash": "sha256-ikWRNR/P/aKCCySZnUfF1W0u0t6rSoJgQgKeDdCBAK8=", "owner": "Gerg-L", "repo": "mnw", - "rev": "cf9e19413b6c2d995b55565cd99facf9c751b653", + "rev": "c5322a2bf74c0066fd15ca35721561397a2e7eab", "type": "github" }, "original": { diff --git a/flake/legacyPackages/blink-cmp.nix b/flake/legacyPackages/blink-cmp.nix index 435cb290..8d734719 100644 --- a/flake/legacyPackages/blink-cmp.nix +++ b/flake/legacyPackages/blink-cmp.nix @@ -14,7 +14,7 @@ env.RUSTC_BOOTSTRAP = true; useFetchCargoVendor = true; - cargoHash = "sha256-MWElqh7ENJ6CbLOnvz0DsP5YYu+e+y12GSUOfW1IKGU="; + cargoHash = "sha256-F1wh/TjYoiIbDY3J/prVF367MKk3vwM7LqOpRobOs7I="; nativeBuildInputs = [gitMinimal]; }; diff --git a/modules/plugins/diagnostics/nvim-lint/config.nix b/modules/plugins/diagnostics/nvim-lint/config.nix index 488bd70f..fca38cfa 100644 --- a/modules/plugins/diagnostics/nvim-lint/config.nix +++ b/modules/plugins/diagnostics/nvim-lint/config.nix @@ -29,7 +29,40 @@ in { end end - nvf_lint = ${toLuaObject cfg.lint_function} + function nvf_lint(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 ''; }; }) diff --git a/modules/plugins/diagnostics/nvim-lint/nvim-lint.nix b/modules/plugins/diagnostics/nvim-lint/nvim-lint.nix index 59c50f1d..6657be69 100644 --- a/modules/plugins/diagnostics/nvim-lint/nvim-lint.nix +++ b/modules/plugins/diagnostics/nvim-lint/nvim-lint.nix @@ -1,8 +1,7 @@ {lib, ...}: let - inherit (lib.options) mkOption mkEnableOption literalExpression; + inherit (lib.options) mkOption mkEnableOption; inherit (lib.types) nullOr attrsOf listOf str either submodule bool enum; inherit (lib.nvim.types) luaInline; - inherit (lib.generators) mkLuaInline; linterType = submodule { options = { @@ -74,11 +73,8 @@ required_files = mkOption { type = nullOr (listOf str); 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"]; - description = '' - Required files to lint. These files must exist relative to the cwd - of the linter or else this linter will be skipped - ''; }; }; }; @@ -128,53 +124,5 @@ in { }; 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."; - }; }; }