function-must-have-type

Try in Playground
typescript-best-practicesUnknownInformational

0

No tags

No CWE or CVE

Ast Rule: function definition


function-must-have-type

How to write a rule
function visit(node, filename, code) {
  if (node.parameters && node.parameters.values && node.parameters.values.length > 0) {

    node.parameters.values.forEach(a => {
      if (!a.type && a.name) {
        const error = buildError(a.name.start.line, a.name.start.col,
          a.name.end.line, a.name.end.col,
          "add a type", "MINOR", "BEST_PRACTICE");
        const edit = buildEditAdd(
          a.name.end.line, a.name.end.col,
          ": unknown");
        const fix = buildFix("add unknown type (refine once added)", [edit]);

        addError(error.addFix(fix));
      }
    });

  }
}

no-type.ts

Expected test result: has error

function foo(bar) {
}
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.