jzaefferer / grunt-esformatter Goto Github PK
View Code? Open in Web Editor NEWGrunt wrapper plugin for esformatter - validate or format your JavaScript code
License: MIT License
Grunt wrapper plugin for esformatter - validate or format your JavaScript code
License: MIT License
It would be really nice to have this support. PR incoming...
Hello,
I'm experiencing an issue when I tried skipHashbang: true
in options.
In package.json, I have these in devDependencies:
"grunt-esformatter": "1.0.1",
"esformatter": "0.7.3",
"esformatter-semicolons": "1.1.1",
"esformatter-var-each": "2.1.0",
"esformatter-quotes": "1.0.3",
"esformatter-eol-last": "1.0.0",
"esformatter-dot-notation": "1.3.1",
"esformatter-literal-notation": "1.0.1"
And this is a part of Gruntfile.js:
var step1 = {
src: [
'src/js/*.js'
],
options: {
'plugins': [
'esformatter-semicolons',
'esformatter-var-each'
],
'skipHashbang': true,
'quotes': {
'type': 'single',
'avoidEscape': true
},
'whiteSpace': {
'before': {
'Property': '>=0',
'PropertyName': 1,
'ArrayExpressionClosing': 1,
'ObjectExpressionClosingBrace': 1
},
'after': {
'FunctionReservedWord': 1,
'ArrayExpressionOpening': 1,
'ObjectExpressionOpeningBrace': '>=0'
}
},
'lineBreak': {
'before': {
'ArrayExpressionClosing': '>=0',
'ObjectExpressionClosingBrace': '>=0',
'Property': '>=0'
},
'after': {
'ArrayExpressionOpening': '>=0',
'ArrayExpressionComma': '>=0',
'ObjectExpressionClosingBrace': '>=0',
'ObjectExpressionOpeningBrace': '>=0',
'PropertyValue': '>=0'
}
}
}
};
var step2 = JSON.parse(JSON.stringify(step1));
step2.options.plugins = [
'esformatter-quotes',
'esformatter-eol-last',
'esformatter-dot-notation',
'esformatter-literal-notation'
];
grunt.config.set('esformatter', {
step1: step1,
step2: step2
});
grunt.registerTask('compassFormat', ['esformatter']);
The issue I see while formatting is going on is this: whenever there's a line that has 'null' (in multiple files), for example, at this kind of line:
var foo = null;
error is thrown. One sample error message looks like this:
>> Exception while formatting js/views/slides.js
>> Error: Line 321: Unexpected token ;
>> at createError (/Users/glee/demo_proj/node_modules/grunt-esformatter/node_modules/esformatter/node_modules/rocambole/node_modules/esprima/esprima.js:2392:21)
>> at unexpectedTokenError (/Users/glee/demo_proj/node_modules/grunt-esformatter/node_modules/esformatter/node_modules/rocambole/node_modules/esprima/esprima.js:2467:13)
>> at throwUnexpectedToken (/Users/glee/demo_proj/node_modules/grunt-esformatter/node_modules/esformatter/node_modules/rocambole/node_modules/esprima/esprima.js:2472:15)
>> at parsePrimaryExpression (/Users/glee/demo_proj/node_modules/grunt-esformatter/node_modules/esformatter/node_modules/rocambole/node_modules/esprima/esprima.js:3266:13)
>> at inheritCoverGrammar (/Users/glee/demo_proj/node_modules/grunt-esformatter/node_modules/esformatter/node_modules/rocambole/node_modules/esprima/esprima.js:2648:18)
>> at parseLeftHandSideExpressionAllowCall (/Users/glee/demo_proj/node_modules/grunt-esformatter/node_modules/esformatter/node_modules/rocambole/node_modules/esprima/esprima.js:3373:20)
>> at inheritCoverGrammar (/Users/glee/demo_proj/node_modules/grunt-esformatter/node_modules/esformatter/node_modules/rocambole/node_modules/esprima/esprima.js:2648:18)
>> at parsePostfixExpression (/Users/glee/demo_proj/node_modules/grunt-esformatter/node_modules/esformatter/node_modules/rocambole/node_modules/esprima/esprima.js:3449:16)
>> at parseUnaryExpression (/Users/glee/demo_proj/node_modules/grunt-esformatter/node_modules/esformatter/node_modules/rocambole/node_modules/esprima/esprima.js:3509:20)
>> at inheritCoverGrammar (/Users/glee/demo_proj/node_modules/grunt-esformatter/node_modules/esformatter/node_modules/rocambole/node_modules/esprima/esprima.js:2648:18)
Do you have any idea what caused this error? Please let me know if you want me to provide more info. Thanks.
The esformattter project links to this repo, even though it is currently empty.
At the moment, AFAICS all the configuration options needs to be done in the Gruntfile.js. When using esformatter standalone it allows you to create an additional configuration file and specify that file using the --config
command-line switch.
It would be great if there was an equivalent for --config
in the Grunt task so you do not have to replicate all the rules.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.