diff --git a/package.json b/package.json index a4f6e18bcf422..ba7e16ca9abc0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "dependencies": { "browser-ui-test": "^0.24.0", "es-check": "^9.4.4", - "eslint": "^8.57.1", - "typescript": "^5.8.3" + "typescript": "^5.8.3", + "vite-plus": "^0.1.24" } } diff --git a/src/bootstrap/README.md b/src/bootstrap/README.md index ef2de9b37ed0f..86c140aab297b 100644 --- a/src/bootstrap/README.md +++ b/src/bootstrap/README.md @@ -69,7 +69,7 @@ build/ bin/ target/ - # Directory where js dependencies like tsc and eslint are stored. + # Directory where js dependencies like tsc and Vite+ are stored. node_modules/ .bin/ diff --git a/src/doc/rustc-dev-guide/src/rustdoc.md b/src/doc/rustc-dev-guide/src/rustdoc.md index 1259ed10c09bd..f568b3ddbb6c0 100644 --- a/src/doc/rustc-dev-guide/src/rustdoc.md +++ b/src/doc/rustc-dev-guide/src/rustdoc.md @@ -54,12 +54,12 @@ Note that literally all that does is call the `main()` that's in this crate's `l * For frontend debugging, disable the `rust.docs-minification` option in [`bootstrap.toml`]. * Use `./x test tests/rustdoc*` to run the tests using a stage1 rustdoc. * See [Rustdoc internals] for more information about tests. -* Use `./x test tidy --extra-checks=js` to run rustdoc’s JavaScript checks (`eslint`, `es-check`, and `tsc`). +* Use `./x test tidy --extra-checks=js` to run rustdoc’s JavaScript checks (`vp fmt`, `vp lint`, `es-check`, and `tsc`). > **Note:** `./x test tidy` already runs these checks automatically when JS/TS sources changed; `--extra-checks=js` forces them explicitly. ### JavaScript CI checks -Rustdoc’s JavaScript and TypeScript are checked during CI by `eslint`, `es-check`, and `tsc` (not by compiletest). +Rustdoc’s JavaScript and TypeScript are checked during CI by `vp fmt`, `vp lint`, `es-check`, and `tsc` (not by compiletest). These run as part of the `tidy` job. ```console diff --git a/src/librustdoc/html/static/.eslintrc.js b/src/librustdoc/html/static/.eslintrc.js deleted file mode 100644 index 303c5667140cf..0000000000000 --- a/src/librustdoc/html/static/.eslintrc.js +++ /dev/null @@ -1,96 +0,0 @@ -module.exports = { - "env": { - "browser": true, - "es6": true - }, - "extends": "eslint:recommended", - "parserOptions": { - "ecmaVersion": 2019, - "sourceType": "module" - }, - "rules": { - "linebreak-style": [ - "error", - "unix" - ], - "semi": [ - "error", - "always" - ], - "quotes": [ - "error", - "double" - ], - "linebreak-style": [ - "error", - "unix" - ], - "no-trailing-spaces": "error", - "no-var": ["error"], - "prefer-const": ["error"], - "prefer-arrow-callback": ["error"], - "brace-style": [ - "error", - "1tbs", - { "allowSingleLine": false } - ], - "keyword-spacing": [ - "error", - { "before": true, "after": true } - ], - "arrow-spacing": [ - "error", - { "before": true, "after": true } - ], - "key-spacing": [ - "error", - { "beforeColon": false, "afterColon": true, "mode": "strict" } - ], - "func-call-spacing": ["error", "never"], - "space-infix-ops": "error", - "space-before-function-paren": ["error", "never"], - "space-before-blocks": "error", - "comma-dangle": ["error", "always-multiline"], - "comma-style": ["error", "last"], - "max-len": ["error", { "code": 100, "tabWidth": 4 }], - "eol-last": ["error", "always"], - "arrow-parens": ["error", "as-needed"], - "no-unused-vars": [ - "error", - { - "argsIgnorePattern": "^_", - "varsIgnorePattern": "^_" - } - ], - "eqeqeq": "error", - "no-const-assign": "error", - "no-debugger": "error", - "no-dupe-args": "error", - "no-dupe-else-if": "error", - "no-dupe-keys": "error", - "no-duplicate-case": "error", - "no-ex-assign": "error", - "no-fallthrough": "error", - "no-invalid-regexp": "error", - "no-import-assign": "error", - "no-self-compare": "error", - "no-template-curly-in-string": "error", - "block-scoped-var": "error", - "guard-for-in": "error", - "no-alert": "error", - "no-confusing-arrow": "error", - "no-div-regex": "error", - "no-floating-decimal": "error", - "no-implicit-globals": "error", - "no-implied-eval": "error", - "no-label-var": "error", - "no-lonely-if": "error", - "no-mixed-operators": "error", - "no-multi-assign": "error", - "no-return-assign": "error", - "no-script-url": "error", - "no-sequences": "error", - "no-div-regex": "error", - "no-console": "error", - } -}; diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 05bcf50dca0a0..9aa7e936c9af7 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -196,7 +196,7 @@ function preLoadCss(cssUrl) { document.getElementsByTagName("head")[0].appendChild(link); } -(function() { +(function () { const isHelpPage = window.location.pathname.endsWith("/help.html"); /** @@ -320,8 +320,9 @@ function preLoadCss(cssUrl) { if (!container) { return false; } - return !!container.parentElement && container.parentElement.id === - ALTERNATIVE_DISPLAY_ID; + return ( + !!container.parentElement && container.parentElement.id === ALTERNATIVE_DISPLAY_ID + ); }, // Sets the focus on the search bar at the top of the page focus: () => { @@ -353,7 +354,9 @@ function preLoadCss(cssUrl) { const search = window.searchState.containerElement(); switchDisplayedElement(search); const btn = document.querySelector("#search-button a"); - if (browserSupportsHistoryApi() && btn instanceof HTMLAnchorElement && + if ( + browserSupportsHistoryApi() && + btn instanceof HTMLAnchorElement && window.searchState.getQueryStringParams().search === undefined ) { history.pushState(null, "", btn.href); @@ -382,8 +385,10 @@ function preLoadCss(cssUrl) { getQueryStringParams: () => { /** @type {Object.} */ const params = {}; - window.location.search.substring(1).split("&"). - map(s => { + window.location.search + .substring(1) + .split("&") + .map(s => { // https://github.com/rust-lang/rust/issues/119219 const pair = s.split("=").map(x => x.replace(/\+/g, " ")); params[decodeURIComponent(pair[0])] = @@ -507,12 +512,12 @@ function preLoadCss(cssUrl) { }, setLoadingSearch: () => { const search = window.searchState.outputElement(); - nonnull(search).innerHTML = "

