Skip to content
Snippets Groups Projects
Commit 274f8662 authored by Mark Banner's avatar Mark Banner
Browse files

Bug 1479515 - Extend the ESLint rule for checking Ci properties to check for...

Bug 1479515 - Extend the ESLint rule for checking Ci properties to check for unknown interfaces as well. r=Gijs,application-update-reviewers,nalexander

Differential Revision: https://phabricator.services.mozilla.com/D156425
parent fd892006
No related branches found
No related tags found
No related merge requests found
valid-ci-uses
=============
Ensures that property access on ``Ci.<interface>`` are valid.
Ensures that interface accesses on ``Ci`` are valid, and property accesses on
``Ci.<interface>`` are also valid.
This rule requires a full build to run, and is not turned on by default. To run
this rule manually, use:
......@@ -13,6 +14,12 @@ this rule manually, use:
Examples of incorrect code for this rule:
-----------------------------------------
``nsIFoo`` does not exist.
.. code-block:: js
Ci.nsIFoo
``UNKNOWN_CONSTANT`` does not exist on nsIURIFixup.
.. code-block:: js
......@@ -22,6 +29,12 @@ Examples of incorrect code for this rule:
Examples of correct code for this rule:
---------------------------------------
``nsIFile`` does exist.
.. code-block:: js
Ci.nsIFile
``FIXUP_FLAG_NONE`` does exist on nsIURIFixup.
.. code-block:: js
......
......@@ -87,17 +87,13 @@ function exactGC() {
function resetQuotaManager() {
return new Promise(function(resolve) {
var qm = Cc["@mozilla.org/dom/quota/manager;1"].getService(
Ci.nsIQuotaManager
);
var prefService = Services.prefs;
// enable quota manager testing mode
var pref = "dom.quotaManager.testing";
prefService.getBranch(null).setBoolPref(pref, true);
var request = qm.reset();
var request = Services.qms.reset();
request.callback = resolve;
// disable quota manager testing mode
......
......@@ -6,9 +6,6 @@
/* globals gSandbox */
const nsILDAPURL = Ci.nsILDAPURL;
const LDAPURLContractID = "@mozilla.org/network/ldap-url;1";
const nsILDAPSyncQuery = Ci.nsILDAPSyncQuery;
const LDAPSyncQueryContractID = "@mozilla.org/ldapsyncquery;1";
var gVersion;
......@@ -133,13 +130,17 @@ function getLDAPAttributes(host, base, filter, attribs, isSecure) {
"?sub?" +
filter;
// nsILDAP* are only defined in comm-central.
// eslint-disable-next-line mozilla/valid-ci-uses
var url = Services.io.newURI(urlSpec).QueryInterface(Ci.nsILDAPURL);
var ldapquery = Cc[LDAPSyncQueryContractID].createInstance(
nsILDAPSyncQuery
// eslint-disable-next-line mozilla/valid-ci-uses
Ci.nsILDAPSyncQuery
);
// default to LDAP v3
if (!gVersion) {
// eslint-disable-next-line mozilla/valid-ci-uses
gVersion = Ci.nsILDAPConnection.VERSION3;
}
// user supplied method
......
......@@ -141,12 +141,6 @@ XPCOMUtils.defineLazyGetter(this, "gUpdateChecker", function test_gUC() {
);
});
XPCOMUtils.defineLazyGetter(this, "gUP", function test_gUP() {
return Cc["@mozilla.org/updates/update-prompt;1"].createInstance(
Ci.nsIUpdatePrompt
);
});
XPCOMUtils.defineLazyGetter(this, "gDefaultPrefBranch", function test_gDPB() {
return Services.prefs.getDefaultBranch(null);
});
......
/**
* @fileoverview Reject uses of unknown properties on Ci.<interface>.
* @fileoverview Reject uses of unknown interfaces on Ci and properties of those
* interfaces.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -8,8 +9,55 @@
"use strict";
const os = require("os");
const helpers = require("../helpers");
// These interfaces are all platform specific, so may be not present
// on all platforms.
const platformSpecificInterfaces = new Map([
["nsIAboutThirdParty", "windows"],
["nsIJumpListItem", "windows"],
["nsIJumpListLink", "windows"],
["nsIJumpListSeparator", "windows"],
["nsIJumpListShortcut", "windows"],
["nsITaskbarWindowPreview", "windows"],
["nsIWindowsAlertsService", "windows"],
["nsIWinAppHelper", "windows"],
["nsIWinTaskbar", "windows"],
["nsIWinTaskSchedulerService", "windows"],
["nsIWindowsRegKey", "windows"],
["nsIWindowsPackageManager", "windows"],
["nsIWindowsShellService", "windows"],
["nsIMacShellService", "darwin"],
["nsIMacDockSupport", "darwin"],
["nsIMacFinderProgress", "darwin"],
["nsIMacSharingService", "darwin"],
["nsIMacUserActivityUpdater", "darwin"],
["nsIMacWebAppUtils", "darwin"],
["nsIStandaloneNativeMenu", "darwin"],
["nsITouchBarHelper", "darwin"],
["nsITouchBarInput", "darwin"],
["nsITouchBarUpdater", "darwin"],
["mozISandboxReporter", "linux"],
["nsIApplicationChooser", "linux"],
["nsIGNOMEShellService", "linux"],
["nsIGtkTaskbarProgress", "linux"],
// These are used in the ESLint test code.
["amIFoo", "any"],
["nsIMeh", "any"],
// Can't easily detect android builds from ESLint at the moment.
["nsIAndroidBridge", "any"],
["nsIAndroidView", "any"],
// Code coverage is enabled only for certain builds (MOZ_CODE_COVERAGE).
["nsICodeCoverage", "any"],
// Layout debugging is enabled only for certain builds (MOZ_LAYOUT_DEBUGGER).
["nsILayoutDebuggingTools", "any"],
// Sandbox test is only enabled for certain configurations (MOZ_SANDBOX,
// MOZ_DEBUG, ENABLE_TESTS).
["mozISandboxTest", "any"],
]);
function interfaceHasProperty(interfaceName, propertyName) {
// `Ci.nsIFoo.number` is valid, it returns the iid.
if (propertyName == "number") {
......@@ -18,7 +66,6 @@ function interfaceHasProperty(interfaceName, propertyName) {
let interfaceInfo = helpers.xpidlData.get(interfaceName);
// TODO: Check for missing interfaces.
if (!interfaceInfo) {
return true;
}
......@@ -41,6 +88,9 @@ module.exports = {
"https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/valid-ci-uses.html",
},
messages: {
missingInterface:
"{{ interface }} is defined in this rule's platform specific list, but is not available",
unknownInterface: "Use of unknown interface Ci.{{ interface}}",
unknownProperty:
"Use of unknown property Ci.{{ interface }}.{{ property }}",
},
......@@ -50,6 +100,38 @@ module.exports = {
create(context) {
return {
MemberExpression(node) {
if (
node.computed === false &&
node.type === "MemberExpression" &&
node.object.type === "Identifier" &&
node.object.name === "Ci" &&
node.property.type === "Identifier" &&
node.property.name.includes("I")
) {
if (!helpers.xpidlData.get(node.property.name)) {
let platformSpecific = platformSpecificInterfaces.get(
node.property.name
);
if (!platformSpecific) {
context.report({
node,
messageId: "unknownInterface",
data: {
interface: node.property.name,
},
});
} else if (platformSpecific == os.platform) {
context.report({
node,
messageId: "missingInterface",
data: {
interface: node.property.name,
},
});
}
}
}
if (
node.computed === false &&
node.object.type === "MemberExpression" &&
......
......@@ -7,6 +7,7 @@
// Requirements
// ------------------------------------------------------------------------------
var os = require("os");
var rule = require("../lib/rules/valid-ci-uses");
var RuleTester = require("eslint").RuleTester;
......@@ -22,12 +23,36 @@ function invalidCode(code, messageId, data) {
process.env.TEST_XPIDLDIR = `${__dirname}/xpidl`;
ruleTester.run("valid-ci-uses", rule, {
valid: ["Ci.nsIURIFixup.FIXUP_FLAG_NONE"],
const tests = {
valid: ["Ci.nsIURIFixup", "Ci.nsIURIFixup.FIXUP_FLAG_NONE"],
invalid: [
invalidCode("Ci.nsIURIFixup.UNKNOWN_CONSTANT", "unknownProperty", {
interface: "nsIURIFixup",
property: "UNKNOWN_CONSTANT",
}),
invalidCode("Ci.nsIFoo", "unknownInterface", {
interface: "nsIFoo",
}),
],
});
};
// For ESLint tests, we only have a couple of xpt examples in the xpidl directory.
// Therefore we can pretend that these interfaces no longer exist.
switch (os.platform) {
case "windows":
tests.invalid.push(
invalidCode("Ci.nsIJumpListShortcut", "missingInterface")
);
break;
case "darwin":
tests.invalid.push(
invalidCode("Ci.nsIMacShellService", "missingInterface")
);
break;
case "linux":
tests.invalid.push(
invalidCode("Ci.mozISandboxReporter", "missingInterface")
);
}
ruleTester.run("valid-ci-uses", rule, tests);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment