test-script

Try in Playground
turn-foo-to-bar

Shan Shah

UnknownInformational

0

No tags

No CWE or CVE

Pattern Rule: assert ${something}


test-script

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 = 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

assert foo

foo.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
  • Playground
  • Snippets
  • Cookbooks
soc-2 icon

We are SOC-2 Compliance Certified

G2 high performer medal

Codiga – All rights reserved 2022.