i'm using jshint
lint es6
code on ionic framework project. need config listing in order use es6. seems when run linter, using small script, doesn't read configuration file .jshintrc
. got bunch of these errors:
'arrow function syntax (=>)' available in es6 (use esnext option). -> $ionicplatform.ready(() => {
my .jshintrc file:
{ "asi": false, "boss": true, "curly": true, "eqeqeq": false, "eqnull": true, "esnext": true, "expr": true, "forin": true, "immed": true, "laxbreak": true, "newcap": false, "noarg": true, "node": true, "nonew": true, "plusplus": true, "quotmark": "single", "strict": false, "undef": true, "unused": true }
i'm running jshint script contained in hooks/before_prepare
#!/usr/bin/env node var fs = require('fs'); var path = require('path'); var jshint = require('jshint').jshint; var async = require('async'); var folderstoprocess = [ 'js6/', 'js6/controllers', 'js6/controllers/schedule', ]; folderstoprocess.foreach(function(folder) { processfiles("www/" + folder); }); function processfiles(dir, callback) { var errorcount = 0; fs.readdir(dir, function(err, list) { if (err) { console.log('processfiles err: ' + err); return; } async.eachseries(list, function(file, innercallback) { file = dir + '/' + file; fs.stat(file, function(err, stat) { if(!stat.isdirectory()) { if(path.extname(file) === ".js") { lintfile(file, function(haserror) { if(haserror) { errorcount++; } innercallback(); }); } else { innercallback(); } } else { innercallback(); } }); }, function(error) { if(errorcount > 0) { process.exit(1); } }); }); } function lintfile(file, callback) { console.log("linting " + file); fs.readfile(file, function(err, data) { if(err) { console.log('error: ' + err); return; } if(jshint(data.tostring())) { console.log('file ' + file + ' has no errors.'); console.log('-----------------------------------------'); callback(false); } else { console.log('errors in file ' + file); var out = jshint.data(), errors = out.errors; for(var j = 0; j < errors.length; j++) { console.log(errors[j].line + ':' + errors[j].character + ' -> ' + errors[j].reason + ' -> ' + errors[j].evidence); } console.log('-----------------------------------------'); callback(true); } }); }
the file structure typical cordova project structure, have www folder js6 folder inside www --> js6 --> controllers --> schedule
change
if(jshint(data.tostring())) {
to
if(jshint(data.tostring(), {esnext:true}})) {
or can read .jshintrc file's content first, , set jshint config in place. see https://github.com/jetma/cordova-hooks/blob/master/before_prepare/02_jshint.js/.
Comments
Post a Comment