question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using custom linters via the CLI

See original GitHub issue

The README indicates custom linters can be defined via the CLI via the --linters option, however, from my experience adding custom linters to the lesshintrc file they must also be enabled. Can you provide an example of custom linter usage via the CLI as it is unclear how to both define and enable the customer linter via the CLI.

Thanks.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
JoshuaKGoldbergcommented, Jan 25, 2017

Hi, yes! It “should”* be a relatively simple process. Something like following should probably end up in the docs in some form…

First, create a JavaScript file somewhere that looks like one of the linters from lesshint’s lib/linters directory. important_rule.js is a pretty simple starting point.

As a custom example, here’s a rule that logs on every declaration:

// verbose_rule.js
'use strict';

console.log('Loaded verbose_rule.js.');

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

    lint: function verboseLinter(config, node) {
        console.log('Found node setting', node.prop, 'to', node.value);
    }
};

Given the following file named test.less

.foo {
    color: bar;
}

…and a .lesshintrc file that enables the rule…

{
    "verbose": true
}

…if you run the following command* (assuming you’ve run npm i -g lesshint)…

lesshint test.less --linters C:/Code/lesshint-testing/verbose_rule.js

…you should get the following output:

Loaded verbose_rule.js.
Found node setting color to bar

You can then extend the linter to return an array of failures.

*After testing v2.4.0 today, it looks like the require logic requires relative to the lesshint install, not the script calling it. I’ll fix that ASAP. You can get around it by using the absolute paths (C:/Code/my-lesshint-stuff/linter.js instead of ./linter.js). As per this SO answer you can debug where Node is looking for objects via require. export NODE_DEBUG=module on *nix; set NODE_DEBUG=module on Windows.

0reactions
jwilssoncommented, Feb 11, 2017

Closing this since it’s better documented now.

@kloots Please give us a shout if you disagree!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Command Line Interface
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Custom Linters
Custom Linters ; lsp_json, Produces diagnostics as Language Server Protocol JSON. ; pass_fail, Writes a single file-level diagnostic to stdout . ; regex,...
Read more >
New linters | golangci-lint
Some people and organizations may choose to have custom-made linters run as a part of golangci-lint . Typically, these linters can't be open-sourced...
Read more >
Using go/analysis to write a custom linter
We're going to write a custom linter using the new go/analysis framework which dramatically speeds up creating new linters.
Read more >
Using openapi-cli : custom rules
If you're planning to lint OpenAPI description documents (you should!), always check whether a linter supports adding custom rules.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found