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

user1034127
  • 349
  • 3
  • 5
  • 14
  • 1
    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. – Günter Zöchbauer Oct 19 '16 at 19:07
  • 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:https://stackoverflow.com/questions/2287967/why-is-it-recommended-to-have-empty-line-in-the-end-of-a-source-file – Richárd Baldauf Feb 25 '21 at 08:59

4 Answers4

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/

Hans Tiono
  • 808
  • 8
  • 8
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.

Jerome Indefenzo
  • 967
  • 6
  • 25
  • @user1034127 You could turn on automatic whitespace trimming on file save by turning on [this option](http://i.imgur.com/lcbIjVt). 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. – Jerome Indefenzo Oct 19 '16 at 19:33
  • what is the point in adding a new line at the end of file. Is there any benefits on doing so? @JeromeIndefenzo – Pitchiah Natarajan Feb 07 '18 at 12:30
  • @PitchiahNatarajan There are quite a few, although you should easily be able to find those reasons only. Perhaps you can start here: https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline – Jerome Indefenzo Feb 10 '18 at 23:10
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.

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.

RamanSM
  • 275
  • 3
  • 13