Format JavaScript files.
This plugin requires Grunt ~0.4.0
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-esformatter --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-esformatter');
Run this task with the grunt esformatter
command.
Task targets, files and options may be specified according to the grunt Configuring tasks guide.
Files are formatted with esformatter.
Type: String
Default: undefined
Pick one of the presets that esformatter bundles. If you don't specify the option, the default preset is used.
Type: Boolean
Default: false
If you're formatting a script that contains a first line starting with "#!": for example when you're writing scripts that are executable by themselves, set this option to make the task remove this line before formatting it, then put it back after formatting. Here's an example of such a script:
###!/usr/bin/env node
scriptCodeHere();
By default, if you format a file with esformatter that includes this line, the parser (esprima) will throw an exception, pointing out that first line as an "illegal token". Which makes sense in the context of browser scripts, where the parser would throw the same error.
Type: Object
Default: undefined
These are the top-level configuration properties for esformatter. You can specify any of the nested properties to overwrite settings from the chosen preset.
Once there is documentation available for these, a link will be added. Until then you have to look at the esformatter source code.
esformatter: {
src: 'src/**/*.js'
}
esformatter: {
options: {
preset: 'jquery'
},
src: ['src/parser.js', 'src/formatter.js']
}
esformatter: {
four_space_indent: {
options: {
indent: {
value: ' '
}
},
src: 'file1.js'
},
jquery_two_space_indent: {
options: {
preset: 'jquery'
indent: {
value: ' '
}
},
src: 'vendor/*.js'
}
}
Task submitted by Jörn Zaefferer
This file was generated on Sat Dec 07 2013 18:14:26.