function-definition-argname

Try in Playground
javascript-templatesUnknownInformational

0

No tags

No CWE or CVE

Check that the argument name are foo and propose to replace by bar.

Ast Rule: function definition


function-definition-argname

How to write a rule
function visit(node, filename, code) {
  // check that we have more than one argument
  if(node.parameters && node.parameters.values && node.parameters.values.length > 0){

    const argumentsToUpdate = node.parameters.values.filter(a => a.name && a.name.value === "foo");
    argumentsToUpdate.forEach(a => {
      console.log(a);
      // Edit the argument name and use "bar"
      const editChangeFunctionName = buildEditUpdate(a.name.start.line, a.name.start.col, a.name.end.line, a.name.end.col, "bar");
      const fix = buildFix("use bar", [editChangeFunctionName]);

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

  }
}

function.js

Expected test result: has error

function myFunction(foo, bar, baz) {
   console.log("hello");
}
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.