Lint a string against commitlint rules
npm install --save @commitlint/lint
typeRuleLevel=0|1|2;typeRuleCondition='always'|'never';typeRuleOption=any;typePrimitiveRule=[RuleLevel,RuleCondition,RuleOption?];typeAsyncRule=Promise<PrimitiveRule>;typeFunctionRule=()=>PrimitiveRule;typeAsyncFunctionRule=()=>Promise<PrimitiveRule>;typeRule=PrimitiveRule|FunctionRule|AsyncFunctionRule;typeProblem={level: number;valid: boolean;name: string;message: string;}typeReport={valid: boolean;errors: Problem[];warnings: Problem[];}typeOptions={parserOpts?: any;};lint(message: string,rules: {[ruleName: string]: Rule},opts?: Options)=>Promise<Report>;
importlintfrom"@commitlint/lint";
constreport=awaitlint("foo: bar");console.log(report);// => { valid: true, errors: [], warnings: [] }
constreport=awaitlint("foo: bar",{"type-enum": [1,"always",["foo"]]});console.log(report);// => { valid: true, errors: [], warnings: [] }
constreport=awaitlint("foo: bar",{"type-enum": [1,"always",["bar"]]});console.log(report);/* => { valid: false, errors: [], warnings: [ { level: 1, valid: false, name: 'type-enum', message: 'type must be one of [bar]' } ]}*/
constopts={parserOpts: {headerPattern: /^(\w*)-(\w*)/,headerCorrespondence: ["type","scope"],},};constreport=awaitlint("foo-bar",{"type-enum": [2,"always",["foo"]]},opts,);console.log(report);// => { valid: true, errors: [], warnings: [] }
importloadfrom"@commitlint/load";importlintfrom"@commitlint/lint";constCONFIG={extends: ["@commitlint/config-conventional"],};constopts=awaitload(CONFIG);constreport=awaitlint("foo: bar",opts.rules,opts.parserPreset ? {parserOpts: opts.parserPreset.parserOpts} : {},);console.log(report);/* => { valid: false, errors: [ { level: 2, valid: false, name: 'type-enum', message: 'type must be one of [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test]' } ], warnings: [] }*/
importlintfrom"@commitlint/lint";importreadfrom"@commitlint/read";constRULES={"type-enum": [2,"always",["foo"]],};constcommits=awaitread({to: "HEAD",from: "HEAD~2"});console.info(commits.map((commit)=>lint(commit,RULES)));
importloadfrom"@commitlint/load";importreadfrom"@commitlint/read";importlintfrom"@commitlint/lint";const{ rules, parserPreset }=load();const[commit]=awaitread({from: "HEAD~1"});constreport=awaitlint(commit,rules,parserPreset ? {parserOpts: parserPreset.parserOpts} : {},);console.log(JSON.stringify(result.valid));