1
Fork 0

Fix eslint errors

This commit is contained in:
Guillaume Gomez 2021-05-14 13:56:15 +02:00
parent 69b352ef77
commit ccabd4eedf
4 changed files with 32 additions and 34 deletions

View file

@ -1,6 +1,6 @@
// Local js definitions: // Local js definitions:
/* global addClass, getSettingValue, hasClass */ /* global addClass, getSettingValue, hasClass, searchState */
/* global onEach, onEachLazy, hasOwnProperty, removeClass, updateLocalStorage */ /* global onEach, onEachLazy, removeClass */
/* global switchTheme, useSystemTheme */ /* global switchTheme, useSystemTheme */
if (!String.prototype.startsWith) { if (!String.prototype.startsWith) {
@ -347,10 +347,6 @@ function hideThemeButtonState() {
document.getElementsByTagName("body")[0].style.marginTop = ""; document.getElementsByTagName("body")[0].style.marginTop = "";
} }
function isHidden(elem) {
return elem.offsetHeight === 0;
}
var toggleAllDocsId = "toggle-all-docs"; var toggleAllDocsId = "toggle-all-docs";
var main = document.getElementById("main"); var main = document.getElementById("main");
var savedHash = ""; var savedHash = "";
@ -553,7 +549,7 @@ function hideThemeButtonState() {
len = window.rootPath.match(/\.\.\//g).length + 1; len = window.rootPath.match(/\.\.\//g).length + 1;
for (i = 0; i < len; ++i) { for (i = 0; i < len; ++i) {
match = url.match(/\/[^\/]*$/); match = url.match(/\/[^/]*$/);
if (i < len - 1) { if (i < len - 1) {
stripped = match[0] + stripped; stripped = match[0] + stripped;
} }
@ -952,13 +948,11 @@ function hideThemeButtonState() {
}); });
var currentType = document.getElementsByClassName("type-decl")[0]; var currentType = document.getElementsByClassName("type-decl")[0];
var className = null;
if (currentType) { if (currentType) {
currentType = currentType.getElementsByClassName("rust")[0]; currentType = currentType.getElementsByClassName("rust")[0];
if (currentType) { if (currentType) {
onEachLazy(currentType.classList, function(item) { onEachLazy(currentType.classList, function(item) {
if (item !== "main") { if (item !== "main") {
className = item;
return true; return true;
} }
}); });
@ -1047,7 +1041,7 @@ function hideThemeButtonState() {
}; };
} }
function buildHelperPopup() { var buildHelperPopup = function() {
var popup = document.createElement("aside"); var popup = document.createElement("aside");
addClass(popup, "hidden"); addClass(popup, "hidden");
popup.id = "help"; popup.id = "help";
@ -1114,7 +1108,7 @@ function hideThemeButtonState() {
insertAfter(popup, searchState.outputElement()); insertAfter(popup, searchState.outputElement());
// So that it's only built once and then it'll do nothing when called! // So that it's only built once and then it'll do nothing when called!
buildHelperPopup = function() {}; buildHelperPopup = function() {};
} };
onHashChange(null); onHashChange(null);
window.addEventListener("hashchange", onHashChange); window.addEventListener("hashchange", onHashChange);

View file

@ -1,3 +1,6 @@
/* global addClass, getNakedUrl, getSettingValue, hasOwnPropertyRustdoc, initSearch, onEach */
/* global onEachLazy, removeClass, searchState, updateLocalStorage */
(function() { (function() {
// This mapping table should match the discriminants of // This mapping table should match the discriminants of
// `rustdoc::html::item_type::ItemType` type in Rust. // `rustdoc::html::item_type::ItemType` type in Rust.
@ -170,7 +173,7 @@ window.initSearch = function(rawSearchIndex) {
function sortResults(results, isType) { function sortResults(results, isType) {
var ar = []; var ar = [];
for (var entry in results) { for (var entry in results) {
if (hasOwnProperty(results, entry)) { if (hasOwnPropertyRustdoc(results, entry)) {
ar.push(results[entry]); ar.push(results[entry]);
} }
} }
@ -254,7 +257,7 @@ window.initSearch = function(rawSearchIndex) {
}); });
for (i = 0, len = results.length; i < len; ++i) { for (i = 0, len = results.length; i < len; ++i) {
var result = results[i]; result = results[i];
// this validation does not make sense when searching by types // this validation does not make sense when searching by types
if (result.dontValidate) { if (result.dontValidate) {
@ -301,7 +304,7 @@ window.initSearch = function(rawSearchIndex) {
if (obj.length > GENERICS_DATA && if (obj.length > GENERICS_DATA &&
obj[GENERICS_DATA].length >= val.generics.length) { obj[GENERICS_DATA].length >= val.generics.length) {
var elems = Object.create(null); var elems = Object.create(null);
var elength = object[GENERICS_DATA].length; var elength = obj[GENERICS_DATA].length;
for (var x = 0; x < elength; ++x) { for (var x = 0; x < elength; ++x) {
elems[getObjectNameFromId(obj[GENERICS_DATA][x])] += 1; elems[getObjectNameFromId(obj[GENERICS_DATA][x])] += 1;
} }
@ -717,7 +720,7 @@ window.initSearch = function(rawSearchIndex) {
query.output = val; query.output = val;
query.search = val; query.search = val;
// gather matching search results up to a certain maximum // gather matching search results up to a certain maximum
val = val.replace(/\_/g, ""); val = val.replace(/_/g, "");
var valGenerics = extractGenerics(val); var valGenerics = extractGenerics(val);
@ -1242,7 +1245,9 @@ window.initSearch = function(rawSearchIndex) {
function getFilterCrates() { function getFilterCrates() {
var elem = document.getElementById("crate-search"); var elem = document.getElementById("crate-search");
if (elem && elem.value !== "All crates" && hasOwnProperty(rawSearchIndex, elem.value)) { if (elem && elem.value !== "All crates" &&
hasOwnPropertyRustdoc(rawSearchIndex, elem.value))
{
return elem.value; return elem.value;
} }
return undefined; return undefined;
@ -1293,14 +1298,13 @@ window.initSearch = function(rawSearchIndex) {
var id = 0; var id = 0;
for (var crate in rawSearchIndex) { for (var crate in rawSearchIndex) {
if (!hasOwnProperty(rawSearchIndex, crate)) { continue; } if (!hasOwnPropertyRustdoc(rawSearchIndex, crate)) {
continue;
}
var crateSize = 0; var crateSize = 0;
searchWords.push(crate); searchWords.push(crate);
var normalizedName = crate.indexOf("_") === -1
? crate
: crate.replace(/_/g, "");
// This object should have exactly the same set of fields as the "row" // This object should have exactly the same set of fields as the "row"
// object defined below. Your JavaScript runtime will thank you. // object defined below. Your JavaScript runtime will thank you.
// https://mathiasbynens.be/notes/shapes-ics // https://mathiasbynens.be/notes/shapes-ics
@ -1313,7 +1317,7 @@ window.initSearch = function(rawSearchIndex) {
parent: undefined, parent: undefined,
type: null, type: null,
id: id, id: id,
normalizedName: normalizedName, normalizedName: crate.indexOf("_") === -1 ? crate : crate.replace(/_/g, ""),
}; };
id += 1; id += 1;
searchIndex.push(crateRow); searchIndex.push(crateRow);
@ -1363,9 +1367,6 @@ window.initSearch = function(rawSearchIndex) {
word = ""; word = "";
searchWords.push(""); searchWords.push("");
} }
var normalizedName = word.indexOf("_") === -1
? word
: word.replace(/_/g, "");
var row = { var row = {
crate: crate, crate: crate,
ty: itemTypes[i], ty: itemTypes[i],
@ -1375,7 +1376,7 @@ window.initSearch = function(rawSearchIndex) {
parent: itemParentIdxs[i] > 0 ? paths[itemParentIdxs[i] - 1] : undefined, parent: itemParentIdxs[i] > 0 ? paths[itemParentIdxs[i] - 1] : undefined,
type: itemFunctionSearchTypes[i], type: itemFunctionSearchTypes[i],
id: id, id: id,
normalizedName: normalizedName, normalizedName: word.indexOf("_") === -1 ? word : word.replace(/_/g, ""),
}; };
id += 1; id += 1;
searchIndex.push(row); searchIndex.push(row);
@ -1387,9 +1388,11 @@ window.initSearch = function(rawSearchIndex) {
ALIASES[crate] = {}; ALIASES[crate] = {};
var j, local_aliases; var j, local_aliases;
for (var alias_name in aliases) { for (var alias_name in aliases) {
if (!aliases.hasOwnProperty(alias_name)) { continue; } if (!hasOwnPropertyRustdoc(aliases, alias_name)) {
continue;
}
if (!ALIASES[crate].hasOwnProperty(alias_name)) { if (!hasOwnPropertyRustdoc(ALIASES[crate], alias_name)) {
ALIASES[crate][alias_name] = []; ALIASES[crate][alias_name] = [];
} }
local_aliases = aliases[alias_name]; local_aliases = aliases[alias_name];

View file

@ -2,7 +2,8 @@
/* global search, sourcesIndex */ /* global search, sourcesIndex */
// Local js definitions: // Local js definitions:
/* global addClass, getCurrentValue, hasClass, removeClass, updateLocalStorage */ /* global addClass, getCurrentValue, hasClass, onEachLazy, removeClass, searchState */
/* global updateLocalStorage */
(function() { (function() {
function getCurrentFilePath() { function getCurrentFilePath() {
@ -153,7 +154,7 @@ function createSourceSidebar() {
var lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/; var lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/;
function highlightSourceLines(match, ev) { function highlightSourceLines(scrollTo, match) {
if (typeof match === "undefined") { if (typeof match === "undefined") {
match = window.location.hash.match(lineNumbersRegex); match = window.location.hash.match(lineNumbersRegex);
} }
@ -174,7 +175,7 @@ function highlightSourceLines(match, ev) {
if (!elem) { if (!elem) {
return; return;
} }
if (!ev) { if (scrollTo) {
var x = document.getElementById(from); var x = document.getElementById(from);
if (x) { if (x) {
x.scrollIntoView(); x.scrollIntoView();
@ -202,7 +203,7 @@ var handleSourceHighlight = (function() {
y = window.scrollY; y = window.scrollY;
if (searchState.browserSupportsHistoryApi()) { if (searchState.browserSupportsHistoryApi()) {
history.replaceState(null, null, "#" + name); history.replaceState(null, null, "#" + name);
highlightSourceLines(); highlightSourceLines(true);
} else { } else {
location.replace("#" + name); location.replace("#" + name);
} }
@ -234,7 +235,7 @@ var handleSourceHighlight = (function() {
window.addEventListener("hashchange", function() { window.addEventListener("hashchange", function() {
var match = window.location.hash.match(lineNumbersRegex); var match = window.location.hash.match(lineNumbersRegex);
if (match) { if (match) {
return highlightSourceLines(match, ev); return highlightSourceLines(false, match);
} }
}); });
@ -242,7 +243,7 @@ onEachLazy(document.getElementsByClassName("line-numbers"), function(el) {
el.addEventListener("click", handleSourceHighlight); el.addEventListener("click", handleSourceHighlight);
}); });
highlightSourceLines(); highlightSourceLines(true);
window.createSourceSidebar = createSourceSidebar; window.createSourceSidebar = createSourceSidebar;
})(); })();

View file

@ -84,7 +84,7 @@ function onEachLazy(lazyArray, func, reversed) {
} }
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
function hasOwnProperty(obj, property) { function hasOwnPropertyRustdoc(obj, property) {
return Object.prototype.hasOwnProperty.call(obj, property); return Object.prototype.hasOwnProperty.call(obj, property);
} }