js-security-pwd-check
Ast Rule: try block
js-security-pwd-check
function visit(node, filename, code) {
// If filename starts or ends with test_ or _test, do not do anything
if(filename.includes("_test.py") || filename.startsWith("test_")) {
return;
}
// Get all the exception clauses with just a name equal to "Exception"
const genericExceptions = node.exceptClauses.flatMap(e => e.exceptions.filter(e => e.str === "Exception"));
// For each generic exception
genericExceptions.forEach(exception => {
// report an error there the exception is
const error = buildError(exception.start.line, exception.start.col, exception.end.line, exception.end.col, "generic exception", "WARNING", "BEST_PRACTICES");
addError(error);
});
}
try-exception.py
Expected test result: has error