-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compare versions correctly (#30) #46
Conversation
Thanks for this. Neither browserslist nor MDN compat data specify the format of their versions fully, so I'm not sure how exactly we should be treating them for comparison. Semver as you've used here will cover a lot of cases I expect. However it won't cover everything, and if the format is actually just dot-separated strings we don't need a library to handle that. Most in the data are just a single integer within a string. The compat data has ranged versions, which are not semver - https://github.com/mdn/browser-compat-data/blob/main/schemas/compat-data-schema.md#ranged-versions The schema simply says it's a string - https://github.com/mdn/browser-compat-data/blob/main/schemas/compat-data.schema.json#L46 |
The version numbers that they give are whatever version numbers are specified by the browser/engine manufacturers. Because their version data is dependent on other organizations, I can't imagine that they'd specify a universal version schema for their data (unless it was purely descriptive and not prescriptive). This means it would be on us to come up with a version comparison method that works with all the data. A simple
The bug still exists even with single integers: in JavaScript,
I presume we can just strip the |
What I said about "single integer within a string" was just an observation. I understand the problem. It does seem to be a dotted string up to 3 deep, going by https://github.com/mdn/browser-compat-data/tree/main/browsers. Why do we need a library is over ~5 lines of code? Split the strings, iterate through until last digit of either, parse the bits, compare as numbers. If we do want to use a library, this current one looks good; the more established semver one is semver-specific and too strict. |
I picked |
There is another edge case with Browserslist’s rule
So even with this fix, ESLint returns parsing error:
|
Temporary workaround until robatwilliams/es-compat#46 is fixed
Temporary workaround until robatwilliams/es-compat#46 is fixed
Temporary workaround until robatwilliams/es-compat#46 is fixed
Temporary workaround until robatwilliams/es-compat#46 is fixed
Temporary workaround until robatwilliams/es-compat#46 is fixed
Temporary workaround until robatwilliams/es-compat#46 is fixed
Temporary workaround until robatwilliams/es-compat#46 is fixed
Temporary workaround until robatwilliams/es-compat#46 is fixed
Temporary workaround until robatwilliams/es-compat#46 is fixed
Temporary workaround until robatwilliams/es-compat#46 is fixed
Closing in favour of #67 |
eslint-plugin-ecmascript-compat
currently compares version number strings with the>=
operator, which only yields expected results if each component (major/minor/patch) of both version numbers is the same number of digits, meaning the plugin doesn't work in many cases. For example, the plugin currently considers9.0.0
to be a higher version number than10.0.0
. This patch adds proper version comparison.