esformatter-shebang-ignore

esformatter plugin: ignore jsx blocks so the rest of the javascript code could be formatted

Usage no npm install needed!

<script type="module">
  import esformatterShebangIgnore from 'https://cdn.skypack.dev/esformatter-shebang-ignore';
</script>

README

esformatter-shebang-ignore

esformatter plugin: ignore shebang line so the rest of the javascript code could be formatted without parsing errors

NPM Version Build Status

Esformatter-shebang-ignore is a plugin for esformatter meant to allow the code formatting of files that contain a shebang line. This plugin basically will make esformatter to ignore the offending shebang line and let esformatter apply the magic on the rest of the file.

So this plugin will turn this:


#!/usr/bin/env node

var fs = require(         'fs' );
var utils = require    (    './lib/util' );
var path = require   ( 'path');

into:

#!/usr/bin/env node

var fs = require( 'fs' );
var utils = require( './lib/util' );
var path = require( 'path' );

Installation

$ npm install esformatter-shebang-ignore --save-dev

Config

Newest esformatter versions autoload plugins from your node_modules See this

Add to your esformatter config file:

In order for this to work, this plugin should be the first one! (I Know too picky, but who isn't).

{
  "plugins": [
    "esformatter-shebang-ignore"
  ]
}

Note: The previous syntax won't work because of this issue. But registering it manually will work like a charm!

Or you can manually register your plugin:

// register plugin
esformatter.register(require('esformatter-shebang-ignore'));

Usage

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

var str = fs.readFileSync('someKewlFile.js').toString();
var output = esformatter.format(str);
//-> output will now contain the formatted code, allowing to format files with shebang lines

See esformatter for more options and further usage.

License

MIT @Roy Riojas