robasaurus robasaurus - 11 months ago 106
Less Question

lesshint custom rule get the filename being walked

I'm creating a custom linting rule in lesshint.

I want to access the filename of the file being walked.

Current code:

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

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


The closest I've got is
node.root().source.input.from
which seems to output the index of the file, but not its name.

config
object seems to be a boolean

Answer Source

Lead maintainer of lesshint here.

I've just pushed an update where the full file path will be included on all nodes. You can access it via the source property, like this:

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

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

The value of config will be the value you specified for it in your .lesshintrc file. For example:

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

Will pass that object in config.

Link to the newly released version: https://github.com/lesshint/lesshint/releases/tag/v4.6.2

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download