forked from jhipster/prettier-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.huskyrc.js
33 lines (30 loc) · 942 Bytes
/
.huskyrc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"use strict";
const { execSync } = require("child_process");
const { entrypoint } = require("./packages/prettier-plugin-java/src/options");
const tasks = arr => arr.join(" && ");
function checkEntrypointOptions() {
const missingRules = [];
const rules = execSync(
`sed -nE 's/.*RULE\\("([^"]+)".*/\\1/p' $(ls packages/java-parser/src/productions/*)`
)
.toString()
.split("\n");
const optionRules = [];
entrypoint.choices.forEach(wrappedRule =>
optionRules.push(wrappedRule.value)
);
rules.forEach(rule => {
if (!optionRules.includes(rule) && rule !== "") {
missingRules.push(rule);
}
});
if (missingRules.length === 0) return `echo No entrypoint rule is missing.`;
return `echo "\\e[31mMissing rule(s) in entrypoint options ${JSON.stringify(
missingRules
)}.\\e[0m" && false`;
}
module.exports = {
hooks: {
"pre-commit": tasks(["lint-staged", checkEntrypointOptions()])
}
};