From bdc896165928de3e04b02f3f5632094fe337ebbc Mon Sep 17 00:00:00 2001
From: Serial <69764315+Serial-ATA@users.noreply.github.com>
Date: Sun, 24 Apr 2022 16:10:01 -0400
Subject: [PATCH] Add version filtering option to the lint list
---
util/gh-pages/index.html | 164 +++++++++++++++++++++++++++++++++++----
1 file changed, 151 insertions(+), 13 deletions(-)
diff --git a/util/gh-pages/index.html b/util/gh-pages/index.html
index 97c974003..286f3a347 100644
--- a/util/gh-pages/index.html
+++ b/util/gh-pages/index.html
@@ -94,6 +94,20 @@ Otherwise, have a great day =^.^=
@media (min-width: 992px) {
.search-control {
margin-top: 0;
+ float: right;
+ }
+ }
+
+ @media (min-width: 400px) {
+ #upper-filters {
+ display: flex;
+ }
+ }
+
+ @media (max-width: 412px) {
+ #version-filter-selector {
+ right: 0;
+ left: auto;
}
}
@@ -244,7 +258,7 @@ Otherwise, have a great day =^.^=
cursor: pointer;
}
- .theme-choice>li:hover {
+ .theme-choice > li:hover {
background: var(--theme-hover);
}
@@ -273,23 +287,40 @@ Otherwise, have a great day =^.^=
border: 1px solid var(--theme-popup-border);
}
- #filter-label, #filter-clear {
+ #version-filter-selector .checkbox {
+ display: flex;
+ }
+
+ #version-filter {
+ min-width: available;
+ }
+
+ #version-filter li label {
+ padding-right: 0;
+ width: 80%;
+ }
+
+ .version-filter-input {
+ height: 75%;
+ }
+
+ #filter-label, .filter-clear {
background: var(--searchbar-bg);
color: var(--searchbar-fg);
border-color: var(--theme-popup-border);
filter: brightness(95%);
}
- #filter-label:hover, #filter-clear:hover {
+ #filter-label:hover, .filter-clear:hover {
filter: brightness(90%);
}
- #filter-input {
+ .filter-input {
background: var(--searchbar-bg);
color: var(--searchbar-fg);
border-color: var(--theme-popup-border);
}
- #filter-input::-webkit-input-placeholder,
- #filter-input::-moz-placeholder {
+ .filter-input::-webkit-input-placeholder,
+ .filter-input::-moz-placeholder {
color: var(--searchbar-fg);
opacity: 30%;
}
@@ -338,7 +369,7 @@ Otherwise, have a great day =^.^=
-
+
+
-
+
-
+
@@ -601,6 +655,15 @@ Otherwise, have a great day =^.^=
};
$scope.themes = THEMES_DEFAULT;
+ const DEFAULT_VERSION_FILTERS = {
+ ">=": { enabled: false, version_str: "" },
+ "<=": { enabled: false, version_str: "" },
+ "==": { enabled: false, version_str: "" },
+ };
+ // Weird workaround to get a copy of the object
+ $scope.version_filters = JSON.parse(JSON.stringify(DEFAULT_VERSION_FILTERS));
+ $scope.version_regex = new RegExp('\\d\.\\d{2}\.\\d');
+
$scope.selectTheme = function (theme) {
setTheme(theme, true);
}
@@ -613,6 +676,7 @@ Otherwise, have a great day =^.^=
}
}
};
+
$scope.toggleGroups = function (value) {
const groups = $scope.groups;
for (const key in groups) {
@@ -621,9 +685,83 @@ Otherwise, have a great day =^.^=
}
}
};
+
$scope.selectedValuesCount = function (obj) {
return Object.values(obj).filter(x => x).length;
}
+
+ $scope.clearVersionFilters = function () {
+ $scope.version_filters = JSON.parse(JSON.stringify(DEFAULT_VERSION_FILTERS));
+ }
+
+ $scope.versionSymbol = function() {
+ const version_filters = $scope.version_filters;
+ let filter = ">=";
+ for (const key in version_filters) {
+ if (version_filters[key]) {
+ filter = key;
+ }
+ }
+
+ return filter;
+ }
+
+ $scope.byVersion = function(lint) {
+ function validate_version_str(ver) {
+ return ver.length === 6 && $scope.version_regex.test(ver);
+ }
+
+ function cmp_version(ver1, ver2, filter) {
+ // < 0: lint_version < version
+ // 0: equal
+ // > 0: lint_version > version
+ let result = ver1.localeCompare(ver2, undefined, {
+ numeric: true,
+ sensitivity: "base"
+ });
+
+ // "==" gets the highest priority, since all filters are inclusive
+ return (result === 0) || (filter === ">=" && result > 0) || (filter === "<=" && result < 0);
+ }
+
+ let filters = $scope.version_filters;
+
+ // Strip the "pre " prefix for pre 1.29.0 lints
+ let lint_version = lint.version.startsWith("pre ") ? lint.version.substring(4, lint.version.length) : lint.version;
+
+ for (const filter in filters) {
+ let version_str = filters[filter].version_str;
+
+ // Skip the work for version strings with invalid lengths or characters
+ if (!filters[filter].enabled || !validate_version_str(version_str)) {
+ continue;
+ }
+
+ let result = cmp_version(lint_version, version_str, filter);
+ if (result && filter === "==") {
+ return true;
+ } else if (!result) {
+ return false;
+ }
+
+ let cmp_filter;
+ if (filter === ">=") {
+ cmp_filter = "<=";
+ } else {
+ cmp_filter = ">=";
+ }
+
+ let cmp_version_str = filters[cmp_filter].version_str;
+ if (!filters[cmp_filter].enabled || !validate_version_str(cmp_version_str)) {
+ return true;
+ }
+
+ return cmp_version(lint_version, cmp_version_str, cmp_filter);
+ }
+
+ return true;
+ }
+
$scope.byGroups = function (lint) {
return $scope.groups[lint.group];
};
@@ -753,4 +891,4 @@ Otherwise, have a great day =^.^=
setTheme(localStorage.getItem('clippy-lint-list-theme'), false);