bsg
Version:
Lint all in one tool for BSG-FE
61 lines (57 loc) • 1.43 kB
JavaScript
module.exports = async function () {
const load = require("@commitlint/load").default;
const read = require("@commitlint/read").default;
const lint = require("@commitlint/lint").default;
const format = require("@commitlint/format").default;
const tasks = await Promise.all([
load({
extends: ["@commitlint/config-conventional"],
parserPreset: {
parserOpts: {
headerPattern:
/^(\[\w*\])(?:\(([\u4e00-\u9fa5\w$.\-*/ ]*)\))?: (.*)$/,
commentChar: "#",
},
},
// https://cf.ge.cn/pages/viewpage.action?pageId=45799867
rules: {
"subject-case": [2, "never", []],
"type-enum": [
2,
"always",
[
"[feature]",
"[fix]",
"[update]",
"[docs]",
"[style]",
"[refactor]",
"[test]",
"[chore]",
"[bump]",
],
],
},
}),
read({ edit: true }),
]);
const [{ rules, parserPreset }, [commit]] = tasks;
const report = await lint(
commit,
rules,
parserPreset ? { parserOpts: parserPreset.parserOpts } : {},
);
if (!report.valid) {
console.log(
format(
{
results: [report],
},
{
helpUrl: "https://cf.ge.cn/pages/viewpage.action?pageId=110079239",
},
),
);
process.exit(1);
}
};