" + - window.searchState.loadingText + "

"; + nonnull(search).innerHTML = + '

' + window.searchState.loadingText + "

"; window.searchState.showResults(); }, descShards: new Map(), - loadDesc: async function({descShard, descIndex}) { + loadDesc: async function ({ descShard, descIndex }) { if (descShard.promise === null) { descShard.promise = new Promise((resolve, reject) => { // The `resolve` callback is stored in the `descShard` @@ -522,17 +527,14 @@ function preLoadCss(cssUrl) { descShard.resolve = resolve; const ds = descShard; const fname = `${ds.crate}-desc-${ds.shard}-`; - const url = resourcePath( - `search.desc/${descShard.crate}/${fname}`, - ".js", - ); + const url = resourcePath(`search.desc/${descShard.crate}/${fname}`, ".js"); loadScript(url, reject); }); } const list = await descShard.promise; return list[descIndex]; }, - loadedDescShard: function(crate, shard, data) { + loadedDescShard: function (crate, shard, data) { // If loadedDescShard gets called, then the library must have been declared. // @ts-expect-error this.descShards.get(crate)[shard].resolve(data.split("\n")); @@ -553,8 +555,7 @@ function preLoadCss(cssUrl) { const hash = ev.newURL.slice(ev.newURL.indexOf("#") + 1); if (browserSupportsHistoryApi()) { // `window.location.search`` contains all the query parameters, not just `search`. - history.replaceState(null, "", - getNakedUrl() + window.location.search + "#" + hash); + history.replaceState(null, "", getNakedUrl() + window.location.search + "#" + hash); } const elem = document.getElementById(hash); if (elem) { @@ -585,8 +586,8 @@ function preLoadCss(cssUrl) { if (implElem.id !== implId && (!numbered || numbered[1] !== implId)) { return false; } - return onEachLazy(implElem.parentElement.parentElement.querySelectorAll( - `[id^="${assocId}"]`), + return onEachLazy( + implElem.parentElement.parentElement.querySelectorAll(`[id^="${assocId}"]`), item => { const numbered = /^(.+?)-([0-9]+)$/.exec(item.id); if (item.id === assocId || (numbered && numbered[1] === assocId)) { @@ -654,48 +655,50 @@ function preLoadCss(cssUrl) { return; } - if (document.activeElement && + if ( + document.activeElement && document.activeElement instanceof HTMLInputElement && document.activeElement.type !== "checkbox" && - document.activeElement.type !== "radio") { + document.activeElement.type !== "radio" + ) { switch (getVirtualKey(ev)) { - case "Escape": - handleEscape(ev); - break; + case "Escape": + handleEscape(ev); + break; } } else { switch (getVirtualKey(ev)) { - case "Escape": - handleEscape(ev); - break; - - case "s": - case "S": - case "/": - ev.preventDefault(); - window.searchState.focus(); - break; - - case "+": - case "=": - ev.preventDefault(); - expandAllDocs(); - break; - case "-": - ev.preventDefault(); - collapseAllDocs(false); - break; - case "_": - ev.preventDefault(); - collapseAllDocs(true); - break; - - case "?": - showHelp(); - break; - - default: - break; + case "Escape": + handleEscape(ev); + break; + + case "s": + case "S": + case "/": + ev.preventDefault(); + window.searchState.focus(); + break; + + case "+": + case "=": + ev.preventDefault(); + expandAllDocs(); + break; + case "-": + ev.preventDefault(); + collapseAllDocs(false); + break; + case "_": + ev.preventDefault(); + collapseAllDocs(true); + break; + + case "?": + showHelp(); + break; + + default: + break; } } } @@ -845,8 +848,7 @@ function preLoadCss(cssUrl) { // We don't want to include impls from this JS file, when the HTML already has them. // The current crate should always be ignored. Other crates that should also be // ignored are included in the attribute `data-ignore-extern-crates`. - const script = document - .querySelector("script[data-ignore-extern-crates]"); + const script = document.querySelector("script[data-ignore-extern-crates]"); const ignoreExternCrates = new Set( // @ts-expect-error (script ? script.getAttribute("data-ignore-extern-crates") : "").split(","), @@ -857,8 +859,7 @@ function preLoadCss(cssUrl) { } const structs = imp[lib]; - struct_loop: - for (const struct of structs) { + struct_loop: for (const struct of structs) { const list = struct[SYNTHETIC_IDX] ? syntheticImplementors : implementors; // The types list is only used for synthetic impls. @@ -985,9 +986,9 @@ function preLoadCss(cssUrl) { let outputList = isTrait ? trait_implementations : implementations; if (outputList === null) { const outputListName = isTrait ? "Trait Implementations" : "Implementations"; - const outputListId = isTrait ? - "trait-implementations-list" : - "implementations-list"; + const outputListId = isTrait + ? "trait-implementations-list" + : "implementations-list"; const outputListHeaderId = isTrait ? "trait-implementations" : "implementations"; const outputListHeader = document.createElement("h2"); outputListHeader.id = outputListHeaderId; @@ -1054,8 +1055,10 @@ function preLoadCss(cssUrl) { } idMap.set(el.id, i + 1); }); - const templateAssocItems = template.content.querySelectorAll("section.tymethod, " + - "section.method, section.associatedtype, section.associatedconstant"); + const templateAssocItems = template.content.querySelectorAll( + "section.tymethod, " + + "section.method, section.associatedtype, section.associatedconstant", + ); if (isTrait) { const li = document.createElement("li"); const a = document.createElement("a"); @@ -1066,16 +1069,22 @@ function preLoadCss(cssUrl) { sidebarTraitList.append(li); } else { onEachLazy(templateAssocItems, item => { - let block = hasClass(item, "associatedtype") ? associatedTypes : ( - hasClass(item, "associatedconstant") ? associatedConstants : ( - methods)); + let block = hasClass(item, "associatedtype") + ? associatedTypes + : hasClass(item, "associatedconstant") + ? associatedConstants + : methods; if (!block) { - const blockTitle = hasClass(item, "associatedtype") ? "Associated Types" : ( - hasClass(item, "associatedconstant") ? "Associated Constants" : ( - "Methods")); - const blockClass = hasClass(item, "associatedtype") ? "associatedtype" : ( - hasClass(item, "associatedconstant") ? "associatedconstant" : ( - "method")); + const blockTitle = hasClass(item, "associatedtype") + ? "Associated Types" + : hasClass(item, "associatedconstant") + ? "Associated Constants" + : "Methods"; + const blockClass = hasClass(item, "associatedtype") + ? "associatedtype" + : hasClass(item, "associatedconstant") + ? "associatedconstant" + : "method"; const blockHeader = document.createElement("h3"); const blockLink = document.createElement("a"); blockLink.href = "#implementations"; @@ -1119,9 +1128,7 @@ function preLoadCss(cssUrl) { newChildren.sort((a, b) => { const aI = a.innerText; const bI = b.innerText; - return aI < bI ? -1 : - aI > bI ? 1 : - 0; + return aI < bI ? -1 : aI > bI ? 1 : 0; }); list.replaceChildren(...newChildren); } @@ -1181,9 +1188,10 @@ function preLoadCss(cssUrl) { const innerToggle = document.getElementById(toggleAllDocsId); addClass(innerToggle, "will-expand"); onEachLazy(document.getElementsByClassName("toggle"), e => { - if ((collapseImpls || e.parentNode.id !== "implementations-list") || - (!hasClass(e, "implementors-toggle") && - !hasClass(e, "type-contents-toggle")) + if ( + collapseImpls || + e.parentNode.id !== "implementations-list" || + (!hasClass(e, "implementors-toggle") && !hasClass(e, "type-contents-toggle")) ) { e.open = false; } @@ -1207,7 +1215,7 @@ function preLoadCss(cssUrl) { } } - (function() { + (function () { const toggles = document.getElementById(toggleAllDocsId); if (toggles) { toggles.onclick = toggleAllDocs; @@ -1239,9 +1247,8 @@ function preLoadCss(cssUrl) { if (hideMethodDocs && hasClass(e, "method-toggle")) { e.open = false; } - }); - }()); + })(); window.rustdoc_add_line_numbers_to_examples = () => { // @ts-expect-error @@ -1249,19 +1256,24 @@ function preLoadCss(cssUrl) { return `${nb}`; } - onEachLazy(document.querySelectorAll( - ".rustdoc:not(.src) :not(.scraped-example) > .example-wrap > pre > code", - ), code => { - if (hasClass(code.parentElement.parentElement, "hide-lines")) { - removeClass(code.parentElement.parentElement, "hide-lines"); - return; - } - const lines = code.innerHTML.split("\n"); - const digits = (lines.length + "").length; - // @ts-expect-error - code.innerHTML = lines.map((line, index) => generateLine(index + 1) + line).join("\n"); - addClass(code.parentElement.parentElement, `digits-${digits}`); - }); + onEachLazy( + document.querySelectorAll( + ".rustdoc:not(.src) :not(.scraped-example) > .example-wrap > pre > code", + ), + code => { + if (hasClass(code.parentElement.parentElement, "hide-lines")) { + removeClass(code.parentElement.parentElement, "hide-lines"); + return; + } + const lines = code.innerHTML.split("\n"); + const digits = (lines.length + "").length; + code.innerHTML = lines + // @ts-expect-error + .map((line, index) => generateLine(index + 1) + line) + .join("\n"); + addClass(code.parentElement.parentElement, `digits-${digits}`); + }, + ); }; window.rustdoc_remove_line_numbers_from_examples = () => { @@ -1355,11 +1367,15 @@ function preLoadCss(cssUrl) { // use Object.assign to make sure the object has the correct type // with all of the correct fields before it is assigned to a variable, // as typescript has no way to change the type of a variable once it is initialized. - const wrapper = Object.assign(document.createElement("div"), {TOOLTIP_BASE: e}); + const wrapper = Object.assign(document.createElement("div"), { + TOOLTIP_BASE: e, + }); if (notable_ty) { - wrapper.innerHTML = "
" + + wrapper.innerHTML = + '
' + // @ts-expect-error - window.NOTABLE_TRAITS[notable_ty] + "
"; + window.NOTABLE_TRAITS[notable_ty] + + "
"; } else { // Replace any `title` attribute with `data-title` to avoid double tooltips. const ttl = e.getAttribute("title"); @@ -1383,7 +1399,7 @@ function preLoadCss(cssUrl) { wrapper.appendChild(focusCatcher); const pos = e.getBoundingClientRect(); // 5px overlap so that the mouse can easily travel from place to place - wrapper.style.top = (pos.top + window.scrollY + pos.height) + "px"; + wrapper.style.top = pos.top + window.scrollY + pos.height + "px"; // @ts-expect-error wrapper.style.left = 0; wrapper.style.right = "auto"; @@ -1397,7 +1413,7 @@ function preLoadCss(cssUrl) { } else { wrapper.style.setProperty( "--popover-arrow-offset", - (wrapperPos.right - pos.right + 4) + "px", + wrapperPos.right - pos.right + 4 + "px", ); } wrapper.style.visibility = ""; @@ -1444,18 +1460,23 @@ function preLoadCss(cssUrl) { // To "show" an already visible element, just cancel its timeout. return; } - if (window.CURRENT_TOOLTIP_ELEMENT && - window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE !== element) { + if ( + window.CURRENT_TOOLTIP_ELEMENT && + window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE !== element + ) { // Don't do anything if another tooltip is already visible. return; } - element.TOOLTIP_HOVER_TIMEOUT = setTimeout(() => { - if (show) { - showTooltip(element); - } else if (!element.TOOLTIP_FORCE_VISIBLE) { - hideTooltip(false); - } - }, show ? window.RUSTDOC_TOOLTIP_HOVER_MS : window.RUSTDOC_TOOLTIP_HOVER_EXIT_MS); + element.TOOLTIP_HOVER_TIMEOUT = setTimeout( + () => { + if (show) { + showTooltip(element); + } else if (!element.TOOLTIP_FORCE_VISIBLE) { + hideTooltip(false); + } + }, + show ? window.RUSTDOC_TOOLTIP_HOVER_MS : window.RUSTDOC_TOOLTIP_HOVER_EXIT_MS, + ); } /** @@ -1477,7 +1498,8 @@ function preLoadCss(cssUrl) { * @param {Event & { relatedTarget: Node }} event */ function tooltipBlurHandler(event) { - if (window.CURRENT_TOOLTIP_ELEMENT && + if ( + window.CURRENT_TOOLTIP_ELEMENT && !window.CURRENT_TOOLTIP_ELEMENT.contains(document.activeElement) && !window.CURRENT_TOOLTIP_ELEMENT.contains(event.relatedTarget) && !window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE.contains(document.activeElement) && @@ -1553,8 +1575,11 @@ function preLoadCss(cssUrl) { if (ev.pointerType !== "mouse") { return; } - if (!e.TOOLTIP_FORCE_VISIBLE && window.CURRENT_TOOLTIP_ELEMENT && - !window.CURRENT_TOOLTIP_ELEMENT.contains(ev.relatedTarget)) { + if ( + !e.TOOLTIP_FORCE_VISIBLE && + window.CURRENT_TOOLTIP_ELEMENT && + !window.CURRENT_TOOLTIP_ELEMENT.contains(ev.relatedTarget) + ) { // Tooltip pointer leave gesture: // // Designing a good hover microinteraction is a matter of guessing user @@ -1637,10 +1662,21 @@ function preLoadCss(cssUrl) { // although that would be more correct, // since trait impl blocks are collapsed by - ["_", "Collapse all sections, including impl blocks"], - ].map(x => "
" + - x[0].split(" ") - .map((y, index) => ((index & 1) === 0 ? "" + y + "" : " " + y + " ")) - .join("") + "
" + x[1] + "
").join(""); + ] + .map( + x => + "
" + + x[0] + .split(" ") + .map((y, index) => + (index & 1) === 0 ? "" + y + "" : " " + y + " ", + ) + .join("") + + "
" + + x[1] + + "
", + ) + .join(""); const div_shortcuts = document.createElement("div"); addClass(div_shortcuts, "shortcuts"); div_shortcuts.innerHTML = "

