https://github.com/pgilad/esformatter-braces
Esformatter plugin for enforcing braces around statements
https://github.com/pgilad/esformatter-braces
Last synced: about 1 year ago
JSON representation
Esformatter plugin for enforcing braces around statements
- Host: GitHub
- URL: https://github.com/pgilad/esformatter-braces
- Owner: pgilad
- License: mit
- Created: 2014-07-02T17:36:32.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2015-05-28T13:59:51.000Z (about 11 years ago)
- Last Synced: 2025-05-08T22:16:38.364Z (about 1 year ago)
- Language: JavaScript
- Size: 265 KB
- Stars: 9
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [esformatter](https://github.com/millermedeiros/esformatter)-braces
> esformatter plugin for enforcing braces around statements
[](https://npmjs.org/package/esformatter-braces)
[](https://npmjs.org/package/esformatter-braces)
[](https://travis-ci.org/pgilad/esformatter-braces)
**Esformatter-braces** is a plugin for [esformatter](https://github.com/millermedeiros/esformatter) meant for brace enforcement around statements. Recommended by Douglas Crockford in his [coding style guide](http://javascript.crockford.com/code.html).
Turn this:
```js
if (theSkyIsBlue)
stareAtItForAWhile();
```
into:
```js
if (theSkyIsBlue) {
stareAtItForAWhile();
}
```
For more information see:
- [Jetbrain's Idea](http://www.jetbrains.com/idea/webhelp10.5/wrapping-and-braces.html) and specifically the **Force brace always** section.
- The [jsHint](https://github.com/jshint/jshint/) option - [curly](http://www.jshint.com/docs/options/#curly)
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
```sh
$ npm install esformatter-braces --save-dev
```
## Config
Newest esformatter versions autoload plugins from your `node_modules` [See this](https://github.com/millermedeiros/esformatter#plugins)
Add to your esformatter config file:
```json
{
"plugins": [
"esformatter-braces"
]
}
```
Or you can manually register your plugin:
```js
// register plugin
esformatter.register(require('esformatter-braces'));
```
## Usage
```js
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](https://github.com/millermedeiros/esformatter) for more options and further usage.
## License
MIT @[Gilad Peleg](http://giladpeleg.com)