Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

286
Views
How to use jsHint to extract code metrics in the CLI report?

I am trying to get code metrics from jshint like on jshint.com:

Metrics

There is only one function in this file.

It takes no arguments.

This function contains 2 statements.

Cyclomatic complexity number for this function is 1.

The cli execution only shows linting outputs, like missing semicolon etc., But does not output any of these metrics. However, the above link seems to do that just fine for any pasted code.

How can I get such a code report across all JS files/modules? Technically this information should be available but I'm unable to have any output similar to the above via the CLI. Rummaging through the source code it seems entirely possible but I can't figure out if there's an easier way than hacking at the source code.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

After rummaging through the source code and checking out the online docs, it seems you can write your own reporter as shown here. However, it fails to mention that you can also add additional arguments to get additional information in callback as seen in the code in its cli.js:

Combining the two here's how you can write your custom reporter function that prints the metrics to the console. It's a crude example modified from one in the repo in case someone stumbles on this:

module.exports = {
    reporter: function (res,data,options) {
        //console.dir(data,{depth:5}) //To see entire object
        data.forEach(d => {
            d.functions.forEach(f => {
                console.log(d.file, f.name, f.param, f.metrics);
            });
        });
    }
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!