Vale: Enforce vale to be run on CI

This commit is contained in:
Himanshu Mishra
2020-10-14 11:16:23 +02:00
parent 3b17fa02f8
commit c1d6bc03f6
+14 -10
View File
@@ -23,8 +23,9 @@ const inheritStdIo = {
const LINT_SKIPPED_MESSAGE =
'Skipping documentation quality check (vale not found). Install vale linter (https://docs.errata.ai/vale/install) to enable.\n';
const ERROR_MESSAGE = `Language linter (vale) generated errors. Please check the errors and review any markdown files that you changed.
const LINT_ERROR_MESSAGE = `Language linter (vale) generated errors. Please check the errors and review any markdown files that you changed.
Possibly update .github/styles/vocab.txt to add new valid words.\n`;
const VALE_NOT_FOUND_MESSAGE = `Language linter (vale) was not found. Please install vale linter (https://docs.errata.ai/vale/install).\n`;
// Note: Make sure the script is run as `node check-docs-quality.js [FILES]` instead of `./check-docs-quality.js [FILES]`
// If the script receives arguments (file paths), the script is run exclusively on them. (e.g. when run via pre-commit hook)
@@ -47,27 +48,29 @@ const getFilesToLint = () => {
};
// Proceed with the script only if Vale linter is installed. Limit the friction and surprises caused by the script.
// On CI, we want to ensure vale linter is run.
commandExists('vale')
.catch(() => {
if (process.env.CI) {
console.log(VALE_NOT_FOUND_MESSAGE);
process.exit(1);
}
console.log(LINT_SKIPPED_MESSAGE);
// process.exit(0);
process.exit(1);
process.exit(0);
})
.then(() => {
const filesToLint = getFilesToLint();
console.log('files to lint');
console.log(filesToLint);
// xargs is not supported by shx.
if (process.platform === 'win32') {
// Windows
try {
const output = spawnSync('vale', filesToLint, inheritStdIo);
// if the command does not succeed
// If the command does not succeed
if (output.status !== 0) {
// if it contains system level error. [in this case vale does not exist]
// If it contains system level error. In this case vale does not exist.
if (output.error) {
console.log(ERROR_MESSAGE);
console.log(LINT_ERROR_MESSAGE);
}
process.exit(1);
}
@@ -76,9 +79,10 @@ commandExists('vale')
process.exit(1);
}
} else {
// Unix
const output = spawnSync('vale', filesToLint, inheritStdIo);
if (output.status !== 0) {
console.log(ERROR_MESSAGE);
console.log(LINT_ERROR_MESSAGE);
process.exit(1);
}
}