{"name":"esformatter-jsx","version":"1.0.8","description":"esformatter plugin: format javascript files that contain React JSX blocks","repository":{"type":"git","url":"https://github.com/royriojas/esformatter-jsx"},"license":"MIT","author":{"name":"Roy Riojas","url":"http://royriojas.com"},"main":"index.js","files":["index.js"],"engines":{"node":">=0.10.0"},"scripts":{"test":"mocha -R spec test","watch":"mocha -R spec --watch test"},"keywords":["esformatter-plugin","esformatter","jsx","react jsx","AST","esprima-fb","fresh-falafel","codestyle","react jsx"],"peerDependencies":{},"dependencies":{"esprima-fb":"^13001.1.0-dev-harmony-fb","fresh-falafel":"^0.2.6","js-beautify":"^1.5.4","lodash.defaults":"^3.0.0"},"devDependencies":{"chai":"*","esformatter":"^0.5.0","mocha":"*","read-json-sync":"^1.1.0"},"gitHead":"f10a4298808cdea85d3d4aaeaef643ca53c2f710","bugs":{"url":"https://github.com/royriojas/esformatter-jsx/issues"},"homepage":"https://github.com/royriojas/esformatter-jsx","_id":"esformatter-jsx@1.0.8","_shasum":"ed01207e094b034227558dd331cdc89e95d1bdc0","_from":".","_npmVersion":"2.6.0","_nodeVersion":"0.12.0","_npmUser":{"name":"royriojas","email":"royriojas@gmail.com"},"maintainers":[{"name":"royriojas","email":"royriojas@gmail.com"}],"dist":{"shasum":"ed01207e094b034227558dd331cdc89e95d1bdc0","tarball":"http://registry-npm.ywwl.com/esformatter-jsx/download/esformatter-jsx-1.0.8.tgz","integrity":"sha512-ciE/GUdywQk3hxeMPnysFCPISBUyMjti4IboEV7cf4UueD4LVpMnNH5ab+EX3c9YXSUYhhKU0o1i4Dmx03kpKg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAlw1Bm9whz0XuyKm8suuMmZjOows+YJmfQWtWnF4O2EAiAGEjzuPGs0E9I+nxdtU1O4vb7lozEIiSE+9mlC25n9GQ=="}],"size":5457,"noattachment":false,"key":"/esformatter-jsx/-/esformatter-jsx-1.0.8.tgz"},"directories":{},"readme":"# [esformatter](https://github.com/millermedeiros/esformatter)-jsx\n> esformatter plugin: format javascript files that contain React JSX blocks\n\n[![NPM Version](http://img.shields.io/npm/v/esformatter-jsx.svg?style=flat)](https://npmjs.org/package/esformatter-jsx)\n[![Build Status](http://img.shields.io/travis/royriojas/esformatter-jsx.svg?style=flat)](https://travis-ci.org/royriojas/esformatter-jsx)\n\n## Demo\n\nLive demo: [esformatter-jsx](http://royriojas.com/resources/esformatter-jsx/)\n\n### Usage with [JSFMT](https://github.com/ionutvmi/sublime-jsfmt)\n\ncheck this [guide](https://github.com/royriojas/esformatter-jsx/wiki/Usage-with-jsfmt)\n\n### best configuration\n\nIf you're running into troubles with the formatting applied to your files I found this configuration to work the best:\n\n```javascript\n{\n  \"jsx\": {\n    \"formatJSX\": true, //Duh! that's the default\n    \"attrsOnSameLineAsTag\": false, // move each attribute to its own line\n    \"maxAttrsOnTag\": 3, // if lower or equal than 3 attributes, they will be kept on a single line\n    \"firstAttributeOnSameLine\": true, // keep the first attribute in the same line as the tag\n    \"formatJSXExpressions\": true, // default true, if false jsxExpressions won't be recursively formatted\n    \"JSXExpressionsSingleLine\": true, // default true, if false the JSXExpressions might span several lines\n    \"alignWithFirstAttribute\": false, // do not align attributes with the first tag\n    \"spaceInJSXExpressionContainers\": \" \", // default to one space. Make it empty if you don't like spaces between JSXExpressionContainers\n    \"removeSpaceBeforeClosingJSX\": false, // default false. if true <React.Something /> => <React.Something/>\n    \"closingTagOnNewLine\": false, // default false. if true attributes on multiple lines will close the tag on a new line\n    \"JSXAttributeQuotes\": \"\", // possible values \"single\" or \"double\". Leave it as empty string if you don't want to modify the attributes' quotes\n    \"htmlOptions\": {\n      // put here the options for js-beautify.html\n    }\n  }\n}\n```\n\n## Overview\n\n**Esformatter-jsx** is a plugin for [esformatter](https://github.com/millermedeiros/esformatter) meant to allow the\ncode formatting of jsx files or js files with React code blocks, using [js-beautify](https://www.npmjs.com/package/js-beautify) to\nbeautify the \"html like\" syntax of the react components. **Use at your own risk**. I have tested this against complex JSX structures and seems to be workfing fine, but bugs might appear, so don't blame me :).\n\nIt works for my main use case and I hope it works for you too.\n\nThis plugin is based on [esformatter-jsx-ignore](https://github.com/royriojas/esformatter-jsx-ignore)\n\nIf you want a bit of history about what this plugin was develop, check:\n- https://github.com/millermedeiros/esformatter/issues/242\n- https://github.com/facebook/esprima/issues/74\n\nSo this plugin will turn this:\n```js\nvar React = require('react');\n\nvar Hello = React.createClass({\nrender: function () {\nreturn (<div\n\nclassName=\"hello-div\">{this.props.message}</div>)\n;\n}\n});\n\nReact.render(<Hello\nmessage=\"world\"/>,      document.body);\n```\n\ninto:\n```js\nvar React = require('react');\n\nvar Hello = React.createClass({\n  render: function() {\n    return (\n    <div className=\"hello-div\">\n      {this.props.message}\n    </div>\n    );\n  }\n});\n\nReact.render(<Hello message=\"world\"/>, document.body);\n```\n\n## Installation\n\n```sh\n$ npm install esformatter-jsx --save-dev\n```\n\n## Config\n\nNewest esformatter versions autoload plugins from your `node_modules` [See this](https://github.com/millermedeiros/esformatter#plugins)\n\nAdd to your esformatter config file:\n\nIn order for this to work, this plugin should be the first one! (I Know too picky, but who isn't).\n\n```javascript\n{\n  \"plugins\": [\n    \"esformatter-jsx\"\n  ],\n  // this is the section this plugin will use to store the settings for the jsx formatting\n  \"jsx\": {\n    // whether to recursively format jsx expressions with esformatter\n    // set this to false if you don't want JSXExpressions to be formatted recursively, like when using problematic plugins\n    \"formatJSXExpressions\": true,\n    // By default ObjectExpression and ArrayExpression in JSXExpressions are inlined,\n    // if false, the Expression might expand several lines\n    \"JSXExpressionsSingleLine\": true,\n    // by default is true if set to false it works the same as esformatter-jsx-ignore\n    \"formatJSX\": true,\n    // keep the node attributes on the same line as the open tag. Default is true.\n    // Setting this to false will put each one of the attributes on a single line\n    \"attrsOnSameLineAsTag\": true,\n     // how many attributes should the node have before having to put each\n     // attribute in a new line. Default 1\n    \"maxAttrsOnTag\": 1,\n    // if the attributes are going to be put each one on its own line, then keep the first\n    // on the same line as the open tag\n    \"firstAttributeOnSameLine\": false,\n    // default to one space. Make it empty if you don't like spaces between JSXExpressionContainers\n    \"spaceInJSXExpressionContainers\": \" \",\n    // align the attributes with the first attribute (if the first attribute was kept on the same line as on the open tag)\n    \"alignWithFirstAttribute\": true,\n    \"htmlOptions\": { // same as the ones passed to js-beautifier.html\n      \"brace_style\": \"collapse\",\n      \"indent_char\": \" \",\n      \"indent_size\": 2,\n      \"max_preserve_newlines\": 2,\n      \"preserve_newlines\": true\n      //wrap_line_length: 250\n    }\n  }\n}\n```\n\nThe `htmlOptions` are passed directly to [js-beautify](https://www.npmjs.com/package/js-beautify), please check its\ndocumentation for all the possible options.\n\nOr you can manually register your plugin:\n\n```js\n// register plugin\nesformatter.register(require('esformatter-jsx'));\n```\n\n## Usage\n\n```js\nvar fs = require('fs');\nvar esformatter = require('esformatter');\n//register plugin manually\nesformatter.register(require('esformatter-jsx'));\n\nvar str = fs.readFileSync('someKewlFile.js').toString();\nvar output = esformatter.format(str);\n//-> output will now contain the formatted code\n```\n\nSee [esformatter](https://github.com/millermedeiros/esformatter) for more options and further usage info.\n\n## License\n\n[MIT](License)\n","publish_time":1425934017191,"_cnpm_publish_time":1425934017191,"dist-tags":{"latest":"8.0.1"}}