Sublime Forum

Java Script formatting plugin, need your help

#1

Hey there,
since I am going to work alot with Java Script now I wanted a plugin for Java Script text auto formatting, similar to auto pep8. The plugins I found were a old and not configurable so I used what was there and improved it.
Here is the result: github.com/select/sublime-text-jsbeautifier
But wait I still have some issues to solve before I can submit it to the plugin manager

  1. When I re-format just one line jsbeautifier takes away the original indentation. I guess this is because it was meant for formating whole files. Any hints on how to get back the leading tabs/spaces?

  2. I am not sure how to parse user preferences or if I even have to. Any hints?

0 Likes

#2

Oh and another issue is that this plugin so far executes on all files not just java script files. Another issue I could need some hints on how to restrict it to js files only.

0 Likes

#3

Haven’t looked at the code so the following is just speculation.

  1. You would have to modify the command to handle single line inputs before formatting.

  2. You would do something like sublime.load_settings(“JsFormat.sublime-settings”). This will return a settings object.

  3. You can use something like view.settings().get(“syntax”) to find out what syntax is being used. You can also view.file_name() to get the name of the file and check for the .js extension.

  4. Welly ou don’t have a fourth point but wanted to ask this. Have you looked at JsFormat? I believe it uses the same library, and is actively maintained. It may already have some of the features you are looking for.

0 Likes

#4

ha should have asked before starting to work
but I just could not find JsFormat :frowning:

0 Likes

#5

anyway thanks alot for the help and I learned quite a bit on how easy it is to write sublime plugins :smile:

0 Likes

#6

Why don’t you include css-beautifier and html-beautifier from the same jsbeatifier’s project as well? (they are included and function almost the same)

0 Likes