Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

newline-before-return false positive #2311

Closed
YKlos opened this issue Mar 7, 2017 · 1 comment
Closed

newline-before-return false positive #2311

YKlos opened this issue Mar 7, 2017 · 1 comment

Comments

@YKlos
Copy link

YKlos commented Mar 7, 2017

Bug Report

  • TSLint version: 4.5.1
  • TypeScript version: 2.2.1
  • Running TSLint via: Node.js API

TypeScript code being linted

class HelloWorld {

    test() {
        console.log("Any statement");
        // Any comment

        return;
    }
}

with tslint.json configuration:

"rules":
{
    "newline-before-return": true
}

Actual behavior

If there is a comment between the last statement and the return statement, tslint throws a false positive "Missing blank line before return"

Expected behavior

@sbj42
Copy link
Contributor

sbj42 commented Mar 8, 2017

Here's another case not covered by the rule:

function foo() {
    fn();
    // comment

    // comment
    return;
}

The if (comments) { ... } block in newlineBeforeReturnRule.ts should probably check if:

  • There's a blank line in between one comment and another
  • Or there's a blank line after the last comment

Either of those conditions could trigger an early return and no warning.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants