2015-10-20 61 views
1

我正在制定一個自定義規則ESLint自定義規則檢查源代碼

基本上是:

module.exports = function (context) { 
    var file = context.getSource(); 
    var fileName = context.getFilename(); 
    var lines = file.split(/\n/); 
    lines.forEach(function(line, i){ 
     // [...] validation logic 

     var report = { 
      message: 'Code style error.' 
     }; 

     report.loc = { 
      line: i + 1, 
      col: 1 // I have some logic for this working 
     }; 

     context.report(report); 
    }); 

    return {}; // do I need this? 
}; 

我的代碼可以找到我要找的錯誤,但我有並報ESLint問題。

我得到:

加載時出錯規則「測試規則」:無法讀取的不確定

財產「型」我該如何配置context.report(report);,並應該模塊有一個return因爲我根本不使用AST?

關於我失蹤的任何建議?

回答