browserslist icon indicating copy to clipboard operation
browserslist copied to clipboard

Add `browserslist.lint()`

Open ai opened this issue 2 years ago • 10 comments

Add a method to find errors in current Browserslist config.

Possible checks:

  1. missed-not-dead: on last N versions without not dead
  2. limited-browsers: on queries only with browser names (and < 7 browser names)
  3. country-was-ignored: on significant (≥20%) drop of coverage in some country (we can use all countries or only countries with ≥1M population).

ai avatar Feb 18 '22 12:02 ai

@ai

on significant (≥20%) drop of coverage in some country (we can use all countries or only countries with ≥1M population).

As I understood, if coverage for country is <80% then issue should be reported. But then "defaults" query will not pass this check (for countries with ≥1M population)

$ browserslist --coverage=AM "defaults"                  
These browsers account for 59.15% of all users in the AM

$ browserslist --coverage=MA "defaults"
These browsers account for 58.51% of all users in the MA

$ browserslist --coverage=RU "defaults"
These browsers account for 72.13% of all users in the RU

$ browserslist --coverage=SG "defaults"
These browsers account for 61.77% of all users in the SG

Is this ok?

dangreen avatar Mar 03 '22 13:03 dangreen

I think linter can be implemented in a separated pacakge, as https://github.com/browserslist/browserslist/issues/549#issuecomment-1044474071 said.

g-plane avatar Mar 05 '22 04:03 g-plane

I think linter can be implemented in a separated pacakge, as https://github.com/browserslist/browserslist/issues/549#issuecomment-1044474071 said.

I can move it by my own

As I understood, if coverage for country is <80% then issue should be reported. But then "defaults" query will not pass this check (for countries with ≥1M population)

Wow! It is a shame for our defaults.

But let add warning first and then we will think how to improve defaults (as part of another task).

ai avatar Mar 05 '22 04:03 ai

@ai it looks weird

$ browserslist --coverage=RU "last 100 versions"
These browsers account for 83.4% of all users in the RU

dangreen avatar Mar 05 '22 17:03 dangreen

Agree. Can I ask you to investigate? Maybe we have an error in coverage calculation?

ai avatar Mar 05 '22 17:03 ai

@ai 👌

dangreen avatar Mar 05 '22 17:03 dangreen

@ai In caniuse country data there is "total" value, it can be not 100%

https://github.com/Fyrd/caniuse/blob/main/region-usage-json/RU.json

"total":81.56795

my suggestion is to interpret this value as 100% and recalculate coverage relative to it

var total = 0

for (var j in data) {
  total += data[j] || 0
}

var tx = 100 / total

return browsers.reduce(function (all, i) {
  var usage = data[i] * tx
  if (usage === undefined) {
    usage = data[i.replace(/ \S+$/, ' 0')] * tx
  }
  return all + (usage || 0)
}, 0)

then coverage for "defaults" is

$ browserslist --coverage=AM "defaults"                  
These browsers account for 59.33% of all users in the AM

$ browserslist --coverage=MA "defaults"
These browsers account for 52.39% of all users in the MA

$ browserslist --coverage=RU "defaults"
These browsers account for 88.36% of all users in the RU

$ browserslist --coverage=SG "defaults"
These browsers account for 64.85% of all users in the SG

Example with "last 100 versions"

Before:

$ browserslist --coverage=AM "last 100 versions"                  
These browsers account for 97.63% of all users in the AM

$ browserslist --coverage=MA "last 100 versions"
These browsers account for 95.88% of all users in the MA

$ browserslist --coverage=RU "last 100 versions"
These browsers account for 81.5% of all users in the RU

$ browserslist --coverage=SG "last 100 versions"
These browsers account for 94.91% of all users in the SG

After:

$ browserslist --coverage=AM "last 100 versions"                  
These browsers account for 99.96% of all users in the AM

$ browserslist --coverage=MA "last 100 versions"
These browsers account for 99.98% of all users in the MA

$ browserslist --coverage=RU "last 100 versions"
These browsers account for 99.92% of all users in the RU

$ browserslist --coverage=SG "last 100 versions"
These browsers account for 99.93% of all users in the SG

dangreen avatar Mar 07 '22 08:03 dangreen

Seems like total ≠ 100% because of browsers which are not on Can I Use (like Yandex browser).

Let’s keep old logic for --coverage and use / total only in linter.

ai avatar Mar 07 '22 09:03 ai

@ai ok. But it solve problem only for RU.

Weak places in other regions:

AM 'firefox 52': 37.23163, - popular but not in "defaults"

MA 'ios_saf 6.0-6.1': 14.55397, - popular but not in "defaults"

SG 'android 4.4.3-4.4.4': 21.76044, - popular but not in "defaults"

dangreen avatar Mar 07 '22 09:03 dangreen

Yes, we will think about solving this problem later.

BTW, it will be nice to suggest in warning what browser to add to fix coverage in the region.

ai avatar Mar 07 '22 09:03 ai

It seems like this hasn't been updated since browserslist-lint was created. Can this be updated or closed?

nickmccurdy avatar Jul 22 '23 09:07 nickmccurdy