Skip to content

Commit

Permalink
treewide: use mkAssertions where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Jan 29, 2025
1 parent 12e658e commit ce82e58
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 106 deletions.
16 changes: 7 additions & 9 deletions plugins/by-name/copilot-lua/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,13 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = {
assertions = [
{
assertion = !config.plugins.copilot-vim.enable;
message = ''
You currently have both `copilot-vim` and `copilot-lua` enabled.
Please disable one of them.
'';
}
];
assertions = lib.nixvim.mkAssertions "plugins.copilot-lua" {
assertion = !config.plugins.copilot-vim.enable;
message = ''
You currently have both `copilot-vim` and `copilot-lua` enabled.
Please disable one of them.
'';
};
};

# TODO: introduced 2025-01-07: remove after 25.05
Expand Down
12 changes: 6 additions & 6 deletions plugins/by-name/git-worktree/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ lib.nixvim.plugins.mkNeovimPlugin {
extraConfig =
cfg:
lib.mkIf cfg.enable {
assertions = [
{
assertion = cfg.enableTelescope -> config.plugins.telescope.enable;
message = ''Nixvim: The git-worktree telescope integration needs telescope to function as intended'';
}
];
assertions = lib.nixvim.mkAssertions "plugins.git-worktree" {
assertion = cfg.enableTelescope -> config.plugins.telescope.enable;
message = ''
You have to enable `plugins.telescope` as `enableTelescope` is activated.
'';
};

extraPackages = [ cfg.gitPackage ];

Expand Down
4 changes: 2 additions & 2 deletions plugins/by-name/harpoon/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ in
// cfg.extraOptions;
in
mkIf cfg.enable {
assertions = [
assertions = lib.nixvim.mkAssertions "plugins.harpoon" [
{
assertion = cfg.enableTelescope -> config.plugins.telescope.enable;
message = ''Nixvim: The harpoon telescope integration needs telescope to function as intended'';
message = "The harpoon telescope integration needs telescope to function as intended.";
}
];

Expand Down
44 changes: 21 additions & 23 deletions plugins/by-name/lean/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -231,29 +231,27 @@ in
config = mkIf cfg.enable {
extraPlugins = [ cfg.package ];

assertions = [
{
assertion =
!(
# leanls lsp server is disabled in nvim-lspconfig
config.plugins.lsp.servers.leanls.enable
# lsp is not (!) disabled in the lean.nvim plugin
&& !(
# lsp is explicitly set to `false`.
(isBool cfg.lsp.enable) && !cfg.lsp.enable
)
);
message = ''
You have not explicitly set `plugins.lean.lsp` to `false` while having `plugins.lsp.servers.leanls.enable` set to `true`.
You need to either
- Remove the configuration in `plugins.lsp.servers.leanls` and move it to `plugins.lean.lsp`.
- Explicitly disable the autoconfiguration of the lsp in the lean.nvim plugin by setting `plugins.lean.lsp` to `false`.
https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#leanls
'';
}
];
assertions = lib.nixvim.mkAssertions "plugins.lean" {
assertion =
!(
# leanls lsp server is disabled in nvim-lspconfig
config.plugins.lsp.servers.leanls.enable
# lsp is not (!) disabled in the lean.nvim plugin
&& !(
# lsp is explicitly set to `false`.
(isBool cfg.lsp.enable) && !cfg.lsp.enable
)
);
message = ''
You have not explicitly set `plugins.lean.lsp` to `false` while having `plugins.lsp.servers.leanls.enable` set to `true`.
You need to either
- Remove the configuration in `plugins.lsp.servers.leanls` and move it to `plugins.lean.lsp`.
- Explicitly disable the autoconfiguration of the lsp in the lean.nvim plugin by setting `plugins.lean.lsp` to `false`.
https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#leanls
'';
};

extraPackages = [ cfg.leanPackage ];

Expand Down
17 changes: 8 additions & 9 deletions plugins/by-name/mini/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,14 @@ lib.nixvim.plugins.mkNeovimPlugin {
callSetup = false;
hasSettings = false;
extraConfig = cfg: {
assertions = [
{
assertion = cfg.mockDevIcons -> cfg.modules ? icons;
message = ''
You have enabled `plugins.mini.mockDevIcons` but have not defined `plugins.mini.modules.icons`.
This setting will have no effect without it.
'';
}
];
assertions = lib.nixvim.mkAssertions "pluhins.mini" {
assertion = cfg.mockDevIcons -> cfg.modules ? icons;
message = ''
You have enabled `plugins.mini.mockDevIcons` but have not defined `plugins.mini.modules.icons`.
This setting will have no effect without it.
'';
};

plugins.mini.luaConfig.content =
lib.foldlAttrs (lines: name: config: ''
${lines}
Expand Down
12 changes: 6 additions & 6 deletions plugins/by-name/neotest/adapters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ let
mkIf cfg.enable {
extraPlugins = [ cfg.package ];

assertions = [
{
assertion = config.plugins.neotest.enable;
message = "Nixvim: you have enabled `plugins.neotest.adapters.${name}` but `plugins.neotest.enable` is `false`.";
}
];
assertions = lib.nixvim.mkAssertions "plugins.neotest.adapters.${name}" {
assertion = config.plugins.neotest.enable;
message = ''
You have to enable `plugins.telescope` as `enableTelescope` is activated.
'';
};

warnings = lib.nixvim.mkWarnings "plugins.neotest.adapters.${name}" {
when = !config.plugins.treesitter.enable;
Expand Down
21 changes: 10 additions & 11 deletions plugins/by-name/none-ls/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,16 @@ lib.nixvim.plugins.mkNeovimPlugin {
'';
};

assertions = [
{
assertion = cfg.enableLspFormat -> config.plugins.lsp-format.enable;
message = ''
Nixvim: You have enabled the lsp-format integration with none-ls.
However, you have not enabled `plugins.lsp-format` itself.
Note: `plugins.none-ls.enableLspFormat` is enabled by default when `plugins.lsp-format` is enabled.
`plugins.none-ls.enableLspFormat` definitions: ${lib.options.showDefs options.plugins.none-ls.enableLspFormat.definitionsWithLocations}
'';
}
];
assertions = lib.nixvim.mkAssertions "plugins.none-ls" {
assertion = cfg.enableLspFormat -> config.plugins.lsp-format.enable;

message = ''
You have enabled the lsp-format integration with none-ls.
However, you have not enabled `plugins.lsp-format` itself.
Note: `plugins.none-ls.enableLspFormat` is enabled by default when `plugins.lsp-format` is enabled.
`plugins.none-ls.enableLspFormat` definitions: ${lib.options.showDefs options.plugins.none-ls.enableLspFormat.definitionsWithLocations}
'';
};

# We only do this here because of enableLspFormat
plugins.none-ls.luaConfig.content = ''
Expand Down
2 changes: 1 addition & 1 deletion plugins/by-name/package-info/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
assertions = lib.nixvim.mkAssertions "plugins.package-info" {
assertion = cfg.enableTelescope -> config.plugins.telescope.enable;
message = ''
The telescope integration needs telescope to function as intended.
You have to enable `plugins.telescope` as `enableTelescope` is activated.
'';
};

Expand Down
19 changes: 9 additions & 10 deletions plugins/by-name/rainbow-delimiters/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,15 @@ with lib;
when = !config.plugins.treesitter.enable;
message = "This plugin needs treesitter to function as intended.";
};
assertions = [
{
assertion = (cfg.whitelist == null) || (cfg.blacklist == null);
message = ''
Both `rainbow-delimiters.whitelist` and `rainbow-delimiters.blacklist` should not be
set simultaneously.
Please remove one of them.
'';
}
];
assertions = lib.nixvim.mkAssertions "plugins.rainbow-delimiters" {
assertion = (cfg.whitelist == null) || (cfg.blacklist == null);

message = ''
Both `rainbow-delimiters.whitelist` and `rainbow-delimiters.blacklist` should not be
set simultaneously.
Please remove one of them.
'';
};

extraPlugins = [ cfg.package ];

Expand Down
17 changes: 8 additions & 9 deletions plugins/by-name/refactoring/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = cfg: {
assertions = [
{
assertion = cfg.enableTelescope -> config.plugins.telescope.enable;
message = ''
Nixvim: You have enabled the `telescope` integration with refactoring-nvim.
However, you have not enabled the `telescope` plugin itself (`plugins.telescope.enable = true`).
'';
}
];
assertions = lib.nixvim.mkAssertions "plugins.refactoring" {
assertion = cfg.enableTelescope -> config.plugins.telescope.enable;

message = ''
You have enabled the `telescope` integration with refactoring-nvim.
However, you have not enabled the `telescope` plugin itself (`plugins.telescope.enable = true`).
'';
};

plugins.telescope.enabledExtensions = mkIf cfg.enableTelescope [ "refactoring" ];
};
Expand Down
2 changes: 1 addition & 1 deletion plugins/by-name/telekasten/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
assertions = lib.nixvim.mkAssertions "plugins.telekasten" {
assertion = config.plugins.telescope.enable;
message = ''
Nixvim (plugins.telekasten): The plugin needs telescope to function as intended.
You have to enable `plugins.telescope` as `enableTelescope` is activated.
'';
};

Expand Down
28 changes: 13 additions & 15 deletions plugins/by-name/tiny-devicons-auto-colors/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,18 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = {
assertions = [
{
assertion =
config.plugins.web-devicons.enable
|| (
config.plugins.mini.enable
&& config.plugins.mini.modules ? icons
&& config.plugins.mini.mockDevIcons
);
message = ''
Nixvim: Either `plugins.web-devicons` or `plugins.mini`* must be enabled to use `tiny-devicons-auto-colors`.
*If using `plugins.mini`, you must enable the `icons` module and the `mockDevIcons` option.
'';
}
];
assertions = lib.nixvim.mkAssertions "plugins.tiny-devicons-auto-colors" {
assertion =
config.plugins.web-devicons.enable
|| (
config.plugins.mini.enable
&& config.plugins.mini.modules ? icons
&& config.plugins.mini.mockDevIcons
);
message = ''
Either `plugins.web-devicons` or `plugins.mini`* must be enabled to use `tiny-devicons-auto-colors`.
*If using `plugins.mini`, you must enable the `icons` module and the `mockDevIcons` option.
'';
};
};
}
6 changes: 3 additions & 3 deletions plugins/by-name/todo-comments/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -414,18 +414,18 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = cfg: {
assertions = [
assertions = lib.nixvim.mkAssertions "plugins.todo-comments" [
{
assertion = cfg.keymaps.todoTelescope.key or null != null -> config.plugins.telescope.enable;
message = ''
Nixvim(plugins.todo-comments): You have enabled todo-comment's `telescope` integration.
You have enabled todo-comment's `telescope` integration.
However, you have not enabled the `telescope` plugin itself (`plugins.telescope.enable = true`).
'';
}
{
assertion = cfg.keymaps.todoTrouble.key or null != null -> config.plugins.trouble.enable;
message = ''
Nixvim(plugins.todo-comments): You have enabled todo-comment's `trouble` integration.
You have enabled todo-comment's `trouble` integration.
However, you have not enabled the `trouble` plugin itself (`plugins.trouble.enable = true`).
'';
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/by-name/yanky/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
{
assertion = cfg.enableTelescope -> config.plugins.telescope.enable;
message = ''
The telescope integration needs telescope to function as intended
You have to enable `plugins.telescope` as `enableTelescope` is activated.
'';
}
{
Expand Down

0 comments on commit ce82e58

Please sign in to comment.