Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has ESlint a rule about blank line before the first statement in function?

Due ESLint I found a rule newline-before-return about empty line before return statements. But did not see a rule about empty line before the first statement in function. F.e.:

function (a) {

    var b = +a;
}

Has ESlint a rule about this? If it has, what is the name this rule? Thanks

like image 486
ArtemM Avatar asked Aug 23 '16 10:08

ArtemM


People also ask

How do I ignore the next line on ESLint?

How do I ignore ESLint warnings? disable warnings eslint Use /* eslint-disable */ to ignore all warnings in a file. You may use special comments to disable some warnings. Use // eslint-disable-next-line to ignore the next line.

What line endings do you use ESLint?

The linebreaks (new lines) used in windows operating system are usually carriage returns (CR) followed by a line feed (LF) making it a carriage return line feed (CRLF) whereas Linux and Unix use a simple line feed (LF). The corresponding control sequences are "\n" (for LF) and "\r\n" for (CRLF).

What are rules in ESLint?

ESLint comes with a large number of built-in rules and you can add more rules through plugins. You can modify which rules your project uses either using configuration comments or configuration files. To change a rule setting, you must set the rule ID equal to one of these values: "off" or 0 - turn the rule off.

How many ESLint rules are there?

Keep in mind that we have over 200 rules, and that is daunting both for end users and the ESLint team (who has to maintain them). As such, any new rules must be deemed of high importance to be considered for inclusion in ESLint.


2 Answers

The padded-blocks rule allows you to require newlines at the start and end of blocks, including function bodies. In addition to function bodies, it also covers the bodies of if statements, for and while loops, and other block-like structures, which you may or may not want.

Try pasting the following code in the demo to see if it works for you:

/* eslint padded-blocks: "error" */
function foo(bar) {

    if (bar) {

        foo();

    }

}

If you only want to check function bodies, you could follow @Dhananjay's suggestion and edit the rule's source code into your own custom rule.

like image 96
btmills Avatar answered Oct 07 '22 20:10

btmills


I don't think there is such a rule available out of the box based on the list of available rules You can try to add a custom rule for this check as explained here

like image 42
Dhananjay Avatar answered Oct 07 '22 22:10

Dhananjay