assert-foo

Try in Playground
julien-pythonUnknownInformational

0

No tags

No CWE or CVE

Pattern Rule: assert ${something}


assert-foo

How to write a rule
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 = buildEditUpdate(exceptionName.start.line, 
                                 exceptionName.start.col, 
                                 exceptionName.end.line, 
                                 exceptionName.end.col,
                                 "bar");
    const fix = buildFix("replace by bar", [edit]);
    addError(error.addFix(fix));
  }
}

bla.py

Expected test result: has error

assert foo
Add comment

Log in to add a comment


    Be the first one to leave a comment!

Codiga Logo
Codiga Hub
  • Rulesets
  • Explore
  • Cookbooks
  • Playground
soc-2 icon

We are SOC-2 Compliance Certified

G2 high performer medal

Codiga – All rights reserved 2022.