question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow padding on simple returns for newline-before-return

See original GitHub issue

ESLint Version: 2.10.1

Problem:

Using newline-before-return with padded-blocks causes a conflict, as padded-blocks insists on padded spacing for functions, and newline-before-return complains if there is a newline before a return statement by itself in a function.

Recommended Solution:

Add an option to newline-before-return to ignore scenarios where the only statement in a function block is the return statement.

For example:

"newline-before-return": ["error", {
    "pad-getters": true  // (New) Ensure getter returns are padded on either side by a newline
}]

This will allow ESLint to properly support it’s built-in plugins without changing the default functionality of the newline-before-return rule. With the above configuration:

This code would result in an error:

function getVar() {
    return this.var;
}

This code would be valid with both plugins:

function getVar() {

    return this.var;

}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (11 by maintainers)

github_iconTop GitHub Comments

5reactions
albertocommented, May 14, 2016

I think newline-before-return should not error when it is the first statement in a block, regardless of the newlines and that should be left to padded-blocks.

The doc says (emphasis mine):

This rule requires an empty line before return statements to increase code clarity, except when the return is alone inside a statement group (such as an if statement). In the latter case, the return statement does not need to be delineated by virtue of it being alone.

4reactions
markelogcommented, May 17, 2016

Can we document what should be considered as breaking change? See JSCS example https://github.com/jscs-dev/node-jscs/blob/master/OVERVIEW.md#user-content-versioning--semver for reference

Read more comments on GitHub >

github_iconTop Results From Across the Web

newline-before-return - ESLint - Pluggable JavaScript Linter
This rule was deprecated in ESLint v4.0.0 and replaced by the padding-line-between-statements rule. There is no hard and fast rule about whether empty...
Read more >
Has ESlint a rule about blank line before the first statement in ...
The padded-blocks rule allows you to require newlines at the start and end of blocks, including function bodies.
Read more >
Injecting a Line Break | CSS-Tricks
The text after the break should be inline/inline-block, because it's going to have a background and padding and such.
Read more >
The Dos and Don'ts of Adding an HTML Line Break
The second uses multiple paragraph elements and no line breaks. As a result, unnecessary padding and margins are added between lines. HTML.
Read more >
HTML Line Break – How to Break a Line with the HTML <br ...
You can insert line breaks in HTML with the <br> tag, which is equivalent to a carriage return on a keyboard. Be aware...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found