test-script
Pattern Rule: assert ${something}
test-script
function visit(nodeOrPattern, filename, code) {
if (filename.includes("_test.py") || filename.startsWith("test_")) {
return;
}
const exceptionName = nodeOrPattern.variables.get("something");
if (exceptionName && exceptionName.value === "foo") {
const error = buildError(
exceptionName.start.line,
exceptionName.start.col,
exceptionName.end.line,
exceptionName.end.col,
"do not assert on foo",
"INFO",
"BEST_PRACTICES"
);
const edit = buildEdit(
exceptionName.start.line,
exceptionName.start.col,
exceptionName.end.line,
exceptionName.end.col,
"update",
"bar"
);
const fix = buildFix("replace by bar", [edit]);
addError(error.addFix(fix));
}
}
test_no_error.py
Expected test result: no error
foo.py
Expected test result: has error