1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-18 19:51:17 +00:00

textlint: add test utility

This commit is contained in:
natsukium 2024-05-18 00:51:25 +09:00
parent cd59be301d
commit 68c7f8e5ab
No known key found for this signature in database
GPG key ID: 9EA45A31DB994C53

View file

@ -58,6 +58,38 @@ buildNpmPackage rec {
makeWrapper ${textlint}/bin/textlint $out/bin/textlint \
--set NODE_PATH ${lib.makeSearchPath "lib/node_modules" ps}
'';
testPackages =
{
rule,
testFile,
pname ? rule.pname,
plugin ? null,
}:
let
ruleName = lib.removePrefix "textlint-rule-" rule.pname;
isPreset = lib.hasPrefix "preset-" ruleName;
ruleName' = lib.removePrefix "preset-" ruleName;
pluginName = lib.removePrefix "textlint-plugin-" plugin.pname;
args =
"${testFile} ${if isPreset then "--preset" else "--rule"} ${ruleName'}"
+ lib.optionalString (plugin != null) " --plugin ${pluginName}";
in
{
"${pname}-test" =
runCommand "${pname}-test"
{
nativeBuildInputs = [
(textlint.withPackages [
rule
plugin
])
];
}
''
grep ${ruleName'} <(textlint ${args}) > $out
'';
};
};
meta = {