Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1353542 - Add an eslint rule deprecating usage of Task.jsm in bro…
Browse files Browse the repository at this point in the history
…wser/ and toolkit/, r=Mossop.
  • Loading branch information
fqueze committed May 12, 2017
1 parent 8b4816e commit d837c7a
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 28 deletions.
2 changes: 2 additions & 0 deletions browser/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ module.exports = {

"no-mixed-spaces-and-tabs": "error",
"no-shadow": "error",

"mozilla/no-task": "error",
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -45,9 +45,9 @@ this.Buttons = {
},

custPaletteButtons: {
applyConfig: Task.async(() => {
applyConfig: async () => {
CustomizableUI.removeWidgetFromArea("screenshot-widget");
}),
},

verifyConfig() {
let browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
Expand Down
2 changes: 2 additions & 0 deletions toolkit/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
};
32 changes: 16 additions & 16 deletions toolkit/components/thumbnails/test/browser_thumbnails_storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion toolkit/modules/Sqlite.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions toolkit/modules/Task.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

"use strict";

/* eslint-disable mozilla/no-task */

this.EXPORTED_SYMBOLS = [
"Task"
];
Expand Down
2 changes: 1 addition & 1 deletion toolkit/modules/tests/xpcshell/test_Promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}));
Expand Down
2 changes: 2 additions & 0 deletions tools/lint/eslint/eslint-plugin-mozilla/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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",
Expand Down
31 changes: 31 additions & 0 deletions tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-task.js
Original file line number Diff line number Diff line change
@@ -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."});
}
}
};
};

0 comments on commit d837c7a

Please sign in to comment.