print-foo
Ast Rule: function call
print-foo
function visit(node, filename, code) {
if (filename.includes("_test.py") || filename.startsWith("test_")) {
return;
}
if(!node.functionName || node.functionName.value !== "print") {
return;
}
console.log("bla");
if(!node.arguments || !node.arguments.values || node.arguments.values.length !== 1 || node.arguments.values[0].value.value !== '\"foo\"') {
return;
}
const firstArgument = node.arguments.values[0].value;
const error = buildError(firstArgument.start.line,
firstArgument.start.col,
firstArgument.end.line,
firstArgument.end.col,
"do not print \"foo\"",
"MINOR", "BEST_PRACTICE");
const edit = buildEditUpdate(firstArgument.start.line,
firstArgument.start.col,
firstArgument.end.line,
firstArgument.end.col,
"\"bar\"");
const fix = buildFix("print bar", [edit]);
addError(error.addFix(fix));
}
bla.py
Expected test result: no error
test_foo.py
Expected test result: no error
print-foo.py
Expected test result: has error