ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Js​Format

by jdavisclark ALL Top 100

Javascript formatting for Sublime Text 2 & 3

Details

  • 2022.04.05.07.25.38
  • github.​com
  • github.​com
  • 3 years ago
  • 3 hours ago
  • 13 years ago

Installs

  • Total 893K
  • Win 554K
  • Mac 242K
  • Linux 97K
Jan 30 Jan 29 Jan 28 Jan 27 Jan 26 Jan 25 Jan 24 Jan 23 Jan 22 Jan 21 Jan 20 Jan 19 Jan 18 Jan 17 Jan 16 Jan 15 Jan 14 Jan 13 Jan 12 Jan 11 Jan 10 Jan 9 Jan 8 Jan 7 Jan 6 Jan 5 Jan 4 Jan 3 Jan 2 Jan 1 Dec 31 Dec 30 Dec 29 Dec 28 Dec 27 Dec 26 Dec 25 Dec 24 Dec 23 Dec 22 Dec 21 Dec 20 Dec 19 Dec 18 Dec 17 Dec 16
Windows 25 27 33 27 12 9 16 35 37 38 28 14 7 28 37 31 38 25 18 19 29 33 32 33 26 11 18 32 30 15 22 16 14 8 24 73 26 24 29 11 13 30 32 47 32 34
Mac 33 60 45 48 13 6 38 58 60 71 37 15 14 45 49 41 55 42 10 16 48 42 42 48 52 20 11 35 34 9 27 26 9 11 33 25 15 34 32 8 8 35 49 53 38 42
Linux 4 11 9 10 7 2 10 12 6 14 7 7 4 7 7 3 12 10 2 4 5 8 5 8 5 1 2 7 5 4 7 11 5 4 8 4 5 6 5 4 5 6 12 12 17 17

Readme

Source
raw.​githubusercontent.​com

FOSSA Status

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: false
  • max_preserve_newlines: 4
  • preserve_newlines: true
  • space_in_paren: false
  • jslint_happy: false
  • brace_style: “collapse”
  • keep_array_indentation: false
  • keep_function_indentation: false
  • eval_code: false,
  • unescape_strings: false,
  • break_chained_methods: false*
  • e4x: false
  • wrap_line_length: 0
  • space_after_anon_function: false

The following JsFormat specific settings are also exposed:

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:

  1. 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.
  2. 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.

FOSSA Status