/esformatter-braces

Esformatter plugin for enforcing braces around statements

Primary LanguageJavaScriptMIT LicenseMIT

esformatter plugin for enforcing braces around statements

NPM Version NPM Downloads Build Status

Esformatter-braces is a plugin for esformatter meant for brace enforcement around statements. Recommended by Douglas Crockford in his coding style guide.

Turn this:

if (theSkyIsBlue)
    stareAtItForAWhile();

into:

if (theSkyIsBlue) {
    stareAtItForAWhile();
}

For more information see:

Currently the following node statements are handled: If conditionals, While, Do While, For loops

For any other formatting (such as braces placement, spacing and line wrapping) use esformatter or other plugins.

Goals

  • Add similar options to IDEA's: Do not force and Multiline
  • Possibly do the reverse: remove braces if possible (single line statements)

Installation

$ npm install esformatter-braces --save-dev

Config

Newest esformatter versions autoload plugins from your node_modules See this

Add to your esformatter config file:

{
  "plugins": [
    "esformatter-braces"
  ]
}

Or you can manually register your plugin:

// register plugin
esformatter.register(require('esformatter-braces'));

Usage

var fs = require('fs');
var esformatter = require('esformatter');
//register plugin manually
esformatter.register(require('esformatter-braces'));

var str = fs.readFileSync('someKewlFile.js').toString();
var output = esformatter.format(str);
//-> output will now contain the formatted string

See esformatter for more options and further usage.

License

MIT @Gilad Peleg