TS: 2.0.0
Code
function foo() {
const x = 1
;(x as any).fun = 2
}
Then format the code in VSCode
Expected behavior:
Indention is correct
Actual behavior:
function foo() {
const x = 1
; (x as any).fun = 2
}
that is not really an ASI issue. an ASI is only inserted if the production is not valid one, or the next token is } (see http://www.ecma-international.org/ecma-262/6.0/#sec-rules-of-automatic-semicolon-insertion). In this case, the semicolon belongs to the statement const x = 1. since it is part of the statement and on a new line, it is indented, similar to
function foo() {
const x = -
1
}
So the indentation looks right to me.
Um....I can understand your reasoning.
But how to support coding style relying on ASI?
In this case we do need the "extra" ; to avoid error on (x as any) part.
why not put the semicolon on the previous line?
It's about consistent coding style.
If I put the semicolon on the previous line, tslint will complain:
[tslint] Unnecessary semicolon
https://github.com/blakeembrey/tslint-config-standard
http://standardjs.com/
/cc @blakeembrey , how do you handle this?
this one looks necessary to me :)
lol, definitely agree with you on this one. 馃槅
For "standardjs" style, the convention is to do add semicolon before [, (, and backticks (can't remember how to escape backticks in markdown)
http://standardjs.com/rules.html#semicolons
Personal opinion: anyone remotely sane would use https://github.com/Flet/semistandard instead
:bike: :house:
:bike: :house:
:bike: :house:
I'm also new to "standardjs" and is trying it out to see how it works.
Omitting semicolon does seem to have a positive impact on my coding performance.
I don't have to move the cursor back and forth just to add the semicolon.
Omitting semicolon does seem to have a positive impact on my coding performance.
Except when you spend hours debating the need for omitting semicolons except for the few (several) cases where they are needed/required. 馃槃
Except when you spend hours debating the need for omitting semicolons except for the few (several) cases where they are needed/required
馃槅 time lost is lost. 馃槣
Most helpful comment
why not put the semicolon on the previous line?