Skip to content

Commit 5342092

Browse files
committed
Auto merge of #13179 - GuillaumeGomez:clean-up-lints-page-js, r=Alexendoo
Clean up clippy lints page JS source code Just a small cleanup for the lints page JS source code. r? `@Alexendoo` changelog: Clean up clippy lints page JS source code
2 parents 3b64ca9 + 957a301 commit 5342092

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

util/gh-pages/script.js

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(function () {
2-
var md = window.markdownit({
2+
const md = window.markdownit({
33
html: true,
44
linkify: true,
55
typographer: true,
@@ -17,29 +17,25 @@
1717
});
1818

1919
function scrollToLint(lintId) {
20-
var target = document.getElementById(lintId);
20+
const target = document.getElementById(lintId);
2121
if (!target) {
2222
return;
2323
}
2424
target.scrollIntoView();
2525
}
2626

2727
function scrollToLintByURL($scope, $location) {
28-
var removeListener = $scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) {
28+
const removeListener = $scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) {
2929
scrollToLint($location.path().substring(1));
3030
removeListener();
3131
});
3232
}
3333

3434
function selectGroup($scope, selectedGroup) {
35-
var groups = $scope.groups;
36-
for (var group in groups) {
35+
const groups = $scope.groups;
36+
for (const group in groups) {
3737
if (groups.hasOwnProperty(group)) {
38-
if (group === selectedGroup) {
39-
groups[group] = true;
40-
} else {
41-
groups[group] = false;
42-
}
38+
groups[group] = group === selectedGroup;
4339
}
4440
}
4541
}
@@ -108,7 +104,7 @@
108104
})
109105
.controller("lintList", function ($scope, $http, $location, $timeout) {
110106
// Level filter
111-
var LEVEL_FILTERS_DEFAULT = {allow: true, warn: true, deny: true, none: true};
107+
const LEVEL_FILTERS_DEFAULT = {allow: true, warn: true, deny: true, none: true};
112108
$scope.levels = { ...LEVEL_FILTERS_DEFAULT };
113109
$scope.byLevels = function (lint) {
114110
return $scope.levels[lint.level];
@@ -367,7 +363,7 @@
367363
}
368364

369365
$scope.clearVersionFilters = function () {
370-
for (let filter in $scope.versionFilters) {
366+
for (const filter in $scope.versionFilters) {
371367
$scope.versionFilters[filter] = { enabled: false, minorVersion: null };
372368
}
373369
}
@@ -378,7 +374,7 @@
378374

379375
$scope.updateVersionFilters = function() {
380376
for (const filter in $scope.versionFilters) {
381-
let minorVersion = $scope.versionFilters[filter].minorVersion;
377+
const minorVersion = $scope.versionFilters[filter].minorVersion;
382378

383379
// 1.29.0 and greater
384380
if (minorVersion && minorVersion > 28) {
@@ -391,14 +387,14 @@
391387
}
392388

393389
$scope.byVersion = function(lint) {
394-
let filters = $scope.versionFilters;
390+
const filters = $scope.versionFilters;
395391
for (const filter in filters) {
396392
if (filters[filter].enabled) {
397-
let minorVersion = filters[filter].minorVersion;
393+
const minorVersion = filters[filter].minorVersion;
398394

399395
// Strip the "pre " prefix for pre 1.29.0 lints
400-
let lintVersion = lint.version.startsWith("pre ") ? lint.version.substring(4, lint.version.length) : lint.version;
401-
let lintMinorVersion = lintVersion.substring(2, 4);
396+
const lintVersion = lint.version.startsWith("pre ") ? lint.version.substring(4, lint.version.length) : lint.version;
397+
const lintMinorVersion = lintVersion.substring(2, 4);
402398

403399
switch (filter) {
404400
// "=" gets the highest priority, since all filters are inclusive
@@ -441,8 +437,8 @@
441437

442438
// Search the description
443439
// The use of `for`-loops instead of `foreach` enables us to return early
444-
let terms = searchStr.split(" ");
445-
let docsLowerCase = lint.docs.toLowerCase();
440+
const terms = searchStr.split(" ");
441+
const docsLowerCase = lint.docs.toLowerCase();
446442
for (index = 0; index < terms.length; index++) {
447443
// This is more likely and will therefore be checked first
448444
if (docsLowerCase.indexOf(terms[index]) !== -1) {
@@ -479,7 +475,7 @@
479475
const clipboard = document.getElementById("clipboard-" + lint.id);
480476
if (clipboard) {
481477
let resetClipboardTimeout = null;
482-
let resetClipboardIcon = clipboard.innerHTML;
478+
const resetClipboardIcon = clipboard.innerHTML;
483479

484480
function resetClipboard() {
485481
resetClipboardTimeout = null;
@@ -511,15 +507,15 @@
511507
$scope.data = data;
512508
$scope.loading = false;
513509

514-
var selectedGroup = getQueryVariable("sel");
510+
const selectedGroup = getQueryVariable("sel");
515511
if (selectedGroup) {
516512
selectGroup($scope, selectedGroup.toLowerCase());
517513
}
518514

519515
scrollToLintByURL($scope, $location);
520516

521517
setTimeout(function () {
522-
var el = document.getElementById('filter-input');
518+
const el = document.getElementById('filter-input');
523519
if (el) { el.focus() }
524520
}, 0);
525521
})
@@ -531,10 +527,10 @@
531527
})();
532528

533529
function getQueryVariable(variable) {
534-
var query = window.location.search.substring(1);
535-
var vars = query.split('&');
536-
for (var i = 0; i < vars.length; i++) {
537-
var pair = vars[i].split('=');
530+
const query = window.location.search.substring(1);
531+
const vars = query.split('&');
532+
for (const entry of vars) {
533+
const pair = entry.split('=');
538534
if (decodeURIComponent(pair[0]) == variable) {
539535
return decodeURIComponent(pair[1]);
540536
}

0 commit comments

Comments
 (0)