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 some bugs reported by eslint #81299

Merged
merged 1 commit into from
Jan 26, 2021
Merged
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
50 changes: 22 additions & 28 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// From rust:
/* global ALIASES */

// Local js definitions:
/* global addClass, getCurrentValue, hasClass */
/* global onEachLazy, hasOwnProperty, removeClass, updateLocalStorage */
/* global addClass, getSettingValue, hasClass */
/* global onEach, onEachLazy, hasOwnProperty, removeClass, updateLocalStorage */
/* global hideThemeButtonState, showThemeButtonState */

if (!String.prototype.startsWith) {
Expand Down Expand Up @@ -2214,7 +2211,7 @@ function defocusSearchBar() {
}
}

function toggleAllDocs(pageId, fromAutoCollapse) {
function toggleAllDocs(fromAutoCollapse) {
var innerToggle = document.getElementById(toggleAllDocsId);
if (!innerToggle) {
return;
Expand Down Expand Up @@ -2257,14 +2254,14 @@ function defocusSearchBar() {
}
if (!parent || !superParent || superParent.id !== "main" ||
hasClass(parent, "impl") === false) {
collapseDocs(e, "hide", pageId);
collapseDocs(e, "hide");
}
});
}
}
}

function collapseDocs(toggle, mode, pageId) {
function collapseDocs(toggle, mode) {
if (!toggle || !toggle.parentNode) {
return;
}
Expand Down Expand Up @@ -2384,35 +2381,35 @@ function defocusSearchBar() {
}
}

function collapser(pageId, e, collapse) {
function collapser(e, collapse) {
// inherent impl ids are like "impl" or impl-<number>'.
// they will never be hidden by default.
var n = e.parentElement;
if (n.id.match(/^impl(?:-\d+)?$/) === null) {
// Automatically minimize all non-inherent impls
if (collapse || hasClass(n, "impl")) {
collapseDocs(e, "hide", pageId);
collapseDocs(e, "hide");
}
}
}

function autoCollapse(pageId, collapse) {
function autoCollapse(collapse) {
if (collapse) {
toggleAllDocs(pageId, true);
toggleAllDocs(true);
} else if (getSettingValue("auto-hide-trait-implementations") !== "false") {
var impl_list = document.getElementById("trait-implementations-list");

if (impl_list !== null) {
onEachLazy(impl_list.getElementsByClassName("collapse-toggle"), function(e) {
collapser(pageId, e, collapse);
collapser(e, collapse);
});
}

var blanket_list = document.getElementById("blanket-implementations-list");

if (blanket_list !== null) {
onEachLazy(blanket_list.getElementsByClassName("collapse-toggle"), function(e) {
collapser(pageId, e, collapse);
collapser(e, collapse);
});
}
}
Expand Down Expand Up @@ -2475,7 +2472,6 @@ function defocusSearchBar() {
var toggle = createSimpleToggle(false);
var hideMethodDocs = getSettingValue("auto-hide-method-docs") === "true";
var hideImplementors = getSettingValue("auto-collapse-implementors") !== "false";
var pageId = getPageId();

var func = function(e) {
var next = e.nextElementSibling;
Expand All @@ -2489,7 +2485,7 @@ function defocusSearchBar() {
var newToggle = toggle.cloneNode(true);
insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]);
if (hideMethodDocs === true && hasClass(e, "method") === true) {
collapseDocs(newToggle, "hide", pageId);
collapseDocs(newToggle, "hide");
}
}
};
Expand All @@ -2513,7 +2509,7 @@ function defocusSearchBar() {
// In case the option "auto-collapse implementors" is not set to false, we collapse
// all implementors.
if (hideImplementors === true && e.parentNode.id === "implementors-list") {
collapseDocs(newToggle, "hide", pageId);
collapseDocs(newToggle, "hide");
}
}
};
Expand All @@ -2527,7 +2523,7 @@ function defocusSearchBar() {
if (e.id.match(/^impl(?:-\d+)?$/) === null) {
// Automatically minimize all non-inherent impls
if (hasClass(e, "impl") === true) {
collapseDocs(newToggle, "hide", pageId);
collapseDocs(newToggle, "hide");
}
}
};
Expand Down Expand Up @@ -2562,14 +2558,12 @@ function defocusSearchBar() {
}
onEachLazy(document.getElementsByClassName("impl-items"), function(e) {
onEachLazy(e.getElementsByClassName("associatedconstant"), func);
var hiddenElems = e.getElementsByClassName("hidden");
var needToggle = false;

var needToggle = onEachLazy(e.getElementsByClassName("hidden"), function(hiddenElem) {
if (hasClass(hiddenElem, "content") === false &&
hasClass(hiddenElem, "docblock") === false) {
return true;
}
// We transform the DOM iterator into a vec of DOM elements to prevent performance
// issues on webkit browsers.
var hiddenElems = Array.prototype.slice.call(e.getElementsByClassName("hidden"));
var needToggle = hiddenElems.some(function(hiddenElem) {
return hasClass(hiddenElem, "content") === false &&
hasClass(hiddenElem, "docblock") === false;
});
if (needToggle === true) {
var inner_toggle = newToggle.cloneNode(true);
Expand Down Expand Up @@ -2672,10 +2666,10 @@ function defocusSearchBar() {

onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper);
onEachLazy(document.getElementsByClassName("sub-variant"), buildToggleWrapper);
var pageId = getPageId();

autoCollapse(pageId, getSettingValue("collapse") === "true");
autoCollapse(getSettingValue("collapse") === "true");

var pageId = getPageId();
if (pageId !== null) {
expandSection(pageId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/settings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Local js definitions:
/* global getCurrentValue, getVirtualKey, updateLocalStorage, updateSystemTheme */
/* global getSettingValue, getVirtualKey, onEachLazy, updateLocalStorage, updateSystemTheme */

(function () {
function changeSetting(settingName, value) {
Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/html/static/source-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ function createSidebarToggle() {
return sidebarToggle;
}

// This function is called from "source-files.js", generated in `html/render/mod.rs`.
// eslint-disable-next-line no-unused-vars
function createSourceSidebar() {
if (window.rootPath.endsWith("/") === false) {
window.rootPath += "/";
Expand Down
10 changes: 8 additions & 2 deletions src/librustdoc/html/static/storage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// From rust:
/* global resourcesSuffix, getSettingValue */
/* global resourcesSuffix */

var darkThemes = ["dark", "ayu"];
var currentTheme = document.getElementById("themeStyle");
Expand Down Expand Up @@ -35,17 +35,20 @@ var localStoredTheme = getSettingValue("theme");

var savedHref = [];

// eslint-disable-next-line no-unused-vars
Copy link
Member

Choose a reason for hiding this comment

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

There's no eslint directive to say that these functions are "exported"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Apparently not... :-/

function hasClass(elem, className) {
return elem && elem.classList && elem.classList.contains(className);
}

// eslint-disable-next-line no-unused-vars
function addClass(elem, className) {
if (!elem || !elem.classList) {
return;
}
elem.classList.add(className);
}

// eslint-disable-next-line no-unused-vars
function removeClass(elem, className) {
if (!elem || !elem.classList) {
return;
Expand Down Expand Up @@ -81,6 +84,7 @@ function onEachLazy(lazyArray, func, reversed) {
reversed);
}

// eslint-disable-next-line no-unused-vars
function hasOwnProperty(obj, property) {
return Object.prototype.hasOwnProperty.call(obj, property);
}
Expand Down Expand Up @@ -148,6 +152,8 @@ function switchTheme(styleElem, mainStyleElem, newTheme, saveTheme) {
}
}

// This function is called from "theme.js", generated in `html/render/mod.rs`.
// eslint-disable-next-line no-unused-vars
function useSystemTheme(value) {
if (value === undefined) {
value = true;
Expand All @@ -172,7 +178,7 @@ var updateSystemTheme = (function() {
switchTheme(
currentTheme,
mainTheme,
JSON.parse(cssTheme) || light,
JSON.parse(cssTheme) || "light",
true
);
};
Expand Down