function-call-simple-name

Try in Playground
javascript-templatesBest PracticeInformational

0

No tags

No CWE or CVE

Example of a function call check. The function call is a simple name (e.g. bar) and does not contain a prefix (e.g. foo.bar).

Ast Rule: function call


function-call-simple-name

How to write a rule
// See https://doc.codiga.io/docs/rosie/ast/javascript/rosie-ast-javascript-functioncall/
function visit(node, filename, code) {
  
  // Check this is a function call and the function name is a simple string
  if(node.functionName && 
     node.functionName.astType === "string" &&
     node.functionName.value === "bar"){

    // Check the name from bar to baz
    const editChangeFunctionCall = buildEditUpdate(node.functionName.start.line, node.functionName.start.col, node.functionName.end.line, node.functionName.end.col, "baz");
    const fix = buildFix("use baz", [editChangeFunctionCall]);

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

program.js

Expected test result: has error

var bla = 1;
var foo = bar(baz);
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.