pivot-table
Ast Rule: function call
pivot-table
function visit(node, filename, code) {
const usePandas = node.context.imports.filter(i => i.astType === "importstatement" && i.packages.filter(p => p.name && p.name.value && p.name.value === "pandas").length > 0).length > 0;
if (!usePandas) {
return;
}
if (node.functionName && node.functionName.value && (node.functionName.value === "pivot" || node.functionName.value === "unstack")) {
if (node.moduleOrObject) {
const error = buildError(node.functionName.start.line, node.functionName.start.col, node.functionName.end.line, node.functionName.end.col,
`do not use ${node.functionName.value}, prefer pivot_table`, "INFO", "BEST_PRACTICE");
const edit = buildEditUpdate(node.functionName.start.line, node.functionName.start.col,
node.functionName.end.line, node.functionName.end.col,
"pivot_table");
const fix = buildFix("use pivot_table", [edit]);
addError(error.addFix(fix));
}
}
}
use-pivot-table.py
Expected test result: no error