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

jsfmt

by ionutvmi ST2/ST3

jsfmt plugin for Sublime Text

Details

  • 1.0.11
  • github.​com
  • github.​com
  • 10 months ago
  • 27 minutes ago
  • 3 years ago

Installs

  • Total 10K
  • Win 5K
  • OS X 4K
  • Linux 1K
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 Oct 6
Windows 7 4 6 10 17 21 9 13 5 5 10 11 14 18 16 5 8 14 20 10 18 15 10 11 13 11 13 7 26 7 9 11 9 14 19 16 3 6 12 16 3 12 5 6 1 3
OS X 1 4 5 8 17 12 12 8 1 2 11 9 8 14 14 3 8 9 12 8 8 10 3 3 6 7 9 5 7 5 1 13 8 4 9 9 4 2 11 8 1 14 4 3 2 4
Linux 0 1 0 1 1 0 1 1 0 0 0 0 2 2 2 2 0 2 2 2 0 0 1 0 2 5 3 0 2 3 0 2 1 1 2 1 0 1 1 1 2 3 0 0 0 1

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.