metal-soy-critic
Version:
A metal-soy code validation utility.
32 lines (31 loc) • 1.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const soy_helpers_1 = require("./soy-helpers");
const util_1 = require("./util");
const chalk = require("chalk");
function shouldSort(template) {
const sortedparams = template.params
.concat()
.sort((a, b) => {
if (a.required && !b.required) {
return -1;
}
else if (!a.required && b.required) {
return 1;
}
return a.name.localeCompare(b.name);
});
return sortedparams.map(p => p.name).join() !==
template.params.map(p => p.name).join();
}
function validateSortedParamDeclarations(soyContext) {
const notSorted = soyContext.ast.body
.filter(shouldSort)
.map(soy_helpers_1.fullName);
if (notSorted.length) {
return util_1.toResult(false, `These templates need their ${chalk.yellow('param')} declarations ${chalk.yellow('sorted')}:\n\n` +
util_1.joinErrors(notSorted));
}
return util_1.toResult(true);
}
exports.default = validateSortedParamDeclarations;