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

Autofix file should end with a newline #2186

Closed
ryanmcnamara opened this issue Feb 7, 2017 · 8 comments · Fixed by #2393 or singapore/lint-condo#263
Closed

Autofix file should end with a newline #2186

ryanmcnamara opened this issue Feb 7, 2017 · 8 comments · Fixed by #2393 or singapore/lint-condo#263

Comments

@ryanmcnamara
Copy link

Bug Report

TSLint version: 4.0.2
TypeScript version: 2.1.4
Running TSLint via: CLI
TypeScript code being linted

export const x = "x";

Enable the file end with newline rule, and see that it fails the linter.

TSLint could autofix this error. It currently does not.

@ryanmcnamara
Copy link
Author

I wouldn't mind trying to fix this but I'm not sure when I'd have the time

@ajafff
Copy link
Contributor

ajafff commented Feb 7, 2017

How do you know which line ending to choose? \r\n or \n?
Of course this could be inferred from the other line endings in the file, but what if there is only a single line?

@ryanmcnamara
Copy link
Author

Good point.
One idea is to only autofix this when there are multiple lines in the file, that way the line ending can be inferred.
Another strategy is just to guess. Not ideal, could potentially be configured, but that seems like a lot of overhead for such a small edge case.
Does the existing TSLint rule just check that the file ends in \r\n or \n?

@ajafff
Copy link
Contributor

ajafff commented Feb 7, 2017

Does the existing TSLint rule just check that the file ends in \r\n or \n?

It just checks if the last character is \n. That covers both cases.
I like the idea of fixing only multiline files. Otherwise when guessing wrong we could introduce new failures for the linebreak-style rule.

@ryanmcnamara
Copy link
Author

Is it possible to check what the value of the linebreak-style rule is while trying to autofix the eofline rule?

@ajafff
Copy link
Contributor

ajafff commented Feb 7, 2017

Nope, currently each rule is limited to its own configuration.
There is no way to access the config of another rule, although that would be pretty useful in many cases.

@nchen63
Copy link
Contributor

nchen63 commented Feb 7, 2017

I don't think we want rules reading options that don't belong to it. I'm fine with only fixing files with multiple lines.

@ajafff ajafff mentioned this issue Mar 23, 2017
4 tasks
adidahiya pushed a commit that referenced this issue Mar 25, 2017
Linebreak style is determined by the first line break in the file. If there is only one line, there will be no fix. Fixes: #2186. Also reorganized the test files.

[new-fixer] `eofline`
@mohdsalaudin
Copy link

mohdsalaudin commented Mar 26, 2019

How do you know which line ending to choose? \r\n or \n?
Of course this could be inferred from the other line endings in the file, but what if there is only a single line?

hi there
Just put enter and add a new line and save the file this warning will disappear

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

Successfully merging a pull request may close this issue.

4 participants