Bug 1353542 - Add an eslint rule deprecating usage of Task.jsm in browser/ and toolkit/, r=Mossop.
This commit is contained in:
@@ -25,5 +25,7 @@ module.exports = {
|
||||
|
||||
"no-mixed-spaces-and-tabs": "error",
|
||||
"no-shadow": "error",
|
||||
|
||||
"mozilla/no-task": "error",
|
||||
}
|
||||
};
|
||||
|
||||
@@ -21,8 +21,7 @@ function makeTest(name, startURL, startProcessIsRemote, endURL, endProcessIsRemo
|
||||
is(browser.isRemoteBrowser, startProcessIsRemote, "Should be displayed in the right process");
|
||||
|
||||
let docLoadedPromise = waitForDocLoadComplete();
|
||||
let asyncTask = Task.async(transitionTask);
|
||||
let expectSyncChange = await asyncTask(browser, endURL);
|
||||
let expectSyncChange = await transitionTask(browser, endURL);
|
||||
if (expectSyncChange) {
|
||||
is(browser.isRemoteBrowser, endProcessIsRemote, "Should have switched to the right process synchronously");
|
||||
}
|
||||
|
||||
@@ -19,21 +19,21 @@ this.Buttons = {
|
||||
|
||||
configurations: {
|
||||
navBarButtons: {
|
||||
applyConfig: Task.async(() => {
|
||||
applyConfig: async () => {
|
||||
CustomizableUI.addWidgetToArea("screenshot-widget", CustomizableUI.AREA_NAVBAR);
|
||||
}),
|
||||
},
|
||||
},
|
||||
|
||||
tabsToolbarButtons: {
|
||||
applyConfig: Task.async(() => {
|
||||
applyConfig: async () => {
|
||||
CustomizableUI.addWidgetToArea("screenshot-widget", CustomizableUI.AREA_TABSTRIP);
|
||||
}),
|
||||
},
|
||||
},
|
||||
|
||||
menuPanelButtons: {
|
||||
applyConfig: Task.async(() => {
|
||||
applyConfig: async () => {
|
||||
CustomizableUI.addWidgetToArea("screenshot-widget", CustomizableUI.AREA_PANEL);
|
||||
}),
|
||||
},
|
||||
|
||||
verifyConfig() {
|
||||
let browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
@@ -45,9 +45,9 @@ this.Buttons = {
|
||||
},
|
||||
|
||||
custPaletteButtons: {
|
||||
applyConfig: Task.async(() => {
|
||||
applyConfig: async () => {
|
||||
CustomizableUI.removeWidgetFromArea("screenshot-widget");
|
||||
}),
|
||||
},
|
||||
|
||||
verifyConfig() {
|
||||
let browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
|
||||
@@ -9,5 +9,7 @@ module.exports = {
|
||||
// XXX Bug 1326071 - This should be reduced down - probably to 20 or to
|
||||
// be removed & synced with the mozilla/recommended value.
|
||||
"complexity": ["error", 41],
|
||||
|
||||
"mozilla/no-task": "error",
|
||||
}
|
||||
};
|
||||
|
||||
@@ -18,19 +18,19 @@ XPCOMUtils.defineLazyGetter(this, "Sanitizer", function() {
|
||||
* be removed when the user sanitizes their history.
|
||||
*/
|
||||
function* runTests() {
|
||||
yield Task.spawn(function*() {
|
||||
yield (async function() {
|
||||
dontExpireThumbnailURLs([URL, URL_COPY]);
|
||||
|
||||
yield promiseClearHistory();
|
||||
yield promiseAddVisitsAndRepopulateNewTabLinks(URL);
|
||||
yield promiseCreateThumbnail();
|
||||
await promiseClearHistory();
|
||||
await promiseAddVisitsAndRepopulateNewTabLinks(URL);
|
||||
await promiseCreateThumbnail();
|
||||
|
||||
// Make sure Storage.copy() updates an existing file.
|
||||
yield PageThumbsStorage.copy(URL, URL_COPY);
|
||||
await PageThumbsStorage.copy(URL, URL_COPY);
|
||||
let copy = new FileUtils.File(PageThumbsStorage.getFilePathForURL(URL_COPY));
|
||||
let mtime = copy.lastModifiedTime -= 60;
|
||||
|
||||
yield PageThumbsStorage.copy(URL, URL_COPY);
|
||||
await PageThumbsStorage.copy(URL, URL_COPY);
|
||||
isnot(new FileUtils.File(PageThumbsStorage.getFilePathForURL(URL_COPY)).lastModifiedTime, mtime,
|
||||
"thumbnail file was updated");
|
||||
|
||||
@@ -41,37 +41,37 @@ function* runTests() {
|
||||
// locks them sometimes.
|
||||
info("Clearing history");
|
||||
while (file.exists() || fileCopy.exists()) {
|
||||
yield promiseClearHistory();
|
||||
await promiseClearHistory();
|
||||
}
|
||||
info("History is clear");
|
||||
|
||||
info("Repopulating");
|
||||
yield promiseAddVisitsAndRepopulateNewTabLinks(URL);
|
||||
yield promiseCreateThumbnail();
|
||||
await promiseAddVisitsAndRepopulateNewTabLinks(URL);
|
||||
await promiseCreateThumbnail();
|
||||
|
||||
info("Clearing the last 10 minutes of browsing history");
|
||||
// Clear the last 10 minutes of browsing history.
|
||||
yield promiseClearHistory(true);
|
||||
await promiseClearHistory(true);
|
||||
|
||||
info("Attempt to clear file");
|
||||
// Retry until the file is gone because Windows locks it sometimes.
|
||||
yield promiseClearFile(file, URL);
|
||||
await promiseClearFile(file, URL);
|
||||
|
||||
info("Done");
|
||||
});
|
||||
})();
|
||||
}
|
||||
|
||||
var promiseClearFile = Task.async(function*(aFile, aURL) {
|
||||
async function promiseClearFile(aFile, aURL) {
|
||||
if (!aFile.exists()) {
|
||||
return undefined;
|
||||
}
|
||||
// Re-add our URL to the history so that history observer's onDeleteURI()
|
||||
// is called again.
|
||||
yield PlacesTestUtils.addVisits(makeURI(aURL));
|
||||
yield promiseClearHistory(true);
|
||||
await PlacesTestUtils.addVisits(makeURI(aURL));
|
||||
await promiseClearHistory(true);
|
||||
// Then retry.
|
||||
return promiseClearFile(aFile, aURL);
|
||||
});
|
||||
}
|
||||
|
||||
function promiseClearHistory(aUseRange) {
|
||||
let s = new Sanitizer();
|
||||
|
||||
@@ -592,7 +592,7 @@ ConnectionData.prototype = Object.freeze({
|
||||
try {
|
||||
// Keep Task.spawn here to preserve API compat; unfortunately
|
||||
// func was a generator rather than a task here.
|
||||
result = await Task.spawn(func);
|
||||
result = await Task.spawn(func); // eslint-disable-line mozilla/no-task
|
||||
} catch (ex) {
|
||||
// It's possible that the exception has been caused by trying to
|
||||
// close the connection in the middle of a transaction.
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
/* eslint-disable mozilla/no-task */
|
||||
|
||||
this.EXPORTED_SYMBOLS = [
|
||||
"Task"
|
||||
];
|
||||
|
||||
@@ -550,7 +550,7 @@ tests.push(
|
||||
// Test that Promise.resolve throws when its argument is an async function.
|
||||
tests.push(
|
||||
make_promise_test(function test_promise_resolve_throws_with_async_function(test) {
|
||||
Assert.throws(() => Promise.resolve(Task.async(function* () {})),
|
||||
Assert.throws(() => Promise.resolve(Task.async(function* () {})), // eslint-disable-line mozilla/no-task
|
||||
/Cannot resolve a promise with an async function/);
|
||||
return Promise.resolve();
|
||||
}));
|
||||
|
||||
@@ -46,6 +46,7 @@ module.exports = {
|
||||
"no-single-arg-cu-import": require("../lib/rules/no-single-arg-cu-import"),
|
||||
"no-import-into-var-and-global":
|
||||
require("../lib/rules/no-import-into-var-and-global.js"),
|
||||
"no-task": require("../lib/rules/no-task"),
|
||||
"no-useless-parameters": require("../lib/rules/no-useless-parameters"),
|
||||
"no-useless-removeEventListener":
|
||||
require("../lib/rules/no-useless-removeEventListener"),
|
||||
@@ -70,6 +71,7 @@ module.exports = {
|
||||
"no-cpows-in-tests": "off",
|
||||
"no-single-arg-cu-import": "off",
|
||||
"no-import-into-var-and-global": "off",
|
||||
"no-task": "off",
|
||||
"no-useless-parameters": "off",
|
||||
"no-useless-removeEventListener": "off",
|
||||
"reject-importGlobalProperties": "off",
|
||||
|
||||
31
tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-task.js
Normal file
31
tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-task.js
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @fileoverview Reject common XPCOM methods called with useless optional
|
||||
* parameters, or non-existent parameters.
|
||||
*
|
||||
* 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
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
module.exports = function(context) {
|
||||
// ---------------------------------------------------------------------------
|
||||
// Public
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
return {
|
||||
"CallExpression": function(node) {
|
||||
let callee = node.callee;
|
||||
if (callee.type === "MemberExpression" &&
|
||||
callee.object.type === "Identifier" &&
|
||||
callee.object.name === "Task") {
|
||||
context.report({node, message: "Task.jsm is deprecated."});
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user