mirror of
https://github.com/vale981/tridactyl
synced 2025-03-04 09:01:39 -05:00
eslint(unsupported-apis): improve checking as outlined in #4792
This commit is contained in:
parent
5635b91dee
commit
5f860f36de
1 changed files with 25 additions and 4 deletions
|
@ -1,15 +1,21 @@
|
|||
const bcd = require('@mdn/browser-compat-data');
|
||||
const api = bcd.webextensions.api;
|
||||
const supported_browsers = ["firefox", "chrome"];
|
||||
const minimalSupportedFirefoxVersion = 114;
|
||||
|
||||
function propertyNameOrValue(n) {
|
||||
return (n.property.type == "Literal" ? n.property.value : n.property.name)
|
||||
}
|
||||
|
||||
function detectBrowserUsage(context, node) {
|
||||
let localApi = api;
|
||||
let fullName = [];
|
||||
while (node.type == "MemberExpression" && node.property.name in localApi) {
|
||||
while (node.type == "MemberExpression" && propertyNameOrValue(node) in localApi) {
|
||||
const n = node;
|
||||
node = node.parent;
|
||||
fullName.push(n.property.name);
|
||||
localApi = localApi[n.property.name];
|
||||
let name = propertyNameOrValue(n);
|
||||
fullName.push(name);
|
||||
localApi = localApi[name];
|
||||
if (!localApi.__compat) {
|
||||
continue;
|
||||
}
|
||||
|
@ -21,8 +27,21 @@ function detectBrowserUsage(context, node) {
|
|||
messageId: "unsupportedApis",
|
||||
data: {
|
||||
name: browser,
|
||||
api: fullName.join("."),
|
||||
}
|
||||
});
|
||||
} else {
|
||||
const version = Number(support[browser].version_added);
|
||||
if (!isNaN(version) && version > minimalSupportedFirefoxVersion) {
|
||||
context.report({
|
||||
node: n,
|
||||
messageId: "apiTooRecent",
|
||||
data: {
|
||||
api: fullName.join("."),
|
||||
version: minimalSupportedFirefoxVersion
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,12 +50,14 @@ function detectBrowserUsage(context, node) {
|
|||
module.exports = {
|
||||
meta: {
|
||||
messages: {
|
||||
unsupportedApis: "Unsupported on '{{ name }}'"
|
||||
unsupportedApis: "{{ api }} unsupported on '{{ name }}'",
|
||||
apiTooRecent: "{{ api }} is not supported on firefox {{ version }}",
|
||||
}
|
||||
},
|
||||
create(context) {
|
||||
return {
|
||||
'MemberExpression[object.name="browser"]': (n) => detectBrowserUsage(context, n),
|
||||
'MemberExpression[object.name="browserBg"]': (n) => detectBrowserUsage(context, n),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue