When I write code with spaces between lines, such as (each "." is a space):
((): void => {
....'use strict';
....
....console.info('hello');
})();
The no-trailing-whitespace rule tells me there is an error on the blank line (in this case line 3). That seems wrong since most editors are going to insert spaces by default, this makes the user have to remove spaces for it to pass. This happens with both spaces & tabs.
This is exactly the intent of the no-trailing-whitespace rule. Most modern editors actually do the _opposite_ -- they remove trailing whitespace upon save, including on empty lines like this -- so it feels like best practice to report this as a lint failure.
If you really want to allow this kind of trailing whitespace in your codebase, you can create a custom tslint rule (see docs for this in the readme) in your project, copy the implementation of noTrailingWhitespaceRule.ts, and have it ignore empty lines.
Thanks a lot!
I would like to see this as an option. Something like ignore-empty-lines.
Looks like there's some interest in this option. Low priority for us, but we're open to PRs.
+1
VsCode by default does not remove whitespace from empty lines.
for VSCode: Version 0.5.0 is out and a new setting has been added to trim whitespace on save (files.trimTrailingWhitespace)
A easy fix if your not worried about the whitespace is to pipe your source through gulp-trimlines.
npm install gulp-trimlines --save-dev
Then in the gulp task:
`function tslint(done) {
return gulp.src("path/to/*.ts")
.pipe($.trimlines())
.pipe($.tslint({
formatter: 'prose',
}))
.pipe($.tslint.report());
done();
}`
Cleans up the whitespace before linting quite well
i think it makes sense to have trailing whitespace on empty lines, especially if you are using something that semantically uses indentation, such as YAML or Python. Can we have a force-trailing-whitespace rule?
@doom777 um, just curious, why would you use tslint on python?
well, you might have something embedded, but I was genereally referring to the overall philosophy. A blank line belongs to a method or a class, or an if block, and therefore should have its indentation.
+1. WebStorm/IntelliJ IDEA has a format option to "preserve indentation on blank lines" which I always use. To me, the spirit of "trailing whitespace" is not to remove indentation.
+1
While in Webstorm, as @aaronbeall wrote, in Settings > Editor > Code Style > Javascript/TypeScript > "Tabs and Indents" tab > [ ] Keep indents on empty lines.
FYI, ESLint has a "skipBlankLines" option to precisely bypass this problem.
With TSLint as of today, we either have to lose one useful feature of modern text editors or get annoyed by a myriad of low value errors.
What do you think is the best course of action:
A) infuriating hundreds of busy developers every hours of every working days or
B) implement the option in 5 mn, set it to true by default and close the issue.
The issue is marked as "Accepting PRs". Feel free to send one.
Fixed by #3346
I believe blank lines and trailing whitespace ought to be treated separately. I do not like for my devs to leave trailing whitespace, but I do like for them to place one blank line before jsdoc comments to improve readability. I would like to see this split apart, because if we turn off _no-trailing-whitespace_ for blank lines, then it allows any number of blank lines which can throw off diff comparisons, and does nothing to improve readability. A _no-blank-lines_ rule could then allow for exceptions such as _before-jsdoc_, _after-method_, etc.
Most helpful comment
for VSCode: Version 0.5.0 is out and a new setting has been added to trim whitespace on save (files.trimTrailingWhitespace)