git-hooks.nix icon indicating copy to clipboard operation
git-hooks.nix copied to clipboard

feature request: extra args for prettier

Open bbigras opened this issue 2 years ago • 1 comments

I think I need --plugin-search-dir to use prettier-plugin-svelte.

bbigras avatar Jun 30 '22 20:06 bbigras

What I usually do is build a wrapper around prettier and create a new hook. Here is a Flake example with the TOML plugin:

{
  description = "Test Flake";

  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:NixOS/nixpkgs";
    pre-commit-hooks = {
      url = "github:cachix/pre-commit-hooks.nix";
      inputs.ixpkgs.follows = "nixpkgs";
      inputs.flake-utils.follows = "flake-utils";
    };
  };

  outputs = {
    self,
    flake-utils,
    nixpkgs,
    pre-commit-hooks,
  }: let
    supportedSystems = ["x86_64-linux"];
  in
    {
      overlays.default = nixpkgs.lib.composeManyExtensions [
        (final: prev: {
          prettierWithTOML = prev.writeShellScriptBin "prettier" ''
              ${prev.nodePackages.prettier}/bin/prettier \
              --plugin-search-dir "${prev.nodePackages.prettier-plugin-toml}/lib" \
              "$@"
          '';
        })
      ];
    }
    // (flake-utils.lib.eachSystem supportedSystems (system: let
      pkgs = import nixpkgs {
        inherit system;
        overlays = [self.overlays.default];
      };
      in {
        checks = {
          pre-commit-check = pre-commit-hooks.lib.${system}.run {
            src = ./.;
            hooks = with pkgs; {
              prettier = {
                enable = true;
                entry = lib.mkForce "${prettierWithTOML}/bin/prettier --check";
                types_or = ["markdown" "toml" "yaml"];
              };
            };
          };
        };
      }));
}

However I can see this being added as a option.

loicreynier avatar Jul 05 '22 12:07 loicreynier

@bbigras You should now be able to use settings.prettier.plugins to provide paths to plugins like `prettier-plugin-svelte.

This was added in #388.

In case this does not work for you please let me know. Closing this issue for now.

totoroot avatar Feb 21 '24 09:02 totoroot