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

Permissions API permissions descriptions linter #6156

Merged
merged 3 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions docs/data-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,27 @@ For example, the `ImageData` API has worker support, recorded like this:

Formerly named `available_in_workers`, this policy was set in [#2362](https://github.com/mdn/browser-compat-data/pull/2362).

### Permissions API permission descriptions (`api.Permissions.*_permission.__compat.description`)

Document Permissions API permissions called `[permissionname]` as `api.Permissions.[permissionname]_permission` and add a description that reads `"<code>[permissionname]</code> permission"`
For example, the Geolocation permission is named `geolocation_permission` with the description text `<code>geolocation</code> permission`, like this:

```
{
"api": {
"Permissions": {
"__compat": { ... },
"geolocation_permission": {
"__compat": {
"description": "<code>geolocation</code> permission",
"support": { ... }
}
}
}
}
}
```

## Non-functional defined names imply `partial_implementation`

If a browser recognizes an API name, but the API doesn’t have any discernable behavior, use `"partial_implementation": true` instead of `"version_added": false`, as if the feature has non-standard support, rather than no support.
Expand Down
30 changes: 30 additions & 0 deletions test/linter/test-descriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,29 @@ function hasCorrectWebWorkersDescription(apiData, apiName, logger) {
}
}

/**
* @param {Identifier} apiData
* @param {String} apiName
* @param {Logger} logger
*/
function hasCorrectPermissionDescription(apiData, apiName, logger) {
const expectedDescrition = `<code>${apiName.replace(
'_permission',
'',
)}</code> permission`;
if (
apiName &&
apiName.match('_permission$') &&
apiData &&
apiData.__compat &&
apiData.__compat.description !== expectedDescrition
) {
logger.error(chalk`{red Incorrect permission description for {bold ${apiName}}}
{yellow Actual: {bold "${apiData.__compat.description || ''}"}}
{green Expected: {bold "${expectedDescrition}"}}`);
}
}

/**
* @param {string} filename
*/
Expand All @@ -101,6 +124,13 @@ function testDescriptions(filename) {
}
}

if (data.api && data.api.Permissions) {
for (const permissionKey in data.api.Permissions) {
const apiData = data.api.Permissions[permissionKey];
hasCorrectPermissionDescription(apiData, permissionKey, logger);
}
}

if (errors.length) {
console.error(
chalk`{red Descriptions – {bold ${errors.length}} ${
Expand Down