metal-soy-critic
Version:
A metal-soy code validation utility.
28 lines (27 loc) • 997 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const soy_helpers_1 = require("./soy-helpers");
const util_1 = require("./util");
const chalk = require("chalk");
function formatMessage(node) {
const firstLine = node.body[0].mark.start.line;
const lastLine = node.body[node.body.length - 1].mark.end.line;
return `${soy_helpers_1.fullName(node)} - Lines ${firstLine} to ${lastLine}`;
}
function validateSortedParams(soyContext) {
const calls = [];
soyContext.visit({
Call(node) {
const paramNames = node.body.map(param => param.name);
if (!util_1.isSorted(paramNames)) {
calls.push(formatMessage(node));
}
}
});
if (!calls.length) {
return util_1.toResult(true);
}
return util_1.toResult(false, `Please ${chalk.yellow('sort')} the params in these ${chalk.yellow('calls')}:\n\n` +
util_1.joinErrors(calls));
}
exports.default = validateSortedParams;