Skip to content

Commit

Permalink
Rollup merge of #85323 - GuillaumeGomez:fix-eslint-errors, r=jsha
Browse files Browse the repository at this point in the history
Fix eslint errors

I cherry-picked the two non-CI commits from #85285.

r? `@jsha`
  • Loading branch information
GuillaumeGomez committed May 15, 2021
2 parents 8f0ea10 + 18b7c0a commit 53c9f91
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 35 deletions.
16 changes: 5 additions & 11 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Local js definitions:
/* global addClass, getSettingValue, hasClass */
/* global onEach, onEachLazy, hasOwnProperty, removeClass, updateLocalStorage */
/* global addClass, getSettingValue, hasClass, searchState */
/* global onEach, onEachLazy, removeClass */
/* global switchTheme, useSystemTheme */

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

function isHidden(elem) {
return elem.offsetHeight === 0;
}

var toggleAllDocsId = "toggle-all-docs";
var main = document.getElementById("main");
var savedHash = "";
Expand Down Expand Up @@ -553,7 +549,7 @@ function hideThemeButtonState() {
len = window.rootPath.match(/\.\.\//g).length + 1;

for (i = 0; i < len; ++i) {
match = url.match(/\/[^\/]*$/);
match = url.match(/\/[^/]*$/);
if (i < len - 1) {
stripped = match[0] + stripped;
}
Expand Down Expand Up @@ -952,13 +948,11 @@ function hideThemeButtonState() {
});

var currentType = document.getElementsByClassName("type-decl")[0];
var className = null;
if (currentType) {
currentType = currentType.getElementsByClassName("rust")[0];
if (currentType) {
onEachLazy(currentType.classList, function(item) {
if (item !== "main") {
className = item;
return true;
}
});
Expand Down Expand Up @@ -1047,7 +1041,7 @@ function hideThemeButtonState() {
};
}

function buildHelperPopup() {
var buildHelperPopup = function() {
var popup = document.createElement("aside");
addClass(popup, "hidden");
popup.id = "help";
Expand Down Expand Up @@ -1114,7 +1108,7 @@ function hideThemeButtonState() {
insertAfter(popup, searchState.outputElement());
// So that it's only built once and then it'll do nothing when called!
buildHelperPopup = function() {};
}
};

onHashChange(null);
window.addEventListener("hashchange", onHashChange);
Expand Down
35 changes: 19 additions & 16 deletions src/librustdoc/html/static/search.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* global addClass, getNakedUrl, getSettingValue, hasOwnPropertyRustdoc, initSearch, onEach */
/* global onEachLazy, removeClass, searchState, updateLocalStorage */

(function() {
// This mapping table should match the discriminants of
// `rustdoc::html::item_type::ItemType` type in Rust.
Expand Down Expand Up @@ -170,7 +173,7 @@ window.initSearch = function(rawSearchIndex) {
function sortResults(results, isType) {
var ar = [];
for (var entry in results) {
if (hasOwnProperty(results, entry)) {
if (hasOwnPropertyRustdoc(results, entry)) {
ar.push(results[entry]);
}
}
Expand Down Expand Up @@ -254,7 +257,7 @@ window.initSearch = function(rawSearchIndex) {
});

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
if (result.dontValidate) {
Expand Down Expand Up @@ -301,7 +304,7 @@ window.initSearch = function(rawSearchIndex) {
if (obj.length > GENERICS_DATA &&
obj[GENERICS_DATA].length >= val.generics.length) {
var elems = Object.create(null);
var elength = object[GENERICS_DATA].length;
var elength = obj[GENERICS_DATA].length;
for (var x = 0; x < elength; ++x) {
elems[getObjectNameFromId(obj[GENERICS_DATA][x])] += 1;
}
Expand Down Expand Up @@ -717,7 +720,7 @@ window.initSearch = function(rawSearchIndex) {
query.output = val;
query.search = val;
// gather matching search results up to a certain maximum
val = val.replace(/\_/g, "");
val = val.replace(/_/g, "");

var valGenerics = extractGenerics(val);

Expand Down Expand Up @@ -1242,7 +1245,9 @@ window.initSearch = function(rawSearchIndex) {
function getFilterCrates() {
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 undefined;
Expand Down Expand Up @@ -1293,14 +1298,13 @@ window.initSearch = function(rawSearchIndex) {
var id = 0;

for (var crate in rawSearchIndex) {
if (!hasOwnProperty(rawSearchIndex, crate)) { continue; }
if (!hasOwnPropertyRustdoc(rawSearchIndex, crate)) {
continue;
}

var crateSize = 0;

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"
// object defined below. Your JavaScript runtime will thank you.
// https://mathiasbynens.be/notes/shapes-ics
Expand All @@ -1313,7 +1317,7 @@ window.initSearch = function(rawSearchIndex) {
parent: undefined,
type: null,
id: id,
normalizedName: normalizedName,
normalizedName: crate.indexOf("_") === -1 ? crate : crate.replace(/_/g, ""),
};
id += 1;
searchIndex.push(crateRow);
Expand Down Expand Up @@ -1363,9 +1367,6 @@ window.initSearch = function(rawSearchIndex) {
word = "";
searchWords.push("");
}
var normalizedName = word.indexOf("_") === -1
? word
: word.replace(/_/g, "");
var row = {
crate: crate,
ty: itemTypes[i],
Expand All @@ -1375,7 +1376,7 @@ window.initSearch = function(rawSearchIndex) {
parent: itemParentIdxs[i] > 0 ? paths[itemParentIdxs[i] - 1] : undefined,
type: itemFunctionSearchTypes[i],
id: id,
normalizedName: normalizedName,
normalizedName: word.indexOf("_") === -1 ? word : word.replace(/_/g, ""),
};
id += 1;
searchIndex.push(row);
Expand All @@ -1387,9 +1388,11 @@ window.initSearch = function(rawSearchIndex) {
ALIASES[crate] = {};
var j, local_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] = [];
}
local_aliases = aliases[alias_name];
Expand Down
13 changes: 7 additions & 6 deletions src/librustdoc/html/static/source-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/* global search, sourcesIndex */

// Local js definitions:
/* global addClass, getCurrentValue, hasClass, removeClass, updateLocalStorage */
/* global addClass, getCurrentValue, hasClass, onEachLazy, removeClass, searchState */
/* global updateLocalStorage */
(function() {

function getCurrentFilePath() {
Expand Down Expand Up @@ -153,7 +154,7 @@ function createSourceSidebar() {

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

function highlightSourceLines(match, ev) {
function highlightSourceLines(scrollTo, match) {
if (typeof match === "undefined") {
match = window.location.hash.match(lineNumbersRegex);
}
Expand All @@ -174,7 +175,7 @@ function highlightSourceLines(match, ev) {
if (!elem) {
return;
}
if (!ev) {
if (scrollTo) {
var x = document.getElementById(from);
if (x) {
x.scrollIntoView();
Expand Down Expand Up @@ -202,7 +203,7 @@ var handleSourceHighlight = (function() {
y = window.scrollY;
if (searchState.browserSupportsHistoryApi()) {
history.replaceState(null, null, "#" + name);
highlightSourceLines();
highlightSourceLines(true);
} else {
location.replace("#" + name);
}
Expand Down Expand Up @@ -234,15 +235,15 @@ var handleSourceHighlight = (function() {
window.addEventListener("hashchange", function() {
var match = window.location.hash.match(lineNumbersRegex);
if (match) {
return highlightSourceLines(match, ev);
return highlightSourceLines(false, match);
}
});

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

highlightSourceLines();
highlightSourceLines(true);

window.createSourceSidebar = createSourceSidebar;
})();
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function onEachLazy(lazyArray, func, reversed) {
}

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

Expand Down
3 changes: 2 additions & 1 deletion src/tools/rustdoc-js/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,10 @@ function loadSearchJsAndIndex(searchJs, searchIndex, storageJs, crate) {
"handleAliases", "getQuery", "buildIndex", "execQuery", "execSearch",
"removeEmptyStringsFromArray"];

const functions = ["hasOwnPropertyRustdoc", "onEach"];
ALIASES = {};
finalJS += 'window = { "currentCrate": "' + crate + '", rootPath: "../" };\n';
finalJS += loadThings(["hasOwnProperty", "onEach"], 'function', extractFunction, storageJs);
finalJS += loadThings(functions, 'function', extractFunction, storageJs);
finalJS += loadThings(arraysToLoad, 'array', extractArrayVariable, searchJs);
finalJS += loadThings(variablesToLoad, 'variable', extractVariable, searchJs);
finalJS += loadThings(functionsToLoad, 'function', extractFunction, searchJs);
Expand Down

0 comments on commit 53c9f91

Please sign in to comment.