Keyboard Shortcuts

" + shortcuts + "
"; @@ -1655,14 +1691,16 @@ function preLoadCss(cssUrl) { and constant.", "Search functions by type signature (e.g., vec -> usize or \ -> vec or String, enum:Cow -> bool)", - "You can look for items with an exact name by putting double quotes around \ - your request: \"string\"", - `Look for functions that accept or return \ + 'You can look for items with an exact name by putting double quotes around \ + your request: "string"', + `Look for functions that accept or return \ slices and \ arrays by writing square \ brackets (e.g., -> [u8] or [] -> Option)`, "Look for items inside another one by searching for a path: vec::Vec", - ].map(x => "

" + x + "

").join(""); + ] + .map(x => "

" + x + "

") + .join(""); const div_infos = document.createElement("div"); addClass(div_infos, "infos"); div_infos.innerHTML = "

Search Tricks

" + infos; @@ -1762,9 +1800,7 @@ function preLoadCss(cssUrl) { // By default, have help button open docs in a popover. // If user clicks with a moderator, though, use default browser behavior, // probably opening in a new window or tab. - if (event.ctrlKey || - event.altKey || - event.metaKey) { + if (event.ctrlKey || event.altKey || event.metaKey) { return; } event.preventDefault(); @@ -1783,7 +1819,7 @@ function preLoadCss(cssUrl) { onHashChange(null); window.addEventListener("hashchange", onHashChange); window.searchState.setup(); -}()); +})(); // Hide, show, and resize the sidebar // @@ -1797,7 +1833,7 @@ function preLoadCss(cssUrl) { // the size of the sidebar // // [fine precision pointer]: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/pointer -(function() { +(function () { // 100 is the size of the logo // don't let the sidebar get smaller than that, or it'll get squished const SIDEBAR_MIN = 100; @@ -1901,7 +1937,7 @@ function preLoadCss(cssUrl) { // from settings.js, which uses a separate function. It's done here because // the minimum sidebar size is rather uncomfortable, and it must pass // through that size when using the shrink-to-nothing gesture. - const hideSidebar = function() { + const hideSidebar = function () { if (isSrcPage) { window.rustdocCloseSourceSidebar(); updateLocalStorage("src-sidebar-width", null); @@ -1934,7 +1970,7 @@ function preLoadCss(cssUrl) { // the visible range without releasing it. You can, however, grab the // resize handle on a source page with the sidebar closed, because it // remains visible all the time on there. - const showSidebar = function() { + const showSidebar = function () { if (isSrcPage) { window.rustdocShowSourceSidebar(); } else { @@ -1949,7 +1985,7 @@ function preLoadCss(cssUrl) { * * @param {number} size - CSS px width of the sidebar. */ - const changeSidebarSize = function(size) { + const changeSidebarSize = function (size) { if (isSrcPage) { updateLocalStorage("src-sidebar-width", size.toString()); // [RUSTDOCIMPL] CSS variable fast path @@ -1969,10 +2005,10 @@ function preLoadCss(cssUrl) { // Check if the sidebar is hidden. Since src pages and doc pages have // different settings, this function has to check that. - const isSidebarHidden = function() { - return isSrcPage ? - !hasClass(document.documentElement, "src-sidebar-expanded") : - hasClass(document.documentElement, "hide-sidebar"); + const isSidebarHidden = function () { + return isSrcPage + ? !hasClass(document.documentElement, "src-sidebar-expanded") + : hasClass(document.documentElement, "hide-sidebar"); }; /** @@ -1982,7 +2018,7 @@ function preLoadCss(cssUrl) { * * @param {PointerEvent} e */ - const resize = function(e) { + const resize = function (e) { if (currentPointerId === null || currentPointerId !== e.pointerId) { return; } @@ -2020,7 +2056,7 @@ function preLoadCss(cssUrl) { return; } stopResize(); - if (desiredSidebarSize !== null && desiredSidebarSize >= (window.innerWidth - BODY_MIN)) { + if (desiredSidebarSize !== null && desiredSidebarSize >= window.innerWidth - BODY_MIN) { changeSidebarSize(window.innerWidth - BODY_MIN); } else if (desiredSidebarSize !== null && desiredSidebarSize > SIDEBAR_MIN) { changeSidebarSize(desiredSidebarSize); @@ -2030,7 +2066,7 @@ function preLoadCss(cssUrl) { /** * @param {PointerEvent=} e */ - const stopResize = function(e) { + const stopResize = function (e) { if (currentPointerId === null) { return; } @@ -2042,7 +2078,7 @@ function preLoadCss(cssUrl) { window.removeEventListener("pointermove", resize, false); window.removeEventListener("pointerup", stopResize, false); removeClass(document.documentElement, "sidebar-resizing"); - document.documentElement.style.removeProperty( "--resizing-sidebar-width"); + document.documentElement.style.removeProperty("--resizing-sidebar-width"); if (resizer.releasePointerCapture) { resizer.releasePointerCapture(currentPointerId); currentPointerId = null; @@ -2052,7 +2088,7 @@ function preLoadCss(cssUrl) { /** * @param {PointerEvent} e */ - const initResize = function(e) { + const initResize = function (e) { if (currentPointerId !== null || e.altKey || e.ctrlKey || e.metaKey || e.button !== 0) { return; } @@ -2074,15 +2110,15 @@ function preLoadCss(cssUrl) { addClass(resizer, "active"); addClass(document.documentElement, "sidebar-resizing"); const pos = e.clientX - sidebar.offsetLeft - 3; - document.documentElement.style.setProperty( "--resizing-sidebar-width", pos + "px"); + document.documentElement.style.setProperty("--resizing-sidebar-width", pos + "px"); desiredSidebarSize = null; }; resizer.addEventListener("pointerdown", initResize, false); -}()); +})(); // This section handles the copy button that appears next to the path breadcrumbs // and the copy buttons on the code examples. -(function() { +(function () { // Common functions to copy buttons. /** * @param {string|null} content @@ -2179,7 +2215,8 @@ function preLoadCss(cssUrl) { /** @type {HTMLElement|null} */ let elem = target; while (elem !== null && !hasClass(elem, "example-wrap")) { - if (elem === document.body || + if ( + elem === document.body || elem.tagName === "A" || elem.tagName === "BUTTON" || hasClass(elem, "docblock") @@ -2223,8 +2260,11 @@ function preLoadCss(cssUrl) { }); parent.appendChild(copyButton); - if (!elem.parentElement || !elem.parentElement.classList.contains("scraped-example") || - !window.updateScrapedExample) { + if ( + !elem.parentElement || + !elem.parentElement.classList.contains("scraped-example") || + !window.updateScrapedExample + ) { return; } const scrapedWrapped = elem.parentElement; @@ -2256,8 +2296,7 @@ function preLoadCss(cssUrl) { elem.addEventListener("mouseover", addCopyButton); elem.addEventListener("click", showHideCodeExampleButtons); }); -}()); - +})(); // Workaround for browser-specific bugs when copying code snippets. // @@ -2270,7 +2309,7 @@ function preLoadCss(cssUrl) { // with `user-select: none`, causing unwanted line numbers to be copied. // - Chromium issue: https://issues.chromium.org/issues/446539520 // - Rust issue: https://github.com/rust-lang/rust/issues/146816 -(function() { +(function () { document.body.addEventListener("copy", event => { let target = nonnull(event.target); let isInsideCode = false; @@ -2295,4 +2334,4 @@ function preLoadCss(cssUrl) { nonnull(event.clipboardData).setData("text/plain", text); event.preventDefault(); }); -}()); +})(); diff --git a/src/librustdoc/html/static/js/rustdoc.d.ts b/src/librustdoc/html/static/js/rustdoc.d.ts index 230ae4f70e912..3e18b7b400daf 100644 --- a/src/librustdoc/html/static/js/rustdoc.d.ts +++ b/src/librustdoc/html/static/js/rustdoc.d.ts @@ -4,7 +4,7 @@ import { RoaringBitmap } from "./stringdex"; -/* eslint-disable */ +/* oxlint-disable */ declare global { /** Search engine data used by main.js and search.js */ declare var searchState: rustdoc.SearchState; diff --git a/src/librustdoc/html/static/js/scrape-examples.js b/src/librustdoc/html/static/js/scrape-examples.js index eeab591bcd807..a5ed1268788b6 100644 --- a/src/librustdoc/html/static/js/scrape-examples.js +++ b/src/librustdoc/html/static/js/scrape-examples.js @@ -1,8 +1,8 @@ - /* global addClass, hasClass, removeClass, onEachLazy, nonnull */ +/* global addClass, hasClass, removeClass, onEachLazy, nonnull */ "use strict"; -(function() { +(function () { // Number of lines shown when code viewer is not expanded. // DEFAULT is the first example shown by default, while HIDDEN is // the examples hidden beneath the "More examples" toggle. @@ -128,8 +128,7 @@ */ function setupLoc(example, isHidden) { const locs_str = nonnull(example.attributes.getNamedItem("data-locs")).textContent; - const locs = - JSON.parse(nonnull(nonnull(locs_str))); + const locs = JSON.parse(nonnull(nonnull(locs_str))); example.locs = locs; // Start with the first example in view scrollToLoc(example, locs[0][0], isHidden); @@ -147,14 +146,18 @@ }); const moreExamples = toggle.querySelectorAll(".scraped-example"); - toggle.querySelector("summary").addEventListener("click", () => { - // Wrapping in setTimeout ensures the update happens after the elements are actually - // visible. This is necessary since setupLoc calls scrollToLoc which - // depends on offsetHeight, a property that requires an element to be visible to - // compute correctly. - setTimeout(() => { - onEachLazy(moreExamples, el => setupLoc(el, true)); - }); - }, {once: true}); + toggle.querySelector("summary").addEventListener( + "click", + () => { + // Wrapping in setTimeout ensures the update happens after the elements are actually + // visible. This is necessary since setupLoc calls scrollToLoc which + // depends on offsetHeight, a property that requires an element to be visible to + // compute correctly. + setTimeout(() => { + onEachLazy(moreExamples, el => setupLoc(el, true)); + }); + }, + { once: true }, + ); }); })(); diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 117437f9b20bf..2e546b2e80f61 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -5526,7 +5526,6 @@ function updateCrate(ev) { search(true); } -// eslint-disable-next-line max-len // polyfill https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64 /** * @type {function(string): Uint8Array} base64 @@ -5602,6 +5601,5 @@ if (typeof window !== "undefined") { }, }); } else if (typeof exports !== "undefined") { - // eslint-disable-next-line no-undef exports.initSearch = initSearch; } diff --git a/src/librustdoc/html/static/js/settings.js b/src/librustdoc/html/static/js/settings.js index 0bbeb6931e443..1141ffd8290ae 100644 --- a/src/librustdoc/html/static/js/settings.js +++ b/src/librustdoc/html/static/js/settings.js @@ -5,7 +5,7 @@ "use strict"; -(function() { +(function () { const isSettingsPage = window.location.pathname.endsWith("/settings.html"); /** @@ -81,7 +81,7 @@ */ function setEvents(settingsElement) { updateLightAndDark(); - onEachLazy(settingsElement.querySelectorAll("input[type=\"checkbox\"]"), toggle => { + onEachLazy(settingsElement.querySelectorAll('input[type="checkbox"]'), toggle => { const settingId = toggle.id; const settingValue = getSettingValue(settingId); if (settingValue !== null) { @@ -92,7 +92,7 @@ }; }); onEachLazy( - settingsElement.querySelectorAll("input[type=\"radio\"]"), + settingsElement.querySelectorAll('input[type="radio"]'), /** @param {HTMLInputElement} elem */ elem => { const settingId = elem.name; @@ -138,7 +138,7 @@
`; onEach(setting["options"], option => { const checked = option === setting["default"] ? " checked" : ""; - const full = `${js_data_name}-${option.replace(/ /g,"-")}`; + const full = `${js_data_name}-${option.replace(/ /g, "-")}`; output += `\