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

fix: webextensions: change let to const, or remove assigning when unn… #20280

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let gettingText = browser.action.getBadgeText(
browser.action.getBadgeText(
details // object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't comment the parameter's type everywhere else, but I guess webext is free to have its own convention, or we can do that as a followup

)
```
Expand Down Expand Up @@ -59,8 +59,7 @@ function gotBadgeText(text) {
console.log(text);
}

let gettingBadgeText = browser.action.getBadgeText({});
gettingBadgeText.then(gotBadgeText);
browser.action.getBadgeText({}).then(gotBadgeText);
```

{{WebExtExamples}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let gettingPopup = browser.action.getPopup(
browser.action.getPopup(
details // object
)
```
Expand Down Expand Up @@ -59,8 +59,7 @@ function gotPopup(popupURL) {
console.log(popupURL);
}

let gettingPopup = browser.action.getPopup({});
gettingPopup.then(gotPopup);
browser.action.getPopup({}).then(gotPopup);
```

{{WebExtExamples}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let gettingTitle = browser.action.getTitle(
browser.action.getTitle(
details // object
)
```
Expand Down Expand Up @@ -66,8 +66,7 @@ function toggleTitle(title) {
}

browser.action.onClicked.addListener(() => {
let gettingTitle = browser.action.getTitle({});
gettingTitle.then(toggleTitle);
browser.action.getTitle({}).then(toggleTitle);
});
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let gettingIsEnabled = browser.action.isEnabled(
browser.action.isEnabled(
details // object
)
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let settingIcon = browser.action.setIcon(
browser.action.setIcon(
details // object
)
```
Expand All @@ -48,7 +48,7 @@ let settingIcon = browser.action.setIcon(

Use a dictionary object to specify multiple `ImageData` objects in different sizes, so the icon does not have to be scaled for a device with a different pixel density. If `imageData` is a dictionary, the value of each property is an `ImageData` object, and its name is its size, like this:

```json
```
{
16: image16,
32: image32
Expand All @@ -63,7 +63,7 @@ let settingIcon = browser.action.setIcon(

Use a dictionary object to specify multiple icon files in different sizes, so the icon does not have to be scaled for a device with a different pixel density. If `path` is a dictionary, the value of each property is a relative path, and its name is its size, like this:

```json
```
{
16: "path/to/image16.jpg",
32: "path/to/image32.jpg"
Expand Down Expand Up @@ -130,8 +130,8 @@ The code below sets the icon using an [`ImageData`](/en-US/docs/Web/API/ImageDat

```js
function getImageData() {
let canvas = document.createElement("canvas");
let ctx = canvas.getContext("2d");
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");

ctx.fillStyle = "green";
ctx.fillRect(10, 10, 100, 100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ function toggleTitle(title) {
}

browser.action.onClicked.addListener(() => {
let gettingTitle = browser.action.getTitle({});
gettingTitle.then(toggleTitle);
browser.action.getTitle({}).then(toggleTitle);
});
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let clearAlarm = browser.alarms.clear(
browser.alarms.clear(
name // string
)
```
Expand All @@ -41,11 +41,10 @@ A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that

```js
function onCleared(wasCleared) {
console.log(wasCleared); // true/false
console.log(wasCleared); // true / false
}

let clearAlarm = browser.alarms.clear("my-periodic-alarm");
clearAlarm.then(onCleared);
browser.alarms.clear("my-periodic-alarm").then(onCleared);
```

{{WebExtExamples}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let clearAlarms = browser.alarms.clearAll()
browser.alarms.clearAll()
```

### Parameters
Expand All @@ -41,8 +41,7 @@ function onClearedAll(wasCleared) {
console.log(wasCleared); // true/false
}

let clearAlarms = browser.alarms.clearAll();
clearAlarms.then(onClearedAll);
browser.alarms.clearAll().then(onClearedAll);
```

{{WebExtExamples}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let getAlarm = browser.alarms.get(
browser.alarms.get(
name // optional string
)
```
Expand All @@ -46,8 +46,7 @@ function gotAlarm(alarm) {
}
}

let getAlarm = browser.alarms.get("my-periodic-alarm");
getAlarm.then(gotAlarm);
browser.alarms.get("my-periodic-alarm").then(gotAlarm);
```

{{WebExtExamples}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let getAlarms = browser.alarms.getAll()
browser.alarms.getAll()
```

### Parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let createBookmark = browser.bookmarks.create(
browser.bookmarks.create(
bookmark // CreateDetails object
)
```
Expand All @@ -50,12 +50,11 @@ function onCreated(node) {
console.log(node);
}

let createBookmark = browser.bookmarks.create({
browser.bookmarks.create({
title: "bookmarks.create() on MDN",
url: "https://developer.mozilla.org/Add-ons/WebExtensions/API/bookmarks/create"
});

createBookmark.then(onCreated);
url: "https://developer.mozilla.org/Add-ons/WebExtensions/API/bookmarks/create",
})
.then(onCreated);
```

{{WebExtExamples}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let getBookmarks = browser.bookmarks.get(
browser.bookmarks.get(
idOrIdList // string or string array
)
```
Expand All @@ -50,8 +50,7 @@ function onRejected(error) {
console.log(`An error: ${error}`);
}

let gettingBookmarks = browser.bookmarks.get("bookmarkAAAA");
gettingBookmarks.then(onFulfilled, onRejected);
browser.bookmarks.get("bookmarkAAAA").then(onFulfilled, onRejected);
```

{{WebExtExamples}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let gettingChildren = browser.bookmarks.getChildren(
browser.bookmarks.getChildren(
id // string
)
```
Expand Down Expand Up @@ -54,8 +54,7 @@ function onRejected(error) {
console.log(`An error: ${error}`);
}

let gettingChildren = browser.bookmarks.getChildren("unfiled_____");
gettingChildren.then(onFulfilled, onRejected);
browser.bookmarks.getChildren("unfiled_____").then(onFulfilled, onRejected);
```

{{WebExtExamples}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let gettingRecent = browser.bookmarks.getRecent(
browser.bookmarks.getRecent(
numberOfItems // integer
)
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let gettingSubTree = browser.bookmarks.getSubTree(
browser.bookmarks.getSubTree(
id // string
)
```
Expand Down Expand Up @@ -72,7 +72,7 @@ function onRejected(error) {
console.log(`An error: ${error}`);
}

let subTreeID = "root_____";
const subTreeID = "root_____";

browser.bookmarks.getSubTree(subTreeID).then(logSubTree, onRejected);
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let gettingTree = browser.bookmarks.getTree()
browser.bookmarks.getTree()
```

### Parameters
Expand Down Expand Up @@ -68,8 +68,7 @@ function onRejected(error) {
console.log(`An error: ${error}`);
}

let gettingTree = browser.bookmarks.getTree();
gettingTree.then(logTree, onRejected);
browser.bookmarks.getTree().then(logTree, onRejected);
```

{{WebExtExamples}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let movingBookmark = browser.bookmarks.move(
browser.bookmarks.move(
id, // string
destination // object
)
Expand Down Expand Up @@ -65,10 +65,9 @@ function onRejected(error) {
console.log(`An error: ${error}`);
}

let bookmarkId = "abcdefghijkl";
const bookmarkId = "abcdefghijkl";

let movingBookmark = browser.bookmarks.move(bookmarkId, { index: 0 });
movingBookmark.then(onMoved, onRejected);
browser.bookmarks.move(bookmarkId, { index: 0 }).then(onMoved, onRejected);
```

{{WebExtExamples}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let removingBookmark = browser.bookmarks.remove(
browser.bookmarks.remove(
id // string
)
```
Expand All @@ -52,10 +52,9 @@ function onRejected(error) {
console.log(`An error: ${error}`);
}

let bookmarkId = "abcdefghijkl";
const bookmarkId = "abcdefghijkl";

let removingBookmark = browser.bookmarks.remove(bookmarkId);
removingBookmark.then(onRemoved, onRejected);
browser.bookmarks.remove(bookmarkId).then(onRemoved, onRejected);
```

{{WebExtExamples}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let removingTree = browser.bookmarks.removeTree(
browser.bookmarks.removeTree(
id // string
)
```
Expand Down Expand Up @@ -56,13 +56,11 @@ function onRejected(error) {

function removeMDN(searchResults) {
if (searchResults.length) {
let removing = browser.bookmarks.removeTree(searchResults[0].id);
removing.then(onRemoved, onRejected);
browser.bookmarksremoveTree(searchResults[0].id).then(onRemoved, onRejected);
}
}

let searchingBookmarks = browser.bookmarks.search({ title: "MDN" });
searchingBookmarks.then(removeMDN, onRejected);
browser.bookmarks.search({ title: "MDN" }).then(removeMDN, onRejected);
```

{{WebExtExamples}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let searching = browser.bookmarks.search(
browser.bookmarks.search(
query // string or object
)
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let updating = browser.bookmarks.update(
browser.bookmarks.update(
id, // string
changes // object
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/Java
## Syntax

```js-nolint
let gettingText = browser.browserAction.getBadgeText(
browser.browserAction.getBadgeText(
details // object
)
```
Expand Down Expand Up @@ -61,8 +61,7 @@ function gotBadgeText(text) {
console.log(text);
}

let gettingBadgeText = browser.browserAction.getBadgeText({});
gettingBadgeText.then(gotBadgeText);
browser.browserAction.getBadgeText({}).then(gotBadgeText);
```

{{WebExtExamples}}
Expand Down
Loading