turn-assert-foo-to-bar

Try in Playground
foo-to-bar

Shan Shah

UnknownInformational

0

No tags

No CWE or CVE

Pattern Rule: assert ${something}


turn-assert-foo-to-bar

How to write a rule
function visit(nodeOrPattern, filename, code) {
  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));
  }
}

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
Legal
  • Security
  • Privacy Policy
  • Code Privacy
  • Terms of Service
soc-2 icon

We are SOC-2 Compliance Certified

G2 high performer medal

Codiga – All rights reserved 2022.