Skip to content
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

Remove nonreal values from the schema #24174

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
10 changes: 0 additions & 10 deletions lint/linter/test-versions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ describe('test-versions', () => {
};
});

it('should log error when a required browser is not defined', () => {
support.chrome = undefined;
test.check(logger, {
data: { support },
path: { category: 'api' },
});
assert.equal(logger.messages.length, 1);
assert.ok(logger.messages[0].message.includes('must be defined'));
});

it('should log error when a browser is set to mirror but does not have an upstream browser', () => {
support.chrome = 'mirror';
test.check(logger, {
Expand Down
38 changes: 1 addition & 37 deletions lint/linter/test-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,6 @@ const browserTips: Record<string, string> = {
'Blink editions of Opera Android and Opera desktop were the Chrome version number minus 13, up until Opera Android 43 when they began skipping Chrome versions. Please double-check browsers/opera_android.json to make sure you are using the correct versions.',
};

const realValuesTargetBrowsers = [
'chrome',
'chrome_android',
'edge',
'firefox',
'firefox_android',
'opera',
'opera_android',
'safari',
'safari_ios',
'samsunginternet_android',
'webview_android',
];

const realValuesRequired: Record<string, string[]> = {
api: realValuesTargetBrowsers,
css: realValuesTargetBrowsers,
html: realValuesTargetBrowsers,
http: realValuesTargetBrowsers,
svg: realValuesTargetBrowsers,
javascript: [...realValuesTargetBrowsers, 'nodejs', 'deno'],
mathml: realValuesTargetBrowsers,
webassembly: realValuesTargetBrowsers,
webdriver: realValuesTargetBrowsers,
webextensions: [],
};

/**
* Test to see if the browser allows for the specified version
* @param browser The browser to check
Expand All @@ -70,11 +43,6 @@ const isValidVersion = (
return !!browsers[browser].preview_name;
}
return Object.hasOwn(browsers[browser].releases, version.replace('≤', ''));
} else if (
realValuesRequired[category].includes(browser) &&
version !== false
) {
return false;
}
return true;
};
Expand Down Expand Up @@ -140,10 +108,6 @@ const checkVersions = (
supportData[browser];

if (!supportStatement) {
if (realValuesRequired[category].includes(browser)) {
logger.error(chalk`{red {bold ${browser}} must be defined}`);
}

continue;
}

Expand All @@ -170,7 +134,7 @@ const checkVersions = (
logger.error(
chalk`{bold ${property}: "${version}"} is {bold NOT} a valid version number for {bold ${browser}}\n Valid {bold ${browser}} versions are: ${Object.keys(
browsers[browser].releases,
).join(', ')}`,
).join(', ')}, false`,
{ tip: browserTips[browser] },
);
}
Expand Down
50 changes: 7 additions & 43 deletions schemas/compat-data-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Here is an example of a `__compat` statement, with all of the properties and the
// Supported since Chrome 57 on
"version_added": "57",
},
"chrome_android": "mirror", // Mirrors from Chrome Desktop, so "57"
"chrome_android": "mirror", // Mirrors from the upstream browser -- in this case, it is Chrome Desktop, so the data becomes "57"
"edge": {
// Supported since Edge 12, with a note about a difference in behavior
"version_added": "12",
Expand All @@ -112,8 +112,8 @@ Here is an example of a `__compat` statement, with all of the properties and the
"version_removed": "80",
},
"firefox_android": {
// Supported in Firefox Android, we just don't know what version it was added in
"version_added": true,
// Support is known to be in at least Firefox Android 50, but it could have been added earlier
"version_added": "≤50",
},
"ie": {
// Supported since IE 10, but has a caveat that impacts compatibility
Expand All @@ -126,10 +126,7 @@ Here is an example of a `__compat` statement, with all of the properties and the
// Not supported at all in Opera
"version_added": false,
},
"opera_android": {
// We don't know if Opera Android supports this or not
"version_added": null,
},
"opera_android": "mirror",
"safari": [
// A support statement can be an array of multiple statements to better describe the compatibility story
{
Expand All @@ -148,6 +145,7 @@ Here is an example of a `__compat` statement, with all of the properties and the
"safari_ios": "mirror",
"samsunginternet_android": "mirror",
"webview_android": "mirror",
// If a browser is not defined, it means we don't have support information for that browser (or for web extensions, the browser has no support at all)
},
"status": {
// Standards track, deprecation and experimental status
Expand Down Expand Up @@ -295,14 +293,6 @@ This is the only mandatory property and it contains a string with the version nu
}
```

- Supported, but version unknown:

```json
{
"version_added": true
}
```

- No support:

```json
Expand All @@ -311,25 +301,10 @@ This is the only mandatory property and it contains a string with the version nu
}
```

- Support unknown (default value, if browser omitted):

```json
{
"version_added": null
}
```

Note: many data categories no longer allow for `version_added` to be set to `true` or `null`, as we are working to [improve the quality of the compatibility data](https://github.com/mdn/browser-compat-data/issues/3555).

#### `version_removed`

Contains a string with the version number the sub-feature was removed in. It may also be `true`, meaning that it is unknown in which version support was removed. If the feature has not been removed from the browser, this property is omitted, rather than being set to `false`.

Default values:

- If `version_added` is set to `true`, `false`, or a string, `version_removed` defaults to `false`.
- If `version_added` is set to `null`, the default value of `version_removed` is also `null`.

Examples:

- Removed in version 10 (added in 4 and supported up until 9):
Expand All @@ -341,17 +316,6 @@ Examples:
}
```

- Removed in some version after 4:

```json
{
"version_added": "4",
"version_removed": true
}
```

Note: many data categories no longer allow for `version_removed` to be set to `true`, as we are working to [improve the quality of the compatibility data](https://github.com/mdn/browser-compat-data/issues/3555).

#### `version_last`

> [!NOTE]
Expand Down Expand Up @@ -436,7 +400,7 @@ Example for one flag required:

```json
{
"version_added": true,
"version_added": "40",
"flags": [
{
"type": "preference",
Expand All @@ -451,7 +415,7 @@ Example for two flags required:

```json
{
"version_added": true,
"version_added": "40",
"flags": [
{
"type": "preference",
Expand Down
25 changes: 5 additions & 20 deletions schemas/compat-data.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,21 @@
"pattern": "^(≤?(\\d+)(\\.\\d+)*|preview)$"
},
{
"type": "boolean",
"nullable": true
"const": false
}
],
"tsType": "VersionValue"
},
"version_removed": {
"description": "A string, indicating which browser version removed this feature, or the value true, indicating that the feature was removed in an unknown version.",
"anyOf": [
{
"type": "string",
"pattern": "^(≤?(\\d+)(\\.\\d+)*|preview)$"
},
{
"const": true
}
],
"type": "string",
"pattern": "^(≤?(\\d+)(\\.\\d+)*|preview)$",
"tsType": "VersionValue"
},
"version_last": {
"description": "A string, indicating the last browser version that supported this feature, or the value true, indicating that the feature was removed in an unknown version. This is automatically generated.",
"anyOf": [
{
"type": "string",
"pattern": "^(≤?(\\d+)(\\.\\d+)*|preview)$"
},
{
"const": true
}
],
"type": "string",
"pattern": "^(≤?(\\d+)(\\.\\d+)*|preview)$",
"tsType": "VersionValue"
},
"prefix": {
Expand Down
30 changes: 15 additions & 15 deletions scripts/statistics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ describe('getStats', () => {
__compat: {
support: {
chrome: { version_added: '≤1' },
firefox: { version_added: '1' },
safari: { version_added: null },
firefox: { version_added: '4' },
safari: { version_added: '10' },
},
},
},
Expand All @@ -31,7 +31,7 @@ describe('getStats', () => {
__compat: {
support: {
chrome: { version_added: '1' },
firefox: { version_added: null },
firefox: { version_added: '≤30' },
safari: { version_added: '1' },
},
},
Expand All @@ -43,24 +43,24 @@ describe('getStats', () => {
it('should return stats for all browsers when allBrowsers is true', () => {
const stats = getStats('api', true, bcd);
assert.deepEqual(stats, {
total: { all: 3, true: 0, null: 1, range: 0, real: 2 },
chrome: { all: 1, true: 0, null: 0, range: 0, real: 1 },
firefox: { all: 1, true: 0, null: 1, range: 0, real: 0 },
safari: { all: 1, true: 0, null: 0, range: 0, real: 1 },
total: { all: 3, range: 1, real: 2 },
chrome: { all: 1, range: 0, real: 1 },
firefox: { all: 1, range: 1, real: 0 },
safari: { all: 1, range: 0, real: 1 },
});
});

it('should return stats for webextensions browsers when folder is "webextensions"', () => {
const stats = getStats('webextensions', false, bcd);
assert.deepEqual(stats, {
total: { all: 7, true: 0, null: 5, range: 1, real: 1 },
chrome: { all: 1, true: 0, null: 0, range: 1, real: 0 },
edge: { all: 1, true: 0, null: 1, range: 0, real: 0 },
firefox: { all: 1, true: 0, null: 0, range: 0, real: 1 },
opera: { all: 1, true: 0, null: 1, range: 0, real: 0 },
safari: { all: 1, true: 0, null: 1, range: 0, real: 0 },
firefox_android: { all: 1, true: 0, null: 1, range: 0, real: 0 },
safari_ios: { all: 1, true: 0, null: 1, range: 0, real: 0 },
total: { all: 7, range: 1, real: 6 },
chrome: { all: 1, range: 1, real: 0 },
edge: { all: 1, range: 0, real: 1 },
firefox: { all: 1, range: 0, real: 1 },
opera: { all: 1, range: 0, real: 1 },
safari: { all: 1, range: 0, real: 1 },
firefox_android: { all: 1, range: 0, real: 1 },
safari_ios: { all: 1, range: 0, real: 1 },
});
});

Expand Down
25 changes: 6 additions & 19 deletions scripts/statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import { getRefDate } from './release/utils.js';

interface VersionStatsEntry {
all: number;
true: number;
null: number;
range: number;
real: number;
}
Expand Down Expand Up @@ -80,16 +78,7 @@ const processData = (
browsers.forEach((browser) => {
stats[browser].all++;
stats.total.all++;
if (!data.support[browser]) {
stats[browser].null++;
stats.total.null++;
} else if (checkSupport(data.support[browser], null)) {
stats[browser].null++;
stats.total.null++;
} else if (checkSupport(data.support[browser], true)) {
stats[browser].true++;
stats.total.true++;
} else if (checkSupport(data.support[browser], '≤')) {
if (checkSupport(data.support[browser], '≤')) {
stats[browser].range++;
stats.total.range++;
} else {
Expand Down Expand Up @@ -148,10 +137,10 @@ const getStats = (
] as BrowserName[]);

const stats: VersionStats = {
total: { all: 0, true: 0, null: 0, range: 0, real: 0 },
total: { all: 0, range: 0, real: 0 },
};
browsers.forEach((browser) => {
stats[browser] = { all: 0, true: 0, null: 0, range: 0, real: 0 };
stats[browser] = { all: 0, range: 0, real: 0 };
});

if (folder) {
Expand Down Expand Up @@ -225,17 +214,15 @@ const printStats = (
}}: \n`,
);

let table = `| browser | real values | ranged values | \`true\` values | \`null\` values |
| --- | --- | --- | --- | --- |
let table = `| browser | real values | ranged values |
| --- | --- | --- |
`;

Object.keys(stats).forEach((entry) => {
table += `| ${entry.replace('_', ' ')} | `;
table += `${getStat(stats[entry], 'real', counts)} | `;
table += `${getStat(stats[entry], 'range', counts)} | `;
table += `${getStat(stats[entry], 'true', counts)} | `;
table += `${getStat(stats[entry], 'null', counts)} |
`;
table += '\n';
});

console.log(table);
Expand Down
Loading