Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

294
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda