-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deno(fmt): adds optional semicolon thinking it's not optional #24285
Comments
@dsherret probably there is a rule you have that if a line starts with +, you insert a semicolon. However that is not necessary for ++ and --, because they are prefixed with a no-newline-terminator-here. |
@lucacasonato @BlackAsLight @dsherret I think we should remove + - from the is_prefix_semi_colon_insertion_char rule ? |
While a semicolon before a With the below code, a semicolon prefixing the last line will change the way it's interpreted from the value of let x = '5'
let y = x + x
+x On the other hand though, a line that started with |
Yes, I understand and I did that. I've introduced a case for '+x' and '-x' that should add ; to be ';+x' ';-x', and I've prevented add ; in the ++ -- scenario. check this PR it has test explaining all cases ` == shouldn't insert semi-colons at the start of lines beginning with a bracket == [expect] == shouldn't insert semi-colons at the start of lines beginning with a bracket == [expect] == should insert semi-colons at the start of lines beginning with a bracket == [expect] == should insert semi-colons at the start of lines beginning with a bracket == [expect] |
Hello, not sure if this is the same issue or not, but I also tried using no semicolons with fmt and Deno inserts a semicolon in a very unexpected place. Minimal repro code: let resp = [1]
let status = null
if (Array.isArray(resp)) {
[status] = resp
} After running let resp = [1]
let status = null
if (Array.isArray(resp)) {
;[status] = resp
} A semicolon was added before |
@hourianto that one is expected. Prettier does the same thing: https://prettier.io/playground/#N4Igxg9gdgLgprEAuEAbOMAEAnOBnAB0wF5MBtARgF0AdKdLPGAQxgFc8TMo3VU66ASwBmmABQBBbNmYBPAHSC8UmbLG5CASk2ZgdTOSasOVLhoJ0AviAA0ICARiDoeZKGbSIAdwAKHhK4ozKhecq52AEYyYADWGADKzAC2cAAyglBwyMLBeHCR0XEw8QTMYBkA5sgw2Gz5IHlJgtm59XAAHgRw2IIpsMEAKt1QHoL4Lah5dniV6ACKbBDwE1MgAFZ47fGzcAtLWUg5k-UAjovwPtgOgSDMeAC0mXAAJi+2IDXMgqiVAMIQSSSzGQtz47xmUAq6AkMBqggibAu3XSmRW9QAFjAkqgAOrowTwQhlODxAIEwQANwJshBYDw4RAFLqAEkoK9YPEwD1HBI2fEYLJ0Gi7AQrnkcTICCDRfhuhSsnYMnlsDBLswKkDhSBSthlSCIswInBUO9RRkYDjBM8YOjkAAOAAMdlwZ0EuDVGuBh1adhYEUt1ttSAATHYOHABobAkdVnAkkbnq9nqlmJC2Oq4AAxCDYIGwyog5iIiAgSyWIA The reason is because if you add a statement before that line it could merge with that one causing a bug. |
@dsherret thanks for the info, I'm quite new with TS so it just looked very out of place :) |
Hello, is my solution acceptable? Please take a look. |
Fixed in dprint/dprint-plugin-typescript#648 via dprint-plugin-typescript upgrade in #24819 |
Version: Deno 1.44.4
When the semicolon option is set to false for
deno fmt
, Deno adds the mandatory semicolons at the start of a line instead of at the end of the previous line.It for some reason falsely thinks this line
++x
requires a semicolon at the start;++x
, but this is not the case as with or without the semicolon, the interpretation of the code does not change, and I can't seem to think of one instance where something like this would be valid code.Reproduction
Before
After
The text was updated successfully, but these errors were encountered: