Skip to content

Commit 46bc552

Browse files
Rollup merge of #85323 - GuillaumeGomez:fix-eslint-errors, r=jsha
Fix eslint errors I cherry-picked the two non-CI commits from #85285. r? ```@jsha```
2 parents 2b5ef25 + 18b7c0a commit 46bc552

File tree

5 files changed

+34
-35
lines changed

5 files changed

+34
-35
lines changed

src/librustdoc/html/static/main.js

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Local js definitions:
2-
/* global addClass, getSettingValue, hasClass */
3-
/* global onEach, onEachLazy, hasOwnProperty, removeClass, updateLocalStorage */
2+
/* global addClass, getSettingValue, hasClass, searchState */
3+
/* global onEach, onEachLazy, removeClass */
44
/* global switchTheme, useSystemTheme */
55

66
if (!String.prototype.startsWith) {
@@ -347,10 +347,6 @@ function hideThemeButtonState() {
347347
document.getElementsByTagName("body")[0].style.marginTop = "";
348348
}
349349

350-
function isHidden(elem) {
351-
return elem.offsetHeight === 0;
352-
}
353-
354350
var toggleAllDocsId = "toggle-all-docs";
355351
var main = document.getElementById("main");
356352
var savedHash = "";
@@ -553,7 +549,7 @@ function hideThemeButtonState() {
553549
len = window.rootPath.match(/\.\.\//g).length + 1;
554550

555551
for (i = 0; i < len; ++i) {
556-
match = url.match(/\/[^\/]*$/);
552+
match = url.match(/\/[^/]*$/);
557553
if (i < len - 1) {
558554
stripped = match[0] + stripped;
559555
}
@@ -952,13 +948,11 @@ function hideThemeButtonState() {
952948
});
953949

954950
var currentType = document.getElementsByClassName("type-decl")[0];
955-
var className = null;
956951
if (currentType) {
957952
currentType = currentType.getElementsByClassName("rust")[0];
958953
if (currentType) {
959954
onEachLazy(currentType.classList, function(item) {
960955
if (item !== "main") {
961-
className = item;
962956
return true;
963957
}
964958
});
@@ -1047,7 +1041,7 @@ function hideThemeButtonState() {
10471041
};
10481042
}
10491043

1050-
function buildHelperPopup() {
1044+
var buildHelperPopup = function() {
10511045
var popup = document.createElement("aside");
10521046
addClass(popup, "hidden");
10531047
popup.id = "help";
@@ -1114,7 +1108,7 @@ function hideThemeButtonState() {
11141108
insertAfter(popup, searchState.outputElement());
11151109
// So that it's only built once and then it'll do nothing when called!
11161110
buildHelperPopup = function() {};
1117-
}
1111+
};
11181112

11191113
onHashChange(null);
11201114
window.addEventListener("hashchange", onHashChange);

src/librustdoc/html/static/search.js

+19-16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* global addClass, getNakedUrl, getSettingValue, hasOwnPropertyRustdoc, initSearch, onEach */
2+
/* global onEachLazy, removeClass, searchState, updateLocalStorage */
3+
14
(function() {
25
// This mapping table should match the discriminants of
36
// `rustdoc::html::item_type::ItemType` type in Rust.
@@ -170,7 +173,7 @@ window.initSearch = function(rawSearchIndex) {
170173
function sortResults(results, isType) {
171174
var ar = [];
172175
for (var entry in results) {
173-
if (hasOwnProperty(results, entry)) {
176+
if (hasOwnPropertyRustdoc(results, entry)) {
174177
ar.push(results[entry]);
175178
}
176179
}
@@ -254,7 +257,7 @@ window.initSearch = function(rawSearchIndex) {
254257
});
255258

256259
for (i = 0, len = results.length; i < len; ++i) {
257-
var result = results[i];
260+
result = results[i];
258261

259262
// this validation does not make sense when searching by types
260263
if (result.dontValidate) {
@@ -301,7 +304,7 @@ window.initSearch = function(rawSearchIndex) {
301304
if (obj.length > GENERICS_DATA &&
302305
obj[GENERICS_DATA].length >= val.generics.length) {
303306
var elems = Object.create(null);
304-
var elength = object[GENERICS_DATA].length;
307+
var elength = obj[GENERICS_DATA].length;
305308
for (var x = 0; x < elength; ++x) {
306309
elems[getObjectNameFromId(obj[GENERICS_DATA][x])] += 1;
307310
}
@@ -717,7 +720,7 @@ window.initSearch = function(rawSearchIndex) {
717720
query.output = val;
718721
query.search = val;
719722
// gather matching search results up to a certain maximum
720-
val = val.replace(/\_/g, "");
723+
val = val.replace(/_/g, "");
721724

722725
var valGenerics = extractGenerics(val);
723726

@@ -1242,7 +1245,9 @@ window.initSearch = function(rawSearchIndex) {
12421245
function getFilterCrates() {
12431246
var elem = document.getElementById("crate-search");
12441247

1245-
if (elem && elem.value !== "All crates" && hasOwnProperty(rawSearchIndex, elem.value)) {
1248+
if (elem && elem.value !== "All crates" &&
1249+
hasOwnPropertyRustdoc(rawSearchIndex, elem.value))
1250+
{
12461251
return elem.value;
12471252
}
12481253
return undefined;
@@ -1293,14 +1298,13 @@ window.initSearch = function(rawSearchIndex) {
12931298
var id = 0;
12941299

12951300
for (var crate in rawSearchIndex) {
1296-
if (!hasOwnProperty(rawSearchIndex, crate)) { continue; }
1301+
if (!hasOwnPropertyRustdoc(rawSearchIndex, crate)) {
1302+
continue;
1303+
}
12971304

12981305
var crateSize = 0;
12991306

13001307
searchWords.push(crate);
1301-
var normalizedName = crate.indexOf("_") === -1
1302-
? crate
1303-
: crate.replace(/_/g, "");
13041308
// This object should have exactly the same set of fields as the "row"
13051309
// object defined below. Your JavaScript runtime will thank you.
13061310
// https://mathiasbynens.be/notes/shapes-ics
@@ -1313,7 +1317,7 @@ window.initSearch = function(rawSearchIndex) {
13131317
parent: undefined,
13141318
type: null,
13151319
id: id,
1316-
normalizedName: normalizedName,
1320+
normalizedName: crate.indexOf("_") === -1 ? crate : crate.replace(/_/g, ""),
13171321
};
13181322
id += 1;
13191323
searchIndex.push(crateRow);
@@ -1363,9 +1367,6 @@ window.initSearch = function(rawSearchIndex) {
13631367
word = "";
13641368
searchWords.push("");
13651369
}
1366-
var normalizedName = word.indexOf("_") === -1
1367-
? word
1368-
: word.replace(/_/g, "");
13691370
var row = {
13701371
crate: crate,
13711372
ty: itemTypes[i],
@@ -1375,7 +1376,7 @@ window.initSearch = function(rawSearchIndex) {
13751376
parent: itemParentIdxs[i] > 0 ? paths[itemParentIdxs[i] - 1] : undefined,
13761377
type: itemFunctionSearchTypes[i],
13771378
id: id,
1378-
normalizedName: normalizedName,
1379+
normalizedName: word.indexOf("_") === -1 ? word : word.replace(/_/g, ""),
13791380
};
13801381
id += 1;
13811382
searchIndex.push(row);
@@ -1387,9 +1388,11 @@ window.initSearch = function(rawSearchIndex) {
13871388
ALIASES[crate] = {};
13881389
var j, local_aliases;
13891390
for (var alias_name in aliases) {
1390-
if (!aliases.hasOwnProperty(alias_name)) { continue; }
1391+
if (!hasOwnPropertyRustdoc(aliases, alias_name)) {
1392+
continue;
1393+
}
13911394

1392-
if (!ALIASES[crate].hasOwnProperty(alias_name)) {
1395+
if (!hasOwnPropertyRustdoc(ALIASES[crate], alias_name)) {
13931396
ALIASES[crate][alias_name] = [];
13941397
}
13951398
local_aliases = aliases[alias_name];

src/librustdoc/html/static/source-script.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
/* global search, sourcesIndex */
33

44
// Local js definitions:
5-
/* global addClass, getCurrentValue, hasClass, removeClass, updateLocalStorage */
5+
/* global addClass, getCurrentValue, hasClass, onEachLazy, removeClass, searchState */
6+
/* global updateLocalStorage */
67
(function() {
78

89
function getCurrentFilePath() {
@@ -153,7 +154,7 @@ function createSourceSidebar() {
153154

154155
var lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/;
155156

156-
function highlightSourceLines(match, ev) {
157+
function highlightSourceLines(scrollTo, match) {
157158
if (typeof match === "undefined") {
158159
match = window.location.hash.match(lineNumbersRegex);
159160
}
@@ -174,7 +175,7 @@ function highlightSourceLines(match, ev) {
174175
if (!elem) {
175176
return;
176177
}
177-
if (!ev) {
178+
if (scrollTo) {
178179
var x = document.getElementById(from);
179180
if (x) {
180181
x.scrollIntoView();
@@ -202,7 +203,7 @@ var handleSourceHighlight = (function() {
202203
y = window.scrollY;
203204
if (searchState.browserSupportsHistoryApi()) {
204205
history.replaceState(null, null, "#" + name);
205-
highlightSourceLines();
206+
highlightSourceLines(true);
206207
} else {
207208
location.replace("#" + name);
208209
}
@@ -234,15 +235,15 @@ var handleSourceHighlight = (function() {
234235
window.addEventListener("hashchange", function() {
235236
var match = window.location.hash.match(lineNumbersRegex);
236237
if (match) {
237-
return highlightSourceLines(match, ev);
238+
return highlightSourceLines(false, match);
238239
}
239240
});
240241

241242
onEachLazy(document.getElementsByClassName("line-numbers"), function(el) {
242243
el.addEventListener("click", handleSourceHighlight);
243244
});
244245

245-
highlightSourceLines();
246+
highlightSourceLines(true);
246247

247248
window.createSourceSidebar = createSourceSidebar;
248249
})();

src/librustdoc/html/static/storage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function onEachLazy(lazyArray, func, reversed) {
8484
}
8585

8686
// eslint-disable-next-line no-unused-vars
87-
function hasOwnProperty(obj, property) {
87+
function hasOwnPropertyRustdoc(obj, property) {
8888
return Object.prototype.hasOwnProperty.call(obj, property);
8989
}
9090

src/tools/rustdoc-js/tester.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,10 @@ function loadSearchJsAndIndex(searchJs, searchIndex, storageJs, crate) {
267267
"handleAliases", "getQuery", "buildIndex", "execQuery", "execSearch",
268268
"removeEmptyStringsFromArray"];
269269

270+
const functions = ["hasOwnPropertyRustdoc", "onEach"];
270271
ALIASES = {};
271272
finalJS += 'window = { "currentCrate": "' + crate + '", rootPath: "../" };\n';
272-
finalJS += loadThings(["hasOwnProperty", "onEach"], 'function', extractFunction, storageJs);
273+
finalJS += loadThings(functions, 'function', extractFunction, storageJs);
273274
finalJS += loadThings(arraysToLoad, 'array', extractArrayVariable, searchJs);
274275
finalJS += loadThings(variablesToLoad, 'variable', extractVariable, searchJs);
275276
finalJS += loadThings(functionsToLoad, 'function', extractFunction, searchJs);

0 commit comments

Comments
 (0)