Tslint: semi: allow at start of line

Created on 19 May 2017  ยท  7Comments  ยท  Source: palantir/tslint

  • __TSLint version__: 5.2.0
  • __TypeScript version__: 2.4.0
  • __Running TSLint via__: WebStorm

TypeScript code being linted

function forFFxFy(f: R2_R, fx: R2_R, fy: R2_R) {
    ;(f as any).x = fx // tslint: unnecessary semicolon (semicolon)
    ;(f as any).y = fy // no error
    return f
}

with tslint.json configuration:

{
  "rules": {
    "semicolon": [true, "never"]
  }
}

Actual behavior

Error as above

Expected behavior

Strictly speaking, yes, the semicolon is unnecessary, but if code is added before the first line it will cause problems. Also, it's inconsistent :/

It would be nice if the "semi" rule had an option to allow this code style.

Formatting rule P3 Accepting PRs Bug ๐ŸŒน R.I.P. ๐ŸŒน

All 7 comments

+1

Is there a way the solve this problem?

I get 'code is not alligned' and 'missing whitespace' with semicolon at the start of line.

There is no proper solution. Prettier will also disagree on formatting, which is a hassle. As a workaround, you can use a pattern like

const anyF = f as any
anyF.x = fx

Ugly, but still slightly better than disabling and re-enabling align and whitespace rules whenever this comes up?

Here's the rationale from the side of Prettier as to why this should be allowed: https://prettier.io/docs/en/rationale.html#semicolons

Essentially, adding anything above these lines, without semicolons, would cause buggy code, so Prettier takes the defensive stance of being explicit that these are independent statements.

It would be nice if semicolon had an option to allow this type of defensive formatting.

We can take in an option to allow this. The option should include documentation similar to the Prettier docs for why such a seemingly ridiculous thing is necessary.

_aside: this is why I dislike ASI...!_

๐Ÿ’€ _It's time!_ ๐Ÿ’€

TSLint is being deprecated and no longer accepting pull requests for major new changes or features. See #4534. ๐Ÿ˜ฑ

If you'd like to see this change implemented, you have two choices:

  • Recommended: Check if this is available in ESLint + typescript-eslint โœ…
  • _Not Recommended: Fork TSLint locally_ ๐Ÿคทโ€โ™‚๏ธ

๐Ÿ‘‹ It was a pleasure open sourcing with you!

_If you believe this message was posted here in error, please comment so we can re-open the issue!_

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cretz picture cretz  ยท  3Comments

zewa666 picture zewa666  ยท  3Comments

SwintDC picture SwintDC  ยท  3Comments

ghost picture ghost  ยท  3Comments

DanielKucal picture DanielKucal  ยท  3Comments