Custom rule to detect a new line before return statements

Hi,

I need a custom rule which search for the usage of a new line before each Return statement in JavaScript.

Compliant:

function myFunction(name) {
  
  return "Hello " + name;
}

Is there any example to detect if previous line is empty or not? How can I read previous line, after visiting a return statement? I couldn’t find any similar rule in existing rules.

Thanks…

Hello @emre,

First of all, I have to warn you that custom rules for JS are deprecated since SonarJS 6.0.

I don’t think working on new custom rules is a wise idea at this point. As a replacement, I suggest you to have a look at ESLint, it provides custom rules that you can then import thanks to the external issues feature.

Hope this helps,
Quentin