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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
21 changes: 4 additions & 17 deletions scripts/traverse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const main = (
browsers: BrowserName[] = Object.keys(bcd.browsers).filter(
(b) => bcd.browsers[b].type !== 'server',
) as BrowserName[],
values = ['null', 'true'],
values = [],
depth = 100,
tag = '',
status = {} as StatusFilters,
Expand Down Expand Up @@ -245,13 +245,6 @@ if (esMain(import.meta)) {
nargs: 1,
default: '',
})
.option('non-real', {
alias: 'n',
describe:
'Filter to features with non-real values. Alias for "-f true -f null"',
type: 'boolean',
nargs: 0,
})
.option('depth', {
alias: 'd',
describe:
Expand Down Expand Up @@ -288,12 +281,8 @@ if (esMain(import.meta)) {
default: undefined,
})
.example(
'npm run traverse -- --browser=safari -n',
'Find all features containing non-real Safari entries',
)
.example(
'npm run traverse -- -b webview_android -f true',
'Find all features marked as true for WebView',
'npm run traverse -- -b webview_android -f ≤37',
'Find all features marked as ≤37 for WebView',
)
.example(
'npm run traverse -- -b firefox -f 10',
Expand Down Expand Up @@ -330,12 +319,10 @@ if (esMain(import.meta)) {
},
);

const filter = [...argv.filter, ...(argv.nonReal ? ['true', 'null'] : [])];

const features = main(
argv.folder,
argv.browser,
filter,
argv.filter,
argv.depth,
argv.tag,
argv.status,
Expand Down
Loading