Skip to content

Commit 9535aac

Browse files
matthiaskdr-rompecabezas
authored andcommitted
Prefer template literals to string concatenation
1 parent 301f2cd commit 9535aac

File tree

5 files changed

+29
-40
lines changed

5 files changed

+29
-40
lines changed

biome.json

-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
"useArrowFunction": "off",
1616
"noForEach": "off"
1717
},
18-
"style": {
19-
"useTemplate": "off"
20-
},
2118
"suspicious": {
2219
"noAssignInExpressions": "off"
2320
}

debug_toolbar/static/debug_toolbar/js/history.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function refreshHistory() {
7474

7575
function switchHistory(newStoreId) {
7676
const formTarget = djDebug.querySelector(
77-
".switchHistory[data-store-id='" + newStoreId + "']"
77+
`.switchHistory[data-store-id='${newStoreId}']`
7878
);
7979
const tbody = formTarget.closest("tbody");
8080

@@ -88,7 +88,7 @@ function switchHistory(newStoreId) {
8888
if (Object.keys(data).length === 0) {
8989
const container = document.getElementById("djdtHistoryRequests");
9090
container.querySelector(
91-
'button[data-store-id="' + newStoreId + '"]'
91+
`button[data-store-id="${newStoreId}"]`
9292
).innerHTML = "Switch [EXPIRED]";
9393
}
9494
replaceToolbarState(newStoreId, data);

debug_toolbar/static/debug_toolbar/js/timer.js

+14-19
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,31 @@ function insertBrowserTiming() {
2727
} else {
2828
width = 0;
2929
}
30-
return width < 1 ? "2px" : width + "%";
30+
return width < 1 ? "2px" : `${width}%`;
3131
}
3232
function addRow(tbody, stat, endStat) {
3333
const row = document.createElement("tr");
34+
const elapsed = performance.timing[stat] - timingOffset;
3435
if (endStat) {
36+
const duration =
37+
performance.timing[endStat] - performance.timing[stat];
3538
// Render a start through end bar
36-
row.innerHTML =
37-
"<td>" +
38-
stat.replace("Start", "") +
39-
"</td>" +
40-
'<td><svg class="djDebugLineChart" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 5" preserveAspectRatio="none"><rect y="0" height="5" fill="#ccc" /></svg></td>' +
41-
"<td>" +
42-
(performance.timing[stat] - timingOffset) +
43-
" (+" +
44-
(performance.timing[endStat] - performance.timing[stat]) +
45-
")</td>";
39+
row.innerHTML = `
40+
<td>${stat.replace("Start", "")}</td>
41+
<td><svg class="djDebugLineChart" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 5" preserveAspectRatio="none"><rect y="0" height="5" fill="#ccc" /></svg></td>
42+
<td>${elapsed} (+${duration})</td>
43+
`;
4644
row.querySelector("rect").setAttribute(
4745
"width",
4846
getCSSWidth(stat, endStat)
4947
);
5048
} else {
5149
// Render a point in time
52-
row.innerHTML =
53-
"<td>" +
54-
stat +
55-
"</td>" +
56-
'<td><svg class="djDebugLineChart" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 5" preserveAspectRatio="none"><rect y="0" height="5" fill="#ccc" /></svg></td>' +
57-
"<td>" +
58-
(performance.timing[stat] - timingOffset) +
59-
"</td>";
50+
row.innerHTML = `
51+
<td>${stat}</td>
52+
<td><svg class="djDebugLineChart" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 5" preserveAspectRatio="none"><rect y="0" height="5" fill="#ccc" /></svg></td>
53+
<td>${elapsed}</td>
54+
`;
6055
row.querySelector("rect").setAttribute("width", 2);
6156
}
6257
row.querySelector("rect").setAttribute("x", getLeft(stat));

debug_toolbar/static/debug_toolbar/js/toolbar.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const djdt = {
116116
const toggleClose = "-";
117117
const openMe = this.textContent === toggleOpen;
118118
const name = this.dataset.toggleName;
119-
const container = document.getElementById(name + "_" + id);
119+
const container = document.getElementById(`${name}_${id}`);
120120
container
121121
.querySelectorAll(".djDebugCollapsed")
122122
.forEach(function (e) {
@@ -129,7 +129,7 @@ const djdt = {
129129
});
130130
const self = this;
131131
this.closest(".djDebugPanelContent")
132-
.querySelectorAll(".djToggleDetails_" + id)
132+
.querySelectorAll(`.djToggleDetails_${id}`)
133133
.forEach(function (e) {
134134
if (openMe) {
135135
e.classList.add("djSelected");
@@ -173,7 +173,7 @@ const djdt = {
173173
top = window.innerHeight - handle.offsetHeight;
174174
}
175175

176-
handle.style.top = top + "px";
176+
handle.style.top = `${top}px`;
177177
djdt.handleDragged = true;
178178
}
179179
}
@@ -255,7 +255,7 @@ const djdt = {
255255
localStorage.getItem("djdt.top") || 265,
256256
window.innerHeight - handle.offsetWidth
257257
);
258-
handle.style.top = handleTop + "px";
258+
handle.style.top = `${handleTop}px`;
259259
},
260260
hideToolbar() {
261261
djdt.hidePanels();
@@ -360,15 +360,15 @@ const djdt = {
360360
}
361361

362362
document.cookie = [
363-
encodeURIComponent(key) + "=" + String(value),
363+
`${encodeURIComponent(key)}=${String(value)}`,
364364
options.expires
365-
? "; expires=" + options.expires.toUTCString()
365+
? `; expires=${options.expires.toUTCString()}`
366366
: "",
367-
options.path ? "; path=" + options.path : "",
368-
options.domain ? "; domain=" + options.domain : "",
367+
options.path ? `; path=${options.path}` : "",
368+
options.domain ? `; domain=${options.domain}` : "",
369369
options.secure ? "; secure" : "",
370370
"samesite" in options
371-
? "; samesite=" + options.samesite
371+
? `; samesite=${options.samesite}`
372372
: "; samesite=lax",
373373
].join("");
374374

debug_toolbar/static/debug_toolbar/js/utils.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,18 @@ function ajax(url, init) {
7777
return response.json().catch(function (error) {
7878
return Promise.reject(
7979
new Error(
80-
"The response is a invalid Json object : " + error
80+
`The response is a invalid Json object : ${error}`
8181
)
8282
);
8383
});
8484
}
8585
return Promise.reject(
86-
new Error(response.status + ": " + response.statusText)
86+
new Error(`${response.status}: ${response.statusText}`)
8787
);
8888
})
8989
.catch(function (error) {
9090
const win = document.getElementById("djDebugWindow");
91-
win.innerHTML =
92-
'<div class="djDebugPanelTitle"><button type="button" class="djDebugClose">»</button><h3>' +
93-
error.message +
94-
"</h3></div>";
91+
win.innerHTML = `<div class="djDebugPanelTitle"><button type="button" class="djDebugClose">»</button><h3>${error.message}</h3></div>`;
9592
$$.show(win);
9693
throw error;
9794
});
@@ -118,7 +115,7 @@ function replaceToolbarState(newStoreId, data) {
118115
const panel = document.getElementById(panelId);
119116
if (panel) {
120117
panel.outerHTML = data[panelId].content;
121-
document.getElementById("djdt-" + panelId).outerHTML =
118+
document.getElementById(`djdt-${panelId}`).outerHTML =
122119
data[panelId].button;
123120
}
124121
});

0 commit comments

Comments
 (0)