angular2, file should end with a newline, and trailing space
Asked Answered
R

4

8

I am new to angular2 and typescript, I got this 3 errors, I don't understand how to fix trailing whitespace and file should end with a newline.

enter image description here

Roo answered 19/10, 2016 at 19:4 Comment(2)
Just ensure that the last line is an empty line and that the "trailing whitespace" lines don't have space characters at the end of the line. I guess there are ways to disable these checks or to get them fixed automatically but I don't know about these.Twofaced
I was reading through all the answers and was looking for a logical reason why we need new line at the end of the file. Some older tools are not working properly if the new line is missing, so it is recommend to add new line at the end of the file. Details:#2288467Bev
J
8

The error is coming from your code linter.

A code linter looks for code formatting inconsistencies and throws exceptions when you violate some rules (that you can specify manually).

This means it's a formatting error on your code. Your linter is basically telling you to add an empty line at the end of the file events/event-list.component.ts. Moreover, there is a trailing whitespace somewhere in that file. There are text editor tools that can do this built-in or with a plugin, and I suggest looking for that feature on your editor. If not, you can look for online tools that strip trailing whitespace on your code.

Jello answered 19/10, 2016 at 19:10 Comment(3)
@Roo You could turn on automatic whitespace trimming on file save by turning on this option. Beyond that, your auto-formatting options are limited. Consider either switching to a local editor like Atom or Sublime, or turning off your code linter if you're bothered by it.Jello
what is the point in adding a new line at the end of file. Is there any benefits on doing so? @JeromeIndefenzoBerri
@PitchiahNatarajan There are quite a few, although you should easily be able to find those reasons only. Perhaps you can start here: #730192Jello
B
15

The errors come from tslint which defines some rules on your project and check if your code matches the rules. You need to either fix the error or ignore/disable those rules.

file should end with a newline

You can ignore this rule on tslint.json by adding this on the rules object property

 "eofline": false

-

trailing whitespace

You can ignore this rule on tslint.json by adding this on the rules object property

 "no-trailing-whitespace": false

More about the rules: https://palantir.github.io/tslint/rules/

Blair answered 20/5, 2017 at 18:22 Comment(0)
J
8

The error is coming from your code linter.

A code linter looks for code formatting inconsistencies and throws exceptions when you violate some rules (that you can specify manually).

This means it's a formatting error on your code. Your linter is basically telling you to add an empty line at the end of the file events/event-list.component.ts. Moreover, there is a trailing whitespace somewhere in that file. There are text editor tools that can do this built-in or with a plugin, and I suggest looking for that feature on your editor. If not, you can look for online tools that strip trailing whitespace on your code.

Jello answered 19/10, 2016 at 19:10 Comment(3)
@Roo You could turn on automatic whitespace trimming on file save by turning on this option. Beyond that, your auto-formatting options are limited. Consider either switching to a local editor like Atom or Sublime, or turning off your code linter if you're bothered by it.Jello
what is the point in adding a new line at the end of file. Is there any benefits on doing so? @JeromeIndefenzoBerri
@PitchiahNatarajan There are quite a few, although you should easily be able to find those reasons only. Perhaps you can start here: #730192Jello
D
3

At the end of the export class, at "}", simply press enter. That should take the cursor to a new line. This takes away the error.

Derrek answered 1/10, 2018 at 8:8 Comment(2)
Thanks Siddhant!!! Your solution worked for me, we just need to press enter after "}" of export classU
Awesome, short & simple...Vassalize
L
1

You can just give it what it is asking for by pressing enter in case of a newline or removing trailing space by going to that location and hitting backspace.

Lugworm answered 7/1, 2018 at 13:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.