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"]
}
}
Error as above
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.
+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...!_
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:
๐ 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!_