import-example

Try in Playground
typescript-templatesUnknownInformational

0

No tags

No CWE or CVE

Ast Rule: import


import-example

How to write a rule
function visit(node, filename, code) {

  if (node.pkg && node.pkg.value) {
    console.log(node.pkg.value);
  }

  if (node.importedNames) {
    node.importedNames.forEach((n) => {
      if (n && n.name && n.name.value && n.name.value === "usequery") {
        const error = buildError(n.name.start.line,
          n.name.start.col,
          n.name.end.line,
          n.name.end.col,
          "do not use usequery", "CRITICAL", "SAFETY");
        const edit = buildEditUpdate(
          n.name.start.line, n.name.start.col,
          n.name.end.line, n.name.end.col,
          "useQuery");
        const fix = buildFix("use useQuery instead", [edit]);

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

test-import.ts

Expected test result: has error

import { useQuery, useMutation } from "@apollo/client";
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.