function-call-example
Ast Rule: function call
function-call-example
function visit(node, filename, code) {
const arguments = node.arguments.values;
/*
* Check each argument. If one argument has the variable "foo" used,
* we report it.
*/
arguments.forEach((a) => {
if (a.value.astType === "string") {
console.log(a.value.value);
if (a.value.value === "foo") {
const error = buildError(a.value.start.line, a.value.start.col,
a.value.end.line, a.value.end.col,
"Do not use foo as value", "WARNING", "BEST_PRACTICE");
addError(error);
}
}
});
/*
* Check the function name. We cannot use my_function, we recommend to use myFunction
*/
if (node.functionName && node.functionName.astType === "string") {
if (node.functionName.value === "my_function") {
const error = buildError(node.functionName.start.line, node.functionName.start.col,
node.functionName.end.line, node.functionName.end.col,
"Do not use function_name", "WARNING", "BEST_PRACTICE");
const edit = buildEditUpdate(node.functionName.start.line, node.functionName.start.col,
node.functionName.end.line, node.functionName.end.col,
"myFunction");
const fix = buildFix("use myFunction", [edit]);
addError(error.addFix(fix));
}
}
}
function-call.ts
Expected test result: has error