Is it possible to format/beautify Javascript in PyCharm?
Asked Answered
F

2

10

PyCharm's Option + Command + L to format HTML, or Python files is very convenient, but it doesn't seem to work for JS, is this an option?

Fondle answered 17/10, 2016 at 21:40 Comment(0)
D
2

Yes it is (possible to format/beautify Javascript)!
The trick lies in TextMate Bundles. Below instructions are for Pycharm Community 2018.1.4

1) Go to the TextMate repo and look for the javascript tmbundle
2) Download the zip and unzip
3) In Pycharm, go to Settings -> Editor -> TextMate Bundles
4) Add new Bundle via the green + top right and select the javascript.tmbundle-master folder
5) If you get the same yellow box that says Some extensions declared in attached bundles are already used by native file types., then Show details -> Unregister native file type
6) Pycharm will then re-index, which may take a long time. After indexing is complete you should have javascript text highlighting.

enter image description here

Here is an arbitrary code sample

enter image description here

Delta answered 27/7, 2018 at 22:33 Comment(0)
K
3

This works to beautify JS on Windows in PyCharm Professional 2018.3:

  1. Ensure your cursor is active inside the js file you want to beautify.
  2. Alt + Ctrl + Shift + L to bring up the "Reformat File" popup.
  3. Select "whole file" radio button and checkboxes for "Rearrange code" and "Code Cleanup".
Koralle answered 9/1, 2019 at 9:15 Comment(1)
Works for linux as wellRocket
D
2

Yes it is (possible to format/beautify Javascript)!
The trick lies in TextMate Bundles. Below instructions are for Pycharm Community 2018.1.4

1) Go to the TextMate repo and look for the javascript tmbundle
2) Download the zip and unzip
3) In Pycharm, go to Settings -> Editor -> TextMate Bundles
4) Add new Bundle via the green + top right and select the javascript.tmbundle-master folder
5) If you get the same yellow box that says Some extensions declared in attached bundles are already used by native file types., then Show details -> Unregister native file type
6) Pycharm will then re-index, which may take a long time. After indexing is complete you should have javascript text highlighting.

enter image description here

Here is an arbitrary code sample

enter image description here

Delta answered 27/7, 2018 at 22:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.