Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If no-consecutive-blank-lines is set to false or [true, <n>] in tslint.json blank lines are always collapsed to one #129

Open
InExtremaRes opened this issue Jul 1, 2018 · 1 comment

Comments

@InExtremaRes
Copy link

InExtremaRes commented Jul 1, 2018

Having this file (with 4 empty/blank lines):

const x = 'hello';




console.log(x);

and tslint.json:

{
  "rules": {
    "no-consecutive-blank-lines": false
  }
}

Running tsfmt -r replaces the file and removes consecutive blank lines as this:

const x = 'hello';

console.log(x);

Expected behavior

I expect the output file sill has consecutive blank lines (as the original) since no-consecutive-blank-lines is explicitly set to false. If tslint.json contains "no-consecutive-blank-lines": [true, 2] I would expect the output file gets removed some blank lines but keeps two of them. Instead every time no-consecutive-blank-lines is set to something all blank lines are collapsed to one.

If I run npx tsfmt --no-tslint -r then blank lines are not removed. The same if I take off the option of tslint.json at all.

By the way, why that option needs to be addressed here in a postprocessing? Isn't that on the tslint realm? Users can just run tslint --fix and let it take care of this.

@aserra54
Copy link

I believe this is due to tslintjson.ts ignoring the value of no-consecutive-blank-lines.

    if (rules.has("no-consecutive-blank-lines")) {
        formattedCode = formattedCode.replace(/\n+^$/mg, "\n");
    }

Looking at the block of code, it could probably be a bit more robust, since it fails for Windows newlines (CRLF) and also doesn't account for "whitespace" blank lines.

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

No branches or pull requests

2 participants