Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Last active June 27, 2020 09:30
Show Gist options
  • Save YonatanKra/b4baa9c7e62acd6b88c2db7ad6268a28 to your computer and use it in GitHub Desktop.
Save YonatanKra/b4baa9c7e62acd6b88c2db7ad6268a28 to your computer and use it in GitHub Desktop.
const load = require('@commitlint/load').default;
const lint = require('@commitlint/lint').default;
const CONFIG = {
extends: ['@commitlint/config-conventional'],
};
function buildLintError(lintErrors) {
return lintErrors.map((error) => error.message);
}
export async function testTitle(title) {
const lintOptions = await load(CONFIG);
const lintResult = await lint(
title,
lintOptions.rules,
lintOptions.parserPreset ? lintOptions.parserPreset : {}
);
if (!lintResult.valid) {
throw new Error(buildLintError(lintResult.errors));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment