【问题标题】:custom rule checking source code自定义规则检查源码
【发布时间】:2016-01-18 22:03:25
【问题描述】:

我正在使用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?

对我缺少什么有什么建议吗?

【问题讨论】:

    标签: javascript abstract-syntax-tree eslint grunt-eslint


    【解决方案1】:

    从今天开始,您还必须提供node 密钥。但我知道文档不是这样说的,这就是我在那里打开问题的原因:https://github.com/eslint/eslint/issues/4220

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-25
      • 2011-06-04
      • 1970-01-01
      • 2011-01-11
      • 1970-01-01
      • 2020-02-11
      • 1970-01-01
      • 2017-02-16
      相关资源
      最近更新 更多