Skip to content

Commit cefa31a

Browse files
committed
Auto merge of rust-lang#13588 - GuillaumeGomez:fix-lint-anchor, r=flip1995
Fix not working lint anchor (generation and filtering) As spotted by `@flip1995,` the anchor button is currently not working. Problem was the JS that was preventing the web browser from adding the hash at the end of the URL. For the second bug fixed, the JS was stripping two characters instead of just stripping the `#` at the beginning. changelog: Fix clippy page lint anchor (generation and filtering) r? `@flip1995`
2 parents 5873cb9 + 7115404 commit cefa31a

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

util/gh-pages/index_template.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ <h1>Clippy Lints</h1> {# #}
150150
<h2 class="panel-title"> {# #}
151151
<div class="panel-title-name" id="lint-{{lint.id}}"> {# #}
152152
<span>{{lint.id}}</span> {#+ #}
153-
<a href="#{{lint.id}}" class="anchor label label-default" onclick="openLint(event)">&para;</a> {#+ #}
153+
<a href="#{{lint.id}}" onclick="lintAnchor(event)" class="anchor label label-default">&para;</a> {#+ #}
154154
<a href="" class="anchor label label-default" onclick="copyToClipboard(event)"> {# #}
155155
&#128203; {# #}
156156
</a> {# #}

util/gh-pages/script.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,14 @@ function expandLint(lintId) {
151151
highlightIfNeeded(lintId);
152152
}
153153

154-
// Show details for one lint
155-
function openLint(event) {
154+
function lintAnchor(event) {
156155
event.preventDefault();
157156
event.stopPropagation();
158-
expandLint(event.target.getAttribute("href").slice(1));
157+
158+
const id = event.target.getAttribute("href").replace("#", "");
159+
window.location.hash = id;
160+
161+
expandLint(id);
159162
}
160163

161164
function copyToClipboard(event) {
@@ -519,7 +522,7 @@ function scrollToLint(lintId) {
519522

520523
// If the page we arrive on has link to a given lint, we scroll to it.
521524
function scrollToLintByURL() {
522-
const lintId = window.location.hash.substring(2);
525+
const lintId = window.location.hash.substring(1);
523526
if (lintId.length > 0) {
524527
scrollToLint(lintId);
525528
}

0 commit comments

Comments
 (0)