2015-05-08 50 views
3

我正在使用JSHint在Ionic框架项目上粘贴我的ES6代码。我需要配置列表才能使用ES6。似乎当我运行linter时,通过使用一个小脚本,它不会读取配置文件.jshintrc。我有一大堆这样的错误:.jshintrc文件未被读取

'arrow function syntax (=>)' is only available in ES6 (use esnext option). ->  $ionicPlatform.ready(() => { 

我.jshintrc文件:

{ 
    "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 
} 

我正在JSHint包含在钩/ 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); 
     } 
    }); 
} 

文件结构这个脚本是一个典型的科尔多瓦项目结构,我有一个www文件夹,内有www - > js6 - > controllers - > schedule

+0

什么是您的文件结构?没有其他jshintrc文件更接近有问题的文件,或者可能有一些本地覆盖?你如何运行Jshint? – doldt

+0

你的问题涉及'.jshint'。你的意思是'.jshintrc'? –

+0

你有没有想过这个?有同样的问题。 –

回答