How npmjs.com calculates the code quality
Asked Answered
L

2

59

When we publish a package to npm, it will show us some data such as popularity, quality, and maintenance in the search page (The example image is blow). I just wonder how npm calculates the quality? Really appreciate if someone can give some clue.

enter image description here

You can see this if you look on the search page. See the right side of search page: npm search for "react"

Lavonnelaw answered 16/4, 2018 at 21:33 Comment(5)
No, it does not show that. Are you looking at some package's Readme?Kriss
I think you can read it from here npmjs.com/package/package-quality#measuring-qualityInteractive
If we search some packages, we will see those images in the search list.Lavonnelaw
This is flat out, too broad. You are, in the broadest terms, asking us how to write software to calculate code metrics. That is, definitively, off-topic according to the reason: "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow".Bodoni
Hi zero298, I am just asking what kind of criteria the npm is using to calculate the quality.Lavonnelaw
L
84

Edit, january 2020: NPM does not show "Powered by npms.io" anymore. I don't know if this is still accurate.


Original answer

npm shows these graphs in search results, but they do not calculate these values themselves. If you look below the search results, you'll see "Powered by npms.io".

According to this service, they don't inspect the code, but use the following metrics to measure code quality:

  • Has README? Has license? Has .gitignore and friends?
  • Is the version stable (> 1.x.x)? Is it deprecated?
  • Has tests? What's their coverage %? Is the build passing?
  • Has outdated dependencies? Do they have vulnerabilities?
  • Has custom website? Has badges?
  • Are there linters configured?

Source: https://npms.io/about

Lundquist answered 16/4, 2018 at 22:23 Comment(4)
Thank you. It is what I am looking for. I should look at that page more carefully. You have a nice day.Lavonnelaw
When checking npm.io, this code might be of help to understand npm's package quality evaluation: github.com/npms-io/npms-analyzer/blob/master/lib/scoring/…Rugby
Currently, the numbers are different (which is a pity). My quality score of npms.io/search?q=%40mliebelt%2Fpgn-parser is 83 (quality) and 100 (maintenance), but on npm (npmjs.com/search?q=pgn-parser), the score is 53 and 33. I think the values are old, and not computed any more at all.Betthezel
See the discussion here github.com/npm/feedback/discussions/66 to understand the current state. So npms.io is not used any more, and the metrics are not open / not clearly defined.Betthezel
A
3

Quality includes considerations such as the presence of a README file, stability, tests, up-to-date dependencies, custom website, and code complexity.

https://docs.npmjs.com/searching-for-and-choosing-packages-to-download

Anesthesia answered 16/2, 2022 at 21:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.