class-name

Try in Playground
javascript-templatesUnknownInformational

0

No tags

No CWE or CVE

Check the name of a class.

Ast Rule: class definition


class-name

How to write a rule
// See https://doc.codiga.io/docs/rosie/ast/javascript/rosie-ast-javascript-classdefinition/
// for properties and data of the `node` parameter.
function visit(node) {
  // Check the name of the class if this is "Rabbit"
  if(node.name && node.name.value && node.name.value === "Rabbit"){

    // Update the name to "Cow"
    const editChangeFunctionName = buildEditUpdate(node.name.start.line, node.name.start.col, node.name.end.line, node.name.end.col, "Cow");
    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));
  }
}

rabbit.js

Expected test result: has error

class Rabbit extends Animal {
  // generated for extending classes without own constructors
  constructor(...args) {
    super(...args);
  }
}
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.