plugins/efmls: use mkPackageOption

This commit is contained in:
Matt Sturgeon 2024-09-03 16:15:48 +01:00
parent 2ef974182e
commit a8a7e405f4
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
3 changed files with 153 additions and 119 deletions

View file

@ -1,4 +1,4 @@
pkgs: {
lib: {
# efmls-configs tools that have no corresponding nixpkgs package
unpackaged = [
"blade_formatter"
@ -27,115 +27,149 @@ pkgs: {
];
# Mapping from a efmls-configs tool name to the corresponding nixpkgs package
packaged = with pkgs; {
inherit
actionlint
alejandra
ameba
astyle
bashate
beautysh
biome
black
buf
cbfmt
checkmake
clazy
codespell
cppcheck
cpplint
dfmt
djlint
dmd
dprint
fish
flawfinder
fnlfmt
gcc
gitlint
gofumpt
golines
golint
hadolint
isort
joker
jq
languagetool
mypy
php
prettypst
proselint
protolint
pylint
rubocop
ruff
rustfmt
scalafmt
selene
shellcheck
shellharden
shfmt
smlfmt
sqlfluff
statix
stylua
taplo
typstfmt
typstyle
uncrustify
vale
yamllint
yapf
;
inherit (python3.pkgs)
autopep8
flake8
mdformat
vulture
;
inherit (nodePackages)
eslint_d
prettier
alex
sql-formatter
stylelint
textlint
;
inherit (phpPackages) phan phpstan psalm;
inherit (luaPackages) luacheck;
inherit (haskellPackages) fourmolu;
ansible_lint = ansible-lint;
chktex = texliveMedium;
clang_format = clang-tools;
clang_tidy = clang-tools;
clj_kondo = clj-kondo;
cmake_lint = cmake-format;
dartfmt = dart;
dotnet_format = dotnet-runtime;
# TODO: Added 2024-08-31; remove 2024-11-31
# eslint was moved out of nodePackages set without alias
# Using fallback as a transition period
eslint = pkgs.eslint or pkgs.nodePackages.eslint;
fish_indent = fish;
gofmt = go;
goimports = go-tools;
golangci_lint = golangci-lint;
google_java_format = google-java-format;
go_revive = revive;
latexindent = texliveMedium;
lua_format = luaformatter;
markdownlint = markdownlint-cli;
mcs = mono;
nixfmt = nixfmt-classic;
phpcbf = phpPackages.php-codesniffer;
php_cs_fixer = phpPackages.php-cs-fixer;
phpcs = phpPackages.php-codesniffer;
prettier_d = prettierd;
slither = slither-analyzer;
staticcheck = go-tools;
terraform_fmt = terraform;
vint = vim-vint;
write_good = write-good;
yq = yq-go;
packaged =
let
# TODO: move these helpers to a shared location so that none-ls can also use them
topLevel = names: lib.genAttrs names lib.id;
scoped = lib.concatMapAttrs (
scope: v:
if builtins.isAttrs v then
lib.mapAttrs (_: loc: [ scope ] ++ loc) (scoped v)
else
lib.genAttrs (lib.toList v) (name: [
scope
name
])
);
in
# Top-level packages
topLevel [
"actionlint"
"alejandra"
"ameba"
"astyle"
"bashate"
"beautysh"
"biome"
"black"
"buf"
"cbfmt"
"checkmake"
"clazy"
"codespell"
"cppcheck"
"cpplint"
"dfmt"
"djlint"
"dmd"
"dprint"
"fish"
"flawfinder"
"fnlfmt"
"gcc"
"gitlint"
"gofumpt"
"golines"
"golint"
"hadolint"
"isort"
"joker"
"jq"
"languagetool"
"mypy"
"php"
"prettypst"
"proselint"
"protolint"
"pylint"
"rubocop"
"ruff"
"rustfmt"
"scalafmt"
"selene"
"shellcheck"
"shellharden"
"shfmt"
"smlfmt"
"sqlfluff"
"statix"
"stylua"
"taplo"
"typstfmt"
"typstyle"
"uncrustify"
"vale"
"yamllint"
"yapf"
]
# Scoped packages
// scoped {
python3.pkgs = [
"autopep8"
"flake8"
"mdformat"
"vulture"
];
nodePackages = [
"eslint" # FIXME: No way to have a transition fallback...
"eslint_d"
"prettier"
"alex"
"sql-formatter"
"stylelint"
"textlint"
];
phpPackages = [
"phan"
"phpstan"
"psalm"
];
luaPackages = [
"luacheck"
];
haskellPackages = [
"fourmolu"
];
}
# Packages where the name is different
// {
ansible_lint = "ansible-lint";
chktex = "texliveMedium";
clang_format = "clang-tools";
clang_tidy = "clang-tools";
clj_kondo = "clj-kondo";
cmake_lint = "cmake-format";
dartfmt = "dart";
dotnet_format = "dotnet-runtime";
fish_indent = "fish";
gofmt = "go";
goimports = "go-tools";
golangci_lint = "golangci-lint";
google_java_format = "google-java-format";
go_revive = "revive";
latexindent = "texliveMedium";
lua_format = "luaformatter";
markdownlint = "markdownlint-cli";
mcs = "mono";
nixfmt = "nixfmt-classic";
phpcbf = [
"phpPackages"
"php-codesniffer"
];
php_cs_fixer = [
"phpPackages"
"php-cs-fixer"
];
phpcs = [
"phpPackages"
"php-codesniffer"
];
prettier_d = "prettierd";
slither = "slither-analyzer";
staticcheck = "go-tools";
terraform_fmt = "terraform";
vint = "vim-vint";
write_good = "write-good";
yq = "yq-go";
};
}

View file

@ -7,7 +7,7 @@
}:
let
tools = import ../../../generated/efmls-configs.nix;
inherit (import ./efmls-configs-pkgs.nix pkgs) packaged;
inherit (import ./efmls-configs-pkgs.nix lib) packaged;
in
{
options.plugins.efmls-configs = {
@ -26,10 +26,10 @@ in
toolPackages = lib.pipe packaged [
# Produce package a option for each tool
(lib.attrsets.mapAttrs (
tool: pkg:
helpers.mkPackageOption {
name = tool;
default = pkg;
name: loc:
lib.mkPackageOption pkgs name {
nullable = true;
default = loc;
}
))
# Filter package defaults that are not compatible with the current platform
@ -38,7 +38,7 @@ in
if lib.meta.availableOn pkgs.stdenv.hostPlatform opt.default then
opt
else
opt // { default = null; }
builtins.removeAttrs opt [ "defaultText" ] // { default = null; }
))
];

View file

@ -54,7 +54,7 @@ let
declared =
let
inherit (import ../plugins/lsp/language-servers/efmls-configs-pkgs.nix pkgs) packaged unpackaged;
inherit (import ../plugins/lsp/language-servers/efmls-configs-pkgs.nix lib) packaged unpackaged;
in
unpackaged ++ lib.attrsets.attrNames packaged;