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

jsfmt

by ionutvmi ST2/ST3

jsfmt plugin for Sublime Text

Details

Installs

  • Total 9K
  • Win 4K
  • OS X 4K
  • Linux 1K
Sep 23 Sep 22 Sep 21 Sep 20 Sep 19 Sep 18 Sep 17 Sep 16 Sep 15 Sep 14 Sep 13 Sep 12 Sep 11 Sep 10 Sep 9 Sep 8 Sep 7 Sep 6 Sep 5 Sep 4 Sep 3 Sep 2 Sep 1 Aug 31 Aug 30 Aug 29 Aug 28 Aug 27 Aug 26 Aug 25 Aug 24 Aug 23 Aug 22 Aug 21 Aug 20 Aug 19 Aug 18 Aug 17 Aug 16 Aug 15 Aug 14 Aug 13 Aug 12 Aug 11 Aug 10 Aug 9
Windows 0 7 10 10 20 27 4 9 15 15 18 18 28 4 8 12 17 15 19 15 9 4 10 17 9 5 16 4 8 17 13 14 20 18 5 7 11 11 18 18 11 8 8 13 20 25
OS X 0 7 5 11 6 8 10 4 11 11 8 19 11 1 5 9 8 7 15 6 2 4 12 4 9 7 6 8 8 10 9 10 6 7 3 4 7 6 6 5 11 1 10 6 8 3
Linux 0 1 0 1 0 1 0 2 2 2 1 3 0 1 1 0 1 0 1 1 1 2 0 0 1 0 2 0 1 2 3 2 2 1 0 2 1 1 2 1 1 1 1 1 0 3

Readme

Source
raw.​githubusercontent.​com

jsfmt for Sublime Text 2/3

If you want your javascript automatically formatted to abide a particular style, then jsfmt is for you. No need to read warnings and fix things yourself. Just keep it all auto. Boom boom jsfmt is pretty tight. And yeah, if you want it in Sublime Text this is your homeboy.

Enable autoformat then save the file and it gets formatted.

Installation

Via package control
Open your command palette -> Package Control: Install Package -> jsfmt

Manual

## go to your ST packages folder. maybe something like …
cd ~/Library/"Application Support/Sublime Text 2"/Packages

# clone this repo
git clone https://github.com/ionutvmi/sublime-jsfmt jsfmt

On windows open cmd and:

cd %APPDATA%\"Sublime Text 3"\Packages
git clone https://github.com/ionutvmi/sublime-jsfmt jsfmt

Plugins included

Settings

{
    // autoformat on save
    "autoformat": false,

    // array of extensions for autoformat
    "extensions": ["js", "sublime-settings"],

    // options for jsfmt
    "options": {
        "preset": "jquery",
        "indent": {
            "value": "    "
        },
        // plugins included
        "plugins": [
            // "esformatter-quotes",
            // "esformatter-semicolons",
            // "esformatter-braces",
            // "esformatter-dot-notation"
        ]
    },
    "options-JSON": {
        "plugins": [
            "esformatter-quotes"
        ],
        "quotes": {
            "type": "double"
        }
    },
    "alert-errors": true,
    // path to nodejs
    "node-path": "node",
    // if true it will format the whole file even if you have a selection active
    "ignore-selection": false
}

Commands

Command palette:

  • JSFMT: Format the current file
  • JSFMT: Toggle autoformat
  • JSFMT: Settings - Default
  • JSFMT: Settings - User

Menu:
Preferences -> Package Settings -> Sublime JSFMT

Keyboard shortcut
If you want to trigger the formatting on a keyboard shortcut you will need to: - Go to Preferences -> Key Bindings - User - Insert the configuration to call the format_javascript command

{ "keys": ["ctrl+q"], "command": "format_javascript" },

Formatting rules

You can set global rules via a .jsfmtrc. Be crazy and establish one for all your projects in ~/.jsfmtrc. (like in dotfiles)

Otherwise you're probably pretty levelheaded and will probably provide one in your project root. It'll be read and applied.

Rules you can intuit from these esformatter preset files.

There's a .jsfmtrc-sample in this repo. It's a good start. Rename it and toss it somewhere. Try it out.

Installing plugins

If you want to use a plugin that is not installed by default you will need to follow the next steps:

  1. Go to the packages folder (Preferences -> Browse Packages)
  2. cd into the jsfmt folder.
  3. Install the plugins you need.
  4. Go to your jsfmt settings file and add the name of the plugin in the plugins array.

Compatibility

Should work in both ST2 and ST3.

Contributing

If you find any bugs feel free to report them here
Pull requests are also encouraged.