function-definition

Try in Playground
typescript-templatesUnknownInformational

0

No tags

No CWE or CVE

Ast Rule: function definition


function-definition

How to write a rule
function visit(node, filename, code) {
  const functionName = node.name.value;
	const arguments = node.parameters;
	
  console.log(functionName);
	
	arguments.values.forEach((a) => {
		console.log(`argument name: ${a.name.value}`);
		
		if(a.type && a.type.astType === "string") {
			console.log(`argument type: ${a.type.value}`);
		}
	});
	
	if(functionName === "foo") {
		const error = buildError(node.name.start.line, node.name.start.col, 
														 node.name.end.line, node.name.end.col,
      "Do not use foo as function name", "WARNING", "BEST_PRACTICE");
    const edit = buildEditUpdate(node.name.start.line, node.name.start.col,
																 node.name.end.line, node.name.end.col, 
																 "bar");
    const fix = buildFix("use bar", [edit]);
    addError(error.addFix(fix));
	}
}

function-definition.ts

Expected test result: has error

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