lesshint 自定义规则获取正在遍历的文件名

lesshint custom rule get the filename being walked

我正在 lesshint 中创建自定义 linting 规则。

我想访问正在遍历的文件的文件名。

当前代码:

module.exports = {
    name: 'customrule',
    nodeTypes: ['decl'],

    lint: function(config, node) {        
        console.log(node.root().source.input.from);        
    }
};

我得到的最接近的是 node.root().source.input.from,它似乎输出文件的索引,但不输出文件名。

config 对象似乎是布尔值

这里是 lesshint 的主要维护者。

我刚刚推送了一个更新,其中完整的文件路径将包含在所有节点上。您可以通过 source 属性 访问它,如下所示:

module.exports = {
    name: 'customrule',
    nodeTypes: ['decl'],

    lint: function(config, node) {        
        console.log(node.source.input.file)     
    }
};

config 的值将是您在 .lesshintrc 文件中为其指定的值。例如:

{
    "customrule": {
        "enabled": true,
        "option": false
    }
}

将在 config 中传递该对象。

Link到新发布的版本:https://github.com/lesshint/lesshint/releases/tag/v4.6.2