Skip to content

Commit

Permalink
Fix: newline-before-return: bug with comment (fixes #5480)
Browse files Browse the repository at this point in the history
  • Loading branch information
diki committed Mar 8, 2016
1 parent ef341be commit 03e6869
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/rules/newline-before-return.js
Expand Up @@ -75,6 +75,23 @@ module.exports = function(context) {
}

comments.forEach(function(comment) {
// https://github.com/eslint/eslint/pull/5512
/*
function main() {
var test = {
//
};
//
return 1;
}
on the code block above number of comment lines are miscalculated
sourceCode.getComments(node).leading method also counts comment lines inside block expression
if there are no other expressions between return and block
*/
if (comment.loc.start.line < tokenBefore.loc.end.line) {
return;
}
numLinesComments++;

if (comment.type === "Block") {
Expand Down
1 change: 1 addition & 0 deletions tests/lib/rules/newline-before-return.js
Expand Up @@ -53,6 +53,7 @@ ruleTester.run("newline-before-return", rule, {
"function a() {\nfor (b in c) { return; }\n}",
"function a() {\nfor (b in c) {\nreturn;\n}\n}",
"function a() {\nfor (b in c) {\nd();\n\nreturn;\n}\n}",
"function a() {\nvar b = {\n//comment\n};\n\nreturn;\n}",
{
code: "function a() {\nfor (b of c) return;\n}",
parserOptions: { ecmaVersion: 6 }
Expand Down

0 comments on commit 03e6869

Please sign in to comment.