about summary refs log tree commit diff
path: root/pkgs/tools/text
diff options
context:
space:
mode:
authorPaul Meyer <49727155+katexochen@users.noreply.github.com>2024-04-21 13:15:03 +0200
committerGitHub <noreply@github.com>2024-04-21 13:15:03 +0200
commit96fbb517b2487bdb2ff1d0868287844ca714d9e1 (patch)
tree10cebcd3f8a99daa9d5f1b098b8b985d104dca83 /pkgs/tools/text
parent1114b274e555ff9b926dab8f908b0315d0dc5ed3 (diff)
parentc354f95643da99c1e08cb4a89bbc44f43c309402 (diff)
Merge pull request #301204 from marsam/vale-styles
valeStyles: init
Diffstat (limited to 'pkgs/tools/text')
-rw-r--r--pkgs/tools/text/vale/default.nix32
-rw-r--r--pkgs/tools/text/vale/styles.nix144
2 files changed, 169 insertions, 7 deletions
diff --git a/pkgs/tools/text/vale/default.nix b/pkgs/tools/text/vale/default.nix
index 9fa3c12ccc88a..5bb73a50f9e64 100644
--- a/pkgs/tools/text/vale/default.nix
+++ b/pkgs/tools/text/vale/default.nix
@@ -1,11 +1,18 @@
-{ lib, buildGoModule, fetchFromGitHub }:
+{ lib
+, buildGoModule
+, fetchFromGitHub
+, makeBinaryWrapper
+, runCommand
+, symlinkJoin
+, vale
+, valeStyles
+}:
 
 buildGoModule rec {
   pname = "vale";
   version = "3.4.1";
 
   subPackages = [ "cmd/vale" ];
-  outputs = [ "out" "data" ];
 
   src = fetchFromGitHub {
     owner = "errata-ai";
@@ -16,18 +23,29 @@ buildGoModule rec {
 
   vendorHash = "sha256-HMzFLSmO6sBDNU89UoIvHcPPd3ubpti2ii4sFMKUDmI=";
 
-  postInstall = ''
-    mkdir -p $data/share/vale
-    cp -r testdata/styles $data/share/vale
-  '';
-
   ldflags = [ "-s" "-w" "-X main.version=${version}" ];
 
   # Tests require network access
   doCheck = false;
 
+  passthru.withStyles = selector: symlinkJoin {
+    name = "vale-with-styles-${vale.version}";
+    paths = [ vale ] ++ selector valeStyles;
+    nativeBuildInputs = [ makeBinaryWrapper ];
+    postBuild = ''
+      wrapProgram "$out/bin/vale" \
+        --set VALE_STYLES_PATH "$out/share/vale/styles/"
+    '';
+  };
+
   meta = with lib; {
     description = "A syntax-aware linter for prose built with speed and extensibility in mind";
+    longDescription = ''
+      Vale in Nixpkgs offers the helper `.withStyles` allow you to install it
+      predefined styles:
+
+          vale.withStyles (s: [ s.alex s.google ])
+    '';
     homepage = "https://vale.sh/";
     changelog = "https://github.com/errata-ai/vale/releases/tag/v${version}";
     mainProgram = "vale";
diff --git a/pkgs/tools/text/vale/styles.nix b/pkgs/tools/text/vale/styles.nix
new file mode 100644
index 0000000000000..f2513289a5488
--- /dev/null
+++ b/pkgs/tools/text/vale/styles.nix
@@ -0,0 +1,144 @@
+{ lib, stdenvNoCC, fetchFromGitHub, fetchzip, nix-update-script }:
+
+let
+  buildStyle =
+    { name
+    , stylePath ? name
+    , ...
+    }@args:
+    stdenvNoCC.mkDerivation ({
+      pname = "vale-style-${lib.toLower name}";
+
+      dontConfigure = true;
+      dontBuild = true;
+      doCheck = false;
+      dontFixup = true;
+
+      installPhase = ''
+        runHook preInstall
+        mkdir -p $out/share/vale/styles
+        cp -R ${stylePath} "$out/share/vale/styles/${name}"
+        runHook postInstall
+      '';
+
+      passthru.updateScript = nix-update-script { };
+
+      meta = {
+        platforms = lib.platforms.all;
+        maintainers = with lib.maintainers; [ katexochen ];
+      } // (args.meta or { });
+    } // removeAttrs args [ "meta" "name" ]);
+in
+{
+  alex = buildStyle rec {
+    name = "alex";
+    version = "0.2.1";
+    src = fetchFromGitHub {
+      owner = "errata-ai";
+      repo = "alex";
+      rev = "v${version}";
+      hash = "sha256-xNF7se2FwKgNe5KYx/zvGWpIwBsBADYGH4JV1lUww+Q=";
+    };
+    meta = {
+      description = "A Vale-compatible implementation of the guidelines enforced by the alex linter";
+      homepage = "https://github.com/errata-ai/alex";
+      license = lib.licenses.mit;
+    };
+  };
+
+  google = buildStyle rec {
+    name = "Google";
+    version = "0.6.0";
+    src = fetchFromGitHub {
+      owner = "errata-ai";
+      repo = "Google";
+      rev = "v${version}";
+      hash = "sha256-TQS/hgS6tEWPSuZpEbX65MdYSE/+HJVcnzIuQbhIG2M=";
+    };
+    meta = {
+      description = "A Vale-compatible implementation of the Google Developer Documentation Style Guide";
+      homepage = "https://github.com/errata-ai/Google";
+      license = lib.licenses.mit;
+    };
+  };
+
+  joblint = buildStyle rec {
+    name = "Joblint";
+    version = "0.4.1";
+    src = fetchFromGitHub {
+      owner = "errata-ai";
+      repo = "Joblint";
+      rev = "v${version}";
+      hash = "sha256-zRz5ThOg5RLTZj3dYPe0PDvOF5DjO31lduSpi2Us87U=";
+    };
+    meta = {
+      description = "A Vale-compatible implementation of the Joblint linter";
+      homepage = "https://github.com/errata-ai/Joblint";
+      license = lib.licenses.mit;
+    };
+  };
+
+  microsoft = buildStyle rec {
+    name = "Microsoft";
+    version = "0.14.0";
+    src = fetchFromGitHub {
+      owner = "errata-ai";
+      repo = "Microsoft";
+      rev = "v${version}";
+      hash = "sha256-22rGNLZOsWYQ+H3CcM2b1zOXV3kNPcgYqDpaCg1iv9o=";
+    };
+    meta = {
+      description = "A Vale-compatible implementation of the Microsoft Writing Style Guide";
+      homepage = "https://github.com/errata-ai/Microsoft";
+      license = lib.licenses.mit;
+    };
+  };
+
+  proselint = buildStyle rec {
+    name = "proselint";
+    version = "0.3.3";
+    src = fetchFromGitHub {
+      owner = "errata-ai";
+      repo = "proselint";
+      rev = "v${version}";
+      hash = "sha256-faeWr1bRhnKsycJY89WqnRv8qIowUmz3EQvDyjtl63w=";
+    };
+    meta = {
+      description = "A Vale-compatible implementation of Python's proselint linter";
+      homepage = "https://github.com/errata-ai/proselint";
+      license = lib.licenses.bsd3;
+    };
+  };
+
+  readability = buildStyle rec {
+    name = "Readability";
+    version = "0.1.1";
+    src = fetchFromGitHub {
+      owner = "errata-ai";
+      repo = "readability";
+      rev = "v${version}";
+      hash = "sha256-5Y9v8QsZjC2w3/pGIcL5nBdhpogyJznO5IFa0s8VOOI=";
+    };
+    meta = {
+      description = "Vale-compatible implementations of many popular \"readability\" metrics";
+      homepage = "https://github.com/errata-ai/readability";
+      license = lib.licenses.mit;
+    };
+  };
+
+  write-good = buildStyle rec {
+    name = "write-good";
+    version = "0.4.0";
+    src = fetchFromGitHub {
+      owner = "errata-ai";
+      repo = "write-good";
+      rev = "v${version}";
+      hash = "sha256-KQzY6MeHV/owPVmUAfzGUO0HmFPkD7wdQqOvBkipwP8=";
+    };
+    meta = {
+      description = "A Vale-compatible implementation of the write-good linter";
+      homepage = "https://github.com/errata-ai/write-good";
+      license = lib.licenses.mit;
+    };
+  };
+}