From c1231826b98025889dbd830468ce7e16c20558d9 Mon Sep 17 00:00:00 2001 From: traxys Date: Fri, 5 Jul 2024 14:26:26 +0200 Subject: [PATCH] dev: Add a script to generate efmls-configs tools --- flake-modules/updates/default.nix | 5 + flake-modules/updates/efmls-configs.nix | 69 +++++++++ .../language-servers/efmls-configs-pkgs.nix | 140 ++++++++++++++++++ 3 files changed, 214 insertions(+) create mode 100644 flake-modules/updates/efmls-configs.nix create mode 100644 plugins/lsp/language-servers/efmls-configs-pkgs.nix diff --git a/flake-modules/updates/default.nix b/flake-modules/updates/default.nix index 62cb14df..42600dca 100644 --- a/flake-modules/updates/default.nix +++ b/flake-modules/updates/default.nix @@ -13,12 +13,17 @@ nix build .#rust-analyzer-options cat ./result >"$generated_dir"/rust-analyzer.nix + # efmls-configs + nix build .#efmls-configs-sources + cat ./result >"$generated_dir"/efmls-configs.nix + nix fmt ''; }; packages = { rust-analyzer-options = pkgs.callPackage ./rust-analyzer.nix { }; + efmls-configs-sources = pkgs.callPackage ./efmls-configs.nix { }; }; }; } diff --git a/flake-modules/updates/efmls-configs.nix b/flake-modules/updates/efmls-configs.nix new file mode 100644 index 00000000..64d7f74b --- /dev/null +++ b/flake-modules/updates/efmls-configs.nix @@ -0,0 +1,69 @@ +{ + lib, + vimPlugins, + writeText, + pkgs, +}: +let + tools = lib.trivial.importJSON "${vimPlugins.efmls-configs-nvim.src}/doc/supported-list.json"; + languages = lib.attrNames tools; + + toLangTools' = lang: kind: lib.map (lib.getAttr "name") (tools.${lang}.${kind} or [ ]); + + miscLinters = toLangTools' "misc" "linters"; + miscFormatters = toLangTools' "misc" "formatters"; + + sources = + (lib.listToAttrs ( + lib.map ( + lang: + let + toLangTools = toLangTools' lang; + in + { + name = lang; + value = { + linter = { + inherit lang; + possible = (toLangTools "linters") ++ miscLinters; + }; + formatter = { + inherit lang; + possible = (toLangTools "formatters") ++ miscFormatters; + }; + }; + } + ) languages + )) + // { + all = { + linter = { + lang = "all languages"; + possible = miscLinters; + }; + formatter = { + lang = "all languages"; + possible = miscFormatters; + }; + }; + }; + + inherit (import ../../plugins/lsp/language-servers/efmls-configs-pkgs.nix pkgs) packaged unpackaged; + + toolList = lib.lists.unique ( + lib.concatLists ( + lib.map ({ linter, formatter }: linter.possible ++ formatter.possible) (lib.attrValues sources) + ) + ); + + unknownTools = lib.filter (tool: !(lib.hasAttr tool packaged || lib.elem tool unpackaged)) toolList; +in +assert lib.assertMsg (lib.length unknownTools == 0) + "The following tools are neither marked as unpackaged nor as packaged: ${ + lib.generators.toPretty { } unknownTools + }"; +writeText "efmls-configs-sources.nix" ( + "# WARNING: DO NOT EDIT\n" + + "# This file is generated with packages..efmls-configs-sources, which is run automatically by CI\n" + + (lib.generators.toPretty { } sources) +) diff --git a/plugins/lsp/language-servers/efmls-configs-pkgs.nix b/plugins/lsp/language-servers/efmls-configs-pkgs.nix new file mode 100644 index 00000000..ab5c9e59 --- /dev/null +++ b/plugins/lsp/language-servers/efmls-configs-pkgs.nix @@ -0,0 +1,140 @@ +pkgs: { + # efmls-configs tools that have no corresponding nixpkgs package + unpackaged = [ + "blade_formatter" + "cspell" + "cljstyle" + "dartanalyzer" + "debride" + "deno_fmt" + "fecs" + "fixjson" + "forge_fmt" + "gersemi" + "js_standard" + "pint" + "prettier_eslint" + "prettier_standard" + "redpen" + "reek" + "rome" + "slim_lint" + "solhint" + "sorbet" + "swiftformat" + "swiftlint" + "xo" + ]; + + # 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 + prettierd + 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 + eslint_d + prettier + alex + sql-formatter + stylelint + textlint + write-good + ; + 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; + 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; + }; +}