treewide: Reformat with nixfmt

This commit is contained in:
traxys 2024-05-05 19:39:35 +02:00
parent c6281260dc
commit 62f32bfc71
459 changed files with 28139 additions and 26377 deletions

View file

@ -5,7 +5,8 @@
pkgs,
...
}:
with lib; let
with lib;
let
cfg = config.plugins.lint;
linterOptions = with types; {
@ -50,7 +51,11 @@ with lib; let
};
stream = {
type = enum ["stdout" "stderr" "both"];
type = enum [
"stdout"
"stderr"
"both"
];
description = ''
configure the stream to which the linter outputs the linting result.
@ -91,117 +96,104 @@ with lib; let
};
};
mkLinterOpts = noDefaults:
mkLinterOpts =
noDefaults:
types.submodule {
freeformType = types.attrs;
options =
mapAttrs
options = mapAttrs (
optionName:
(
optionName: (
{
mandatory ? false,
apply ? x: x,
example ? null,
type,
description,
}:
mkOption (
{
mandatory ? false,
apply ? x: x,
example ? null,
type,
description,
}:
mkOption (
inherit apply description example;
}
// (
if
noDefaults && mandatory
# Make this option mandatory
then
{ inherit type; }
# make it optional
else
{
inherit
apply
description
example
;
type = types.nullOr type;
default = null;
}
// (
if noDefaults && mandatory
# Make this option mandatory
then {
inherit type;
}
# make it optional
else {
type = types.nullOr type;
default = null;
}
)
)
)
)
)
linterOptions;
) linterOptions;
};
in {
options.plugins.lint =
helpers.neovim-plugin.extraOptionsOptions
// {
enable = mkEnableOption "nvim-lint";
in
{
options.plugins.lint = helpers.neovim-plugin.extraOptionsOptions // {
enable = mkEnableOption "nvim-lint";
package = helpers.mkPackageOption "nvim-lint" pkgs.vimPlugins.nvim-lint;
package = helpers.mkPackageOption "nvim-lint" pkgs.vimPlugins.nvim-lint;
lintersByFt = mkOption {
type = with types; attrsOf (listOf str);
default = {};
description = ''
Configure the linters you want to run per file type.
lintersByFt = mkOption {
type = with types; attrsOf (listOf str);
default = { };
description = ''
Configure the linters you want to run per file type.
Default:
```nix
{
text = ["vale"];
json = ["jsonlint"];
markdown = ["vale"];
rst = ["vale"];
ruby = ["ruby"];
janet = ["janet"];
inko = ["inko"];
clojure = ["clj-kondo"];
dockerfile = ["hadolint"];
terraform = ["tflint"];
}
```
'';
example = {
markdown = ["vale"];
};
Default:
```nix
{
text = ["vale"];
json = ["jsonlint"];
markdown = ["vale"];
rst = ["vale"];
ruby = ["ruby"];
janet = ["janet"];
inko = ["inko"];
clojure = ["clj-kondo"];
dockerfile = ["hadolint"];
terraform = ["tflint"];
}
```
'';
example = {
markdown = [ "vale" ];
};
};
linters = mkOption {
type = with types;
attrsOf
(mkLinterOpts false);
default = {};
description = ''
Customize the existing linters by overriding some of their properties.
'';
example = {
phpcs.args = [
"-q"
"--report=json"
"-"
];
};
linters = mkOption {
type = with types; attrsOf (mkLinterOpts false);
default = { };
description = ''
Customize the existing linters by overriding some of their properties.
'';
example = {
phpcs.args = [
"-q"
"--report=json"
"-"
];
};
};
customLinters = mkOption {
type = with types;
attrsOf
(
either
str
(mkLinterOpts true)
);
default = {};
description = ''
Configure the linters you want to run per file type.
It can be both an attrs or a string containing the lua code that returns the appropriate
table.
'';
example = {
};
};
customLinters = mkOption {
type = with types; attrsOf (either str (mkLinterOpts true));
default = { };
description = ''
Configure the linters you want to run per file type.
It can be both an attrs or a string containing the lua code that returns the appropriate
table.
'';
example = { };
};
autoCmd = let
autoCmd =
let
defaultEvent = "BufWritePost";
defaultCallback = helpers.mkRaw ''
function()
@ -209,93 +201,69 @@ in {
end
'';
in
mkOption {
type = with types;
nullOr (submodule {
options =
helpers.autocmd.autoCmdOptions
// {
event = mkOption {
type = with types;
nullOr
(
either
str
(listOf str)
);
default = defaultEvent;
description = "The event or events that should trigger linting.";
};
mkOption {
type =
with types;
nullOr (submodule {
options = helpers.autocmd.autoCmdOptions // {
event = mkOption {
type = with types; nullOr (either str (listOf str));
default = defaultEvent;
description = "The event or events that should trigger linting.";
};
callback = mkOption {
type = with types;
nullOr (either str helpers.nixvimTypes.rawLua);
default = defaultCallback;
description = "What action to perform for linting";
};
};
});
description = ''
The configuration for the linting autocommand.
You can disable it by setting this option to `null`.
'';
default = {
event = defaultEvent;
callback = defaultCallback;
};
callback = mkOption {
type = with types; nullOr (either str helpers.nixvimTypes.rawLua);
default = defaultCallback;
description = "What action to perform for linting";
};
};
});
description = ''
The configuration for the linting autocommand.
You can disable it by setting this option to `null`.
'';
default = {
event = defaultEvent;
callback = defaultCallback;
};
};
};
};
config = mkIf cfg.enable {
extraPlugins = [cfg.package];
extraPlugins = [ cfg.package ];
extraConfigLua =
''
__lint = require('lint')
__lint.linters_by_ft = ${helpers.toLuaObject cfg.lintersByFt}
''
+ (
optionalString
(cfg.linters != {})
(
concatLines
(
flatten
(
mapAttrsToList
(
linter: linterConfig:
mapAttrsToList
(
propName: propValue:
optionalString
(propValue != null)
"__lint.linters.${linter}.${propName} = ${helpers.toLuaObject propValue}"
)
linterConfig
)
cfg.linters
)
+ (optionalString (cfg.linters != { }) (
concatLines (
flatten (
mapAttrsToList (
linter: linterConfig:
mapAttrsToList (
propName: propValue:
optionalString (
propValue != null
) "__lint.linters.${linter}.${propName} = ${helpers.toLuaObject propValue}"
) linterConfig
) cfg.linters
)
)
)
+ (
optionalString
(cfg.customLinters != {})
(
concatLines
(
mapAttrsToList
(customLinter: linterConfig: let
linterConfig' =
if isString linterConfig
then helpers.mkRaw linterConfig
else linterConfig;
in "__lint.linters.${customLinter} = ${helpers.toLuaObject linterConfig'}")
cfg.customLinters
)
))
+ (optionalString (cfg.customLinters != { }) (
concatLines (
mapAttrsToList (
customLinter: linterConfig:
let
linterConfig' = if isString linterConfig then helpers.mkRaw linterConfig else linterConfig;
in
"__lint.linters.${customLinter} = ${helpers.toLuaObject linterConfig'}"
) cfg.customLinters
)
);
));
autoCmd = optional (cfg.autoCmd != null) cfg.autoCmd;
};