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

(no-trailing-whitespace) flags leading empty line as error #4518

Closed
itanex opened this issue Feb 14, 2019 · 3 comments
Closed

(no-trailing-whitespace) flags leading empty line as error #4518

itanex opened this issue Feb 14, 2019 · 3 comments

Comments

@itanex
Copy link

itanex commented Feb 14, 2019

Bug Report

  • TSLint version: 5.11.0
  • TypeScript version: 2.9.2
  • Running TSLint via: CLI / (Visual Studio - does not show this error)

TypeScript code being linted

Multiple classes with a leading line that is empty. This line only contains line endings when analyzed (e.g. \r\n)

export class User {
    userName: string;
}

with tslint.json configuration:

{
  "defaultSeverity": "error",
  "extends": "tslint:recommended",
  "jsRules": {},
  "rules": {
    "quotemark": [
      true,
      "single",
      "avoid-escape"
    ],
    "member-access": [
      true,
      "no-public"
    ],
    "object-literal-sort-keys": [
      false
    ],
    "object-literal-shorthand": [
      true,
      "never"
    ],
    "ordered-imports": [
      false
    ],
    "trailing-comma": [
      true,
      {
        "esSpecCompliant": true
      }
    ]
  },
  "rulesDirectory": [],
  "linterOptions": {
    "exclude": [
      "src/test.ts",
      "src/main.ts",
      "src/polyfills.ts"
    ]
  }
}

Actual behavior

Multiple results identical to the following

ERROR: ClientApp/src/app/models/ActionItem.ts:1:1 - trailing whitespace

Expected behavior

No results generated

@JoshuaKGoldberg
Copy link
Contributor

@itanex thanks for the bug report! I tried reproducing this locally but couldn't. Is the project you're experiencing this with open source, or failing that, could you upload ActionItem.ts or another file it's happening on?

One guess would be that the file has some \r\n lines and some \n.

@itanex
Copy link
Author

itanex commented Feb 20, 2019

@JoshuaKGoldberg Yes the file line endings are windows line endings (\r\n).

I have uploaded the ActionItem.ts file along with the tslint.json.

Please note that the ActionItems.ts file is generated through TypeWriter, so simply deleting the line is not a viable option, as this would need to be done anytime the file is regenerated.

https://github.com/itanex/random-files/tree/master/tslint-bugs/4518

@JoshuaKGoldberg
Copy link
Contributor

This was a fun one to debug! The root issue is that getLineRanges from the tsutils library is reporting that the first line in the ActionItem.ts file has a contentLength of 1 instead of 0. Filed ajafff/tsutils#94 to track.

Accepting PRs to fix in this library in the meantime, since even if tsutils releases a version with a fix, TSLint still accepts older versions of tsutils.

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

No branches or pull requests

3 participants