JsFormat
Javascript formatting for Sublime Text 2 & 3
Details
Installs
- Total 889K
- Win 552K
- Mac 241K
- Linux 97K
Nov 21 | Nov 20 | Nov 19 | Nov 18 | Nov 17 | Nov 16 | Nov 15 | Nov 14 | Nov 13 | Nov 12 | Nov 11 | Nov 10 | Nov 9 | Nov 8 | Nov 7 | Nov 6 | Nov 5 | Nov 4 | Nov 3 | Nov 2 | Nov 1 | Oct 31 | Oct 30 | Oct 29 | Oct 28 | Oct 27 | Oct 26 | Oct 25 | Oct 24 | Oct 23 | Oct 22 | Oct 21 | Oct 20 | Oct 19 | Oct 18 | Oct 17 | Oct 16 | Oct 15 | Oct 14 | Oct 13 | Oct 12 | Oct 11 | Oct 10 | Oct 9 | Oct 8 | Oct 7 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Windows | 8 | 23 | 13 | 26 | 18 | 17 | 21 | 0 | 0 | 35 | 35 | 35 | 18 | 30 | 30 | 42 | 37 | 28 | 16 | 16 | 21 | 29 | 30 | 30 | 32 | 15 | 7 | 33 | 35 | 51 | 43 | 34 | 11 | 21 | 28 | 48 | 35 | 28 | 40 | 12 | 15 | 45 | 49 | 39 | 26 | 44 |
Mac | 8 | 28 | 12 | 55 | 12 | 11 | 51 | 0 | 0 | 55 | 26 | 6 | 7 | 40 | 52 | 48 | 45 | 58 | 11 | 8 | 44 | 45 | 56 | 58 | 51 | 13 | 15 | 45 | 62 | 44 | 48 | 39 | 15 | 9 | 38 | 68 | 48 | 41 | 54 | 14 | 14 | 46 | 53 | 56 | 54 | 45 |
Linux | 1 | 10 | 2 | 10 | 4 | 6 | 9 | 0 | 0 | 6 | 13 | 3 | 7 | 12 | 21 | 12 | 11 | 10 | 4 | 6 | 6 | 9 | 12 | 9 | 10 | 3 | 5 | 8 | 6 | 9 | 13 | 13 | 4 | 6 | 6 | 8 | 9 | 7 | 17 | 4 | 3 | 16 | 10 | 11 | 10 | 5 |
Readme
- Source
- raw.githubusercontent.com
LOOKING FOR AN ADDITIONAL MAINTAINER
I haven't been giving JsFormat the attention it deserves lately, and I'd like to bring on someone else to help maintain the project. Shoot me an email if you are interested.
About the project
JsFormat is a javascript formatting plugin for Sublime Text 2. It uses jsbeautifier to format whole js or json files, or the selected portion(s).
Features
- javascript/json formatting (obviously)
- all settings are customizable (whitespace, formatting style, etc..)
- .jsbeautifyrc settings files support for even more control on a per-project basis
- puts the cursor back in the same location it was before formatting (accounts for whitespace/newline changes)
- Sublime Text 3 support
Settings
JsFormat uses whatever tab/indent settings are configured with the standard translate_tabs_to_spaces
and tab_size
sublime settings.
The following JsBeautifier settings are available in JsFormat/JsFormat.sublime-settings (defaults shown below). Check out the official jsbeautifier documentation for more details on the options:
indent_with_tabs
: falsemax_preserve_newlines
: 4preserve_newlines
: truespace_in_paren
: falsejslint_happy
: falsebrace_style
: “collapse”keep_array_indentation
: falsekeep_function_indentation
: falseeval_code
: false,unescape_strings
: false,break_chained_methods
: false*e4x
: falsewrap_line_length
: 0space_after_anon_function
: false
The following JsFormat specific settings are also exposed:
format_on_save
: false (format files on buffer save)format_on_save_extensions
: [“js”, “json”]jsbeautifyrc_files
: false (see the .jsbeautifyrc files section)
I had temporary lapse of judgment a while back and merged a pull request that modified jsbeautifier. As a result, the functionality that
was added from that pull request has been lost; "ensure_space_before_linestarters"
is no longer supported.
The JsFormat specific ensure_newline_at_eof_on_save
setting has also been removed. This functionality exists in sublime core.
jsbeautifyrc files
JsFormat now supports .jsbeautifyrc
JSON files (disabled by default), which themselves support any of the exposed JsBeautifier options. The option augmentation order is: default options -> user settings -> .jsbeautifyrc
option files.
A hierarchy of .jsbeautifyrc
files is supported, where rc files at the deeper levels override the settings from rc files at higher levels. For example, given the file structure listed below, formatting /home/you/myProject/app.js
would inherit settings from: default -> user settings -> /home/you/myProject/.jsbeautifyrc
, while formatting /home/you/myProject/tests/test.js
would inherit settings from: default -> user settings -> /home/you/myProject/.jsbeautifyrc
-> /home/you/myProject/tests/.jsbeautifyrc
- /home/you/myProject/.jsbeautifyrc
- /home/you/myProject/app.js
- /home/you/myProject/tests/.jsbeautifyrc
- /home/you/myProject/tests/test.js
Installation
Package Control (Recommended)
JsFormat is now included in the default repository channel for Package Control. It should show up in your install list with no changes.
If it does not show up, or you are on an older version of Package Control, add https://github.com/jdavisclark/JsFormat as a Package Control repository. JsFormat will show up in the package install list.
Git Clone
Clone this repository in to the Sublime Text 2 “Packages” directory, which is located where ever the “Preferences” -> “Browse Packages” option in sublime takes you.
Key Bindings
The default key binding is “ctrl+alt+f”
Key Binding Conflicts
Unfortunately there are other plugins that use “ctrl + alt + f”, this is a hard problem to solve. If JsFormat works OK via the command palette but does nothing when you use the “ctrl + alt + f” shortcut, you have two options:
- Add
{ "keys": ["ctrl+alt+f"], "command": "js_format", "context": [{"key": "selector", "operator": "equal", "operand": "source.js,source.json"}] }
to your user keybindings file. This will override anything specified by a plugin. - Find the offending plugin, and change the shortcut in its sublime-keymap file (will revert on updates)
Command Palette
Open the command palette via “ctrl + shift + p”, Jsformat appears as “Format: Javascript”
License
Copyright © 2012 Davis Clark
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.