function-definition-name

Try in Playground
javascript-templatesUnknownInformational

0

No tags

No CWE or CVE

Ast Rule: function definition


function-definition-name

How to write a rule
function visit(node, filename, code) {
  // Check the name of the function and verify if it is "foo"
  if(node.name && node.name.value && node.name.value === "foo"){

    // Edit the function name and use "bar"
    const editChangeFunctionName = buildEditUpdate(node.name.start.line, node.name.start.col, node.name.end.line, node.name.end.col, "bar");
    const fix = buildFix("use bar", [editChangeFunctionName]);

    const error = buildError(node.name.start.line, node.name.start.col, node.name.end.line, node.name.end.col, "do not use function foo", "CRITICAL", "SAFETY");
    addError(error.addFix(fix));
  }
}

function-definition.js

Expected test result: no error

function foo(bla, bli) {
  console.log("foobar");
}
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.