eslint-plugin-compat icon indicating copy to clipboard operation
eslint-plugin-compat copied to clipboard

False positives reported violation when mdn-browser-compat-data uses ranged version

Open tbroyer opened this issue 3 years ago • 2 comments

I recently updated all my dependencies after a few months, and now have a report:

  62:34  error  location.hostname() is not supported in Opera 71  compat/compat

Looking around in related projects, I found that mdn-browser-compat-data have recently updated their data for location.hostname from true to a ranged version, specifically "version_added": "≤12.1", and it looks like eslint-plugin-compat doesn't support that format (parsing strings as a semver, which itself doesn't deal with the character).

tbroyer avatar Jan 07 '21 11:01 tbroyer

Oh, it looks like the issue rather is that ast-metadata-inferer's compat.json actually contains "opera":{"version_added":false}, and this is because version 0.4.0 is built from mdn-browser-compat-data 1.0.20 which contained broken/erroneous data (fixed by https://github.com/mdn/browser-compat-data/pull/6286, released in 1.0.26).

Ideally, both projects (ast-metadata-inferer and eslint-plugin-compat) should upgrade to @mdb/browser-compat-data which is now at version 3.0.1.

Fwiw, adding

  it("should support ranged versions", () => {
    const node = { protoChainId: "Accelerometer" };
    const config = determineTargetsFromConfig(".", "edge 18, edge 87");
    const targets = parseBrowsersListVersion(config);
    const result = getUnsupportedTargets(node, targets);
    expect(result).toEqual(["Edge 18"]);
  });

to test/mdn-provider.spec.ts passes, so it looks like ranged versions are actually correctly supported.

On the other hand, as reported initially:

  it("should support ranged versions", () => {
    const node = { protoChainId: "location.hostname" };
    const config = determineTargetsFromConfig(".", "opera 71");
    const targets = parseBrowsersListVersion(config);
    const result = getUnsupportedTargets(node, targets);
    expect(result).toEqual([]);
  });

fails:

$ yarn spec
yarn run v1.22.10
$ jest --testPathIgnorePatterns test/e2e-repo.spec.ts /benchmarks-tmp
 PASS  test/helpers.spec.ts
 PASS  test/caniuse-provider.spec.ts
 FAIL  test/mdn-provider.spec.ts
  ● MdnProvider › should support ranged versions

    expect(received).toEqual(expected) // deep equality

    - Expected  - 1
    + Received  + 3

    - Array []
    + Array [
    +   "Opera 71",
    + ]

      18 |     const targets = parseBrowsersListVersion(config);
      19 |     const result = getUnsupportedTargets(node, targets);
    > 20 |     expect(result).toEqual([]);
         |                    ^
      21 |   });
      22 | });
      23 | 

      at Object.<anonymous> (test/mdn-provider.spec.ts:20:20)
      at processTicksAndRejections (node:internal/process/task_queues:93:5)

 PASS  test/e2e.spec.ts

Test Suites: 1 failed, 3 passed, 4 total
Tests:       1 failed, 78 passed, 79 total
Snapshots:   8 passed, 8 total
Time:        4.231 s
Ran all test suites.

tbroyer avatar Jan 07 '21 15:01 tbroyer

Having a similar issue with 142:24 error document.body() is not supported in Firefox 55 compat/compat "eslint-plugin-compat": "~4.0.2"

wasd171 avatar Dec 29 '22 19:12 wasd171