Skip to content

[DRAFT] - Esformatter plugin to enforcing one var statement per function scope

License

Notifications You must be signed in to change notification settings

brix/esformatter-onevar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NO PRODUCTION PLUGIN: IT'S STILL UNDER DEVELOPMENT

esformatter plugin for enforcing one var statement per function scope

Esformatter-onevar is a plugin for esformatter meant for onevar enforcement in function scope. Recommended by Douglas Crockford in his coding style guide.

Turn this:

var foo = 'foo',
    bar = 'bar';

var hello = true,
    world = false;
    
for (var i = 0, l = 10; i < l; i++) {
	var chain = chain + ' ' + i;
}

into:

var foo = 'foo',
    bar = 'bar',
    hello,
    world,
    i,
    l,
    chain;

hello = true;
world = false;
    
for (i = 0, l = 10; i < l; i++) {
	chain = chain + ' ' + i;
}

For more information see:

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

Installation

$ npm install esformatter-onevar --save-dev

Config

Newest esformatter versions autoload plugins from your node_modules See this

Add to your esformatter config file:

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

Or you can manually register your plugin:

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

Usage

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

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 ©2014 Evan Vosberg

About

[DRAFT] - Esformatter plugin to enforcing one var statement per function scope

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published