sublimehq / Packages

Syntax highlighting files shipped with Sublime Text and Sublime Merge
https://sublimetext.com
Other
2.95k stars 586 forks source link

[JavaScript] Smart indent and one-liners #3212

Open hyrious opened 2 years ago

hyrious commented 2 years ago

Problem description

If you enabled smart_indent (enabled by default) and write code like this:

if (true) return 1<enter>
  | <- caret here

This is a tiny enhancement request to this config -- don't auto-indent the next line of one-liners in JavaScript variants.

Some C-like languages would force you to write a ; after every statement, but in JavaScript it doesn't. Further more, it has such behavior: it will automatically insert a ; after the next expression right of return (must be same line). i.e. return\n1 is the same as return;\n1, which returns undefined.

Preferred solution

I hope sublime could add a special treatment to JavaScript variant languages, don't "smartly" indent a caret after an one-liner expression. i.e. as of the example above:

if (true) return 1<enter>
| <- caret here (expected)

Alternatives

I didn't find a way to configure smart-indent behavior, I believe it is hard to come up with a solution to handle many languages. So I hope sublime could add special treatment to a language, that's it.

Additional Information

https://stackoverflow.com/questions/2846283/what-are-the-rules-for-javascripts-automatic-semicolon-insertion-asi

deathaxe commented 2 years ago

Reopening this issue as the fix has been regressed by b984aef113ee2d23a4dc850a62e7027c9c1918df