Clean up clippy lints page JS source code

This commit is contained in:
Guillaume Gomez 2024-07-29 16:49:56 +02:00
parent f7db8952e6
commit 957a301083

View file

@ -1,5 +1,5 @@
(function () { (function () {
var md = window.markdownit({ const md = window.markdownit({
html: true, html: true,
linkify: true, linkify: true,
typographer: true, typographer: true,
@ -17,7 +17,7 @@
}); });
function scrollToLint(lintId) { function scrollToLint(lintId) {
var target = document.getElementById(lintId); const target = document.getElementById(lintId);
if (!target) { if (!target) {
return; return;
} }
@ -25,21 +25,17 @@
} }
function scrollToLintByURL($scope, $location) { function scrollToLintByURL($scope, $location) {
var removeListener = $scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) { const removeListener = $scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) {
scrollToLint($location.path().substring(1)); scrollToLint($location.path().substring(1));
removeListener(); removeListener();
}); });
} }
function selectGroup($scope, selectedGroup) { function selectGroup($scope, selectedGroup) {
var groups = $scope.groups; const groups = $scope.groups;
for (var group in groups) { for (const group in groups) {
if (groups.hasOwnProperty(group)) { if (groups.hasOwnProperty(group)) {
if (group === selectedGroup) { groups[group] = group === selectedGroup;
groups[group] = true;
} else {
groups[group] = false;
}
} }
} }
} }
@ -108,7 +104,7 @@
}) })
.controller("lintList", function ($scope, $http, $location, $timeout) { .controller("lintList", function ($scope, $http, $location, $timeout) {
// Level filter // Level filter
var LEVEL_FILTERS_DEFAULT = {allow: true, warn: true, deny: true, none: true}; const LEVEL_FILTERS_DEFAULT = {allow: true, warn: true, deny: true, none: true};
$scope.levels = { ...LEVEL_FILTERS_DEFAULT }; $scope.levels = { ...LEVEL_FILTERS_DEFAULT };
$scope.byLevels = function (lint) { $scope.byLevels = function (lint) {
return $scope.levels[lint.level]; return $scope.levels[lint.level];
@ -367,7 +363,7 @@
} }
$scope.clearVersionFilters = function () { $scope.clearVersionFilters = function () {
for (let filter in $scope.versionFilters) { for (const filter in $scope.versionFilters) {
$scope.versionFilters[filter] = { enabled: false, minorVersion: null }; $scope.versionFilters[filter] = { enabled: false, minorVersion: null };
} }
} }
@ -378,7 +374,7 @@
$scope.updateVersionFilters = function() { $scope.updateVersionFilters = function() {
for (const filter in $scope.versionFilters) { for (const filter in $scope.versionFilters) {
let minorVersion = $scope.versionFilters[filter].minorVersion; const minorVersion = $scope.versionFilters[filter].minorVersion;
// 1.29.0 and greater // 1.29.0 and greater
if (minorVersion && minorVersion > 28) { if (minorVersion && minorVersion > 28) {
@ -391,14 +387,14 @@
} }
$scope.byVersion = function(lint) { $scope.byVersion = function(lint) {
let filters = $scope.versionFilters; const filters = $scope.versionFilters;
for (const filter in filters) { for (const filter in filters) {
if (filters[filter].enabled) { if (filters[filter].enabled) {
let minorVersion = filters[filter].minorVersion; const minorVersion = filters[filter].minorVersion;
// Strip the "pre " prefix for pre 1.29.0 lints // Strip the "pre " prefix for pre 1.29.0 lints
let lintVersion = lint.version.startsWith("pre ") ? lint.version.substring(4, lint.version.length) : lint.version; const lintVersion = lint.version.startsWith("pre ") ? lint.version.substring(4, lint.version.length) : lint.version;
let lintMinorVersion = lintVersion.substring(2, 4); const lintMinorVersion = lintVersion.substring(2, 4);
switch (filter) { switch (filter) {
// "=" gets the highest priority, since all filters are inclusive // "=" gets the highest priority, since all filters are inclusive
@ -441,8 +437,8 @@
// Search the description // Search the description
// The use of `for`-loops instead of `foreach` enables us to return early // The use of `for`-loops instead of `foreach` enables us to return early
let terms = searchStr.split(" "); const terms = searchStr.split(" ");
let docsLowerCase = lint.docs.toLowerCase(); const docsLowerCase = lint.docs.toLowerCase();
for (index = 0; index < terms.length; index++) { for (index = 0; index < terms.length; index++) {
// This is more likely and will therefore be checked first // This is more likely and will therefore be checked first
if (docsLowerCase.indexOf(terms[index]) !== -1) { if (docsLowerCase.indexOf(terms[index]) !== -1) {
@ -479,7 +475,7 @@
const clipboard = document.getElementById("clipboard-" + lint.id); const clipboard = document.getElementById("clipboard-" + lint.id);
if (clipboard) { if (clipboard) {
let resetClipboardTimeout = null; let resetClipboardTimeout = null;
let resetClipboardIcon = clipboard.innerHTML; const resetClipboardIcon = clipboard.innerHTML;
function resetClipboard() { function resetClipboard() {
resetClipboardTimeout = null; resetClipboardTimeout = null;
@ -511,7 +507,7 @@
$scope.data = data; $scope.data = data;
$scope.loading = false; $scope.loading = false;
var selectedGroup = getQueryVariable("sel"); const selectedGroup = getQueryVariable("sel");
if (selectedGroup) { if (selectedGroup) {
selectGroup($scope, selectedGroup.toLowerCase()); selectGroup($scope, selectedGroup.toLowerCase());
} }
@ -519,7 +515,7 @@
scrollToLintByURL($scope, $location); scrollToLintByURL($scope, $location);
setTimeout(function () { setTimeout(function () {
var el = document.getElementById('filter-input'); const el = document.getElementById('filter-input');
if (el) { el.focus() } if (el) { el.focus() }
}, 0); }, 0);
}) })
@ -531,10 +527,10 @@
})(); })();
function getQueryVariable(variable) { function getQueryVariable(variable) {
var query = window.location.search.substring(1); const query = window.location.search.substring(1);
var vars = query.split('&'); const vars = query.split('&');
for (var i = 0; i < vars.length; i++) { for (const entry of vars) {
var pair = vars[i].split('='); const pair = entry.split('=');
if (decodeURIComponent(pair[0]) == variable) { if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]); return decodeURIComponent(pair[1]);
} }