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 1/9] 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 97c974003c62..286f3a34753d 100644 --- a/util/gh-pages/index.html +++ b/util/gh-pages/index.html @@ -94,6 +94,20 @@ @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 @@ cursor: pointer; } - .theme-choice>li:hover { + .theme-choice > li:hover { background: var(--theme-hover); } @@ -273,23 +287,40 @@ 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 @@

Clippy Lints

-
+
+
+
+ + +
+
-
+
- - + + - @@ -406,7 +460,7 @@

Clippy Lints

-
+

@@ -601,6 +655,15 @@

}; $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 @@

} } }; + $scope.toggleGroups = function (value) { const groups = $scope.groups; for (const key in groups) { @@ -621,9 +685,83 @@

} } }; + $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 @@

setTheme(localStorage.getItem('clippy-lint-list-theme'), false); - + \ No newline at end of file From 06cc1abbb1b64a60c059137b3d610bbe0e0f3bea Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Tue, 26 Apr 2022 18:22:37 -0400 Subject: [PATCH 2/9] Move js out to its own file --- .github/deploy.sh | 1 + util/gh-pages/index.html | 375 +-------------------------------------- util/gh-pages/script.js | 372 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 374 insertions(+), 374 deletions(-) create mode 100644 util/gh-pages/script.js diff --git a/.github/deploy.sh b/.github/deploy.sh index 34225a540290..5a59f94ec918 100644 --- a/.github/deploy.sh +++ b/.github/deploy.sh @@ -8,6 +8,7 @@ rm -rf out/master/ || exit 0 echo "Making the docs for master" mkdir out/master/ cp util/gh-pages/index.html out/master +cp util/gh-pages/script.js out/master cp util/gh-pages/lints.json out/master if [[ -n $TAG_NAME ]]; then diff --git a/util/gh-pages/index.html b/util/gh-pages/index.html index 286f3a34753d..552c30f8353f 100644 --- a/util/gh-pages/index.html +++ b/util/gh-pages/index.html @@ -516,379 +516,6 @@

- + \ No newline at end of file diff --git a/util/gh-pages/script.js b/util/gh-pages/script.js new file mode 100644 index 000000000000..469a9306aee5 --- /dev/null +++ b/util/gh-pages/script.js @@ -0,0 +1,372 @@ +(function () { + var md = window.markdownit({ + html: true, + linkify: true, + typographer: true, + highlight: function (str, lang) { + if (lang && hljs.getLanguage(lang)) { + try { + return '
' +
+                        hljs.highlight(lang, str, true).value +
+                        '
'; + } catch (__) {} + } + + return '
' + md.utils.escapeHtml(str) + '
'; + } + }); + + function scrollToLint(lintId) { + var target = document.getElementById(lintId); + if (!target) { + return; + } + target.scrollIntoView(); + } + + function scrollToLintByURL($scope) { + var removeListener = $scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent) { + scrollToLint(window.location.hash.slice(1)); + removeListener(); + }); + } + + function selectGroup($scope, selectedGroup) { + var groups = $scope.groups; + for (var group in groups) { + if (groups.hasOwnProperty(group)) { + if (group === selectedGroup) { + groups[group] = true; + } else { + groups[group] = false; + } + } + } + } + + angular.module("clippy", []) + .filter('markdown', function ($sce) { + return function (text) { + return $sce.trustAsHtml( + md.render(text || '') + // Oh deer, what a hack :O + .replace('=": { 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); + } + + $scope.toggleLevels = function (value) { + const levels = $scope.levels; + for (const key in levels) { + if (levels.hasOwnProperty(key)) { + levels[key] = value; + } + } + }; + + $scope.toggleGroups = function (value) { + const groups = $scope.groups; + for (const key in groups) { + if (groups.hasOwnProperty(key)) { + groups[key] = value; + } + } + }; + + $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]; + }; + + $scope.bySearch = function (lint, index, array) { + let searchStr = $scope.search; + // It can be `null` I haven't missed this value + if (searchStr == null || searchStr.length < 3) { + return true; + } + searchStr = searchStr.toLowerCase(); + + // Search by id + if (lint.id.indexOf(searchStr.replace("-", "_")) !== -1) { + return true; + } + + // Search the description + // The use of `for`-loops instead of `foreach` enables us to return early + let terms = searchStr.split(" "); + let docsLowerCase = lint.docs.toLowerCase(); + for (index = 0; index < terms.length; index++) { + // This is more likely and will therefor be checked first + if (docsLowerCase.indexOf(terms[index]) !== -1) { + continue; + } + + if (lint.id.indexOf(terms[index]) !== -1) { + continue; + } + + return false; + } + + return true; + } + + // Get data + $scope.open = {}; + $scope.loading = true; + // This will be used to jump into the source code of the version that this documentation is for. + $scope.docVersion = window.location.pathname.split('/')[2] || "master"; + + if (window.location.hash.length > 1) { + $scope.search = window.location.hash.slice(1); + $scope.open[window.location.hash.slice(1)] = true; + scrollToLintByURL($scope); + } + + $http.get('./lints.json') + .success(function (data) { + $scope.data = data; + $scope.loading = false; + + var selectedGroup = getQueryVariable("sel"); + if (selectedGroup) { + selectGroup($scope, selectedGroup.toLowerCase()); + } + + scrollToLintByURL($scope); + + setTimeout(function () { + var el = document.getElementById('filter-input'); + if (el) { el.focus() } + }, 0); + }) + .error(function (data) { + $scope.error = data; + $scope.loading = false; + }); + + window.addEventListener('hashchange', function () { + // trigger re-render + $timeout(function () { + $scope.levels = LEVEL_FILTERS_DEFAULT; + $scope.search = window.location.hash.slice(1); + $scope.open[window.location.hash.slice(1)] = true; + + scrollToLintByURL($scope); + }); + return true; + }, false); + }); +})(); + +function getQueryVariable(variable) { + var query = window.location.search.substring(1); + var vars = query.split('&'); + for (var i = 0; i < vars.length; i++) { + var pair = vars[i].split('='); + if (decodeURIComponent(pair[0]) == variable) { + return decodeURIComponent(pair[1]); + } + } +} + +function setTheme(theme, store) { + let enableHighlight = false; + let enableNight = false; + let enableAyu = false; + + if (theme == "ayu") { + enableAyu = true; + } else if (theme == "coal" || theme == "navy") { + enableNight = true; + } else if (theme == "rust") { + enableHighlight = true; + } else { + enableHighlight = true; + // this makes sure that an unknown theme request gets set to a known one + theme = "light"; + } + document.getElementsByTagName("body")[0].className = theme; + + document.getElementById("styleHighlight").disabled = !enableHighlight; + document.getElementById("styleNight").disabled = !enableNight; + document.getElementById("styleAyu").disabled = !enableAyu; + + if (store) { + try { + localStorage.setItem('clippy-lint-list-theme', theme); + } catch (e) { } + } +} + +// loading the theme after the initial load +setTheme(localStorage.getItem('clippy-lint-list-theme'), false); From 9173780568144717da3a4986f67ad375b8fa1ded Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Fri, 29 Apr 2022 19:57:16 -0400 Subject: [PATCH 3/9] Make filters implicit; Update symbols --- util/gh-pages/index.html | 15 ++++++++------- util/gh-pages/script.js | 31 +++++++++++++------------------ 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/util/gh-pages/index.html b/util/gh-pages/index.html index 552c30f8353f..0a990df96f32 100644 --- a/util/gh-pages/index.html +++ b/util/gh-pages/index.html @@ -109,6 +109,10 @@ right: 0; left: auto; } + + #version-filter-count { + display: none; + } } .label { @@ -297,7 +301,7 @@ #version-filter li label { padding-right: 0; - width: 80%; + width: 40%; } .version-filter-input { @@ -425,7 +429,7 @@

Clippy Lints

diff --git a/util/gh-pages/script.js b/util/gh-pages/script.js index 469a9306aee5..8fbd3f50d3c3 100644 --- a/util/gh-pages/script.js +++ b/util/gh-pages/script.js @@ -137,13 +137,13 @@ $scope.themes = THEMES_DEFAULT; const DEFAULT_VERSION_FILTERS = { - ">=": { enabled: false, version_str: "" }, - "<=": { enabled: false, version_str: "" }, - "==": { enabled: false, version_str: "" }, + "≥": { 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.version_regex = new RegExp('1\.\\d{2}\.\\d'); $scope.selectTheme = function (theme) { setTheme(theme, true); @@ -175,16 +175,8 @@ $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.versionFilterCount = function(obj) { + return Object.values(obj).filter(x => x.enabled).length; } $scope.byVersion = function(lint) { @@ -214,10 +206,13 @@ 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)) { + if (!validate_version_str(version_str)) { + filters[filter].enabled = false; continue; } + filters[filter].enabled = true; + let result = cmp_version(lint_version, version_str, filter); if (result && filter === "==") { return true; @@ -226,10 +221,10 @@ } let cmp_filter; - if (filter === ">=") { - cmp_filter = "<="; + if (filter === "≥") { + cmp_filter = "≤"; } else { - cmp_filter = ">="; + cmp_filter = "≥"; } let cmp_version_str = filters[cmp_filter].version_str; From 2c70af3cd59504a79359808d39843132f47c9e32 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Tue, 3 May 2022 18:12:31 -0400 Subject: [PATCH 4/9] Only require minor version --- util/gh-pages/index.html | 25 ++++++++++++++++--- util/gh-pages/script.js | 53 ++++++++++++++++++++-------------------- 2 files changed, 47 insertions(+), 31 deletions(-) diff --git a/util/gh-pages/index.html b/util/gh-pages/index.html index 0a990df96f32..69dcd947dfbd 100644 --- a/util/gh-pages/index.html +++ b/util/gh-pages/index.html @@ -301,11 +301,15 @@ #version-filter li label { padding-right: 0; - width: 40%; + width: 35%; } .version-filter-input { - height: 75%; + height: 60%; + width: 30%; + text-align: center; + border: none; + border-bottom: 1px solid #000000; } #filter-label, .filter-clear { @@ -429,7 +433,11 @@

Clippy Lints

+
diff --git a/util/gh-pages/script.js b/util/gh-pages/script.js index 8fbd3f50d3c3..b04a93745749 100644 --- a/util/gh-pages/script.js +++ b/util/gh-pages/script.js @@ -137,13 +137,12 @@ $scope.themes = THEMES_DEFAULT; const DEFAULT_VERSION_FILTERS = { - "≥": { enabled: false, version_str: "" }, - "≤": { enabled: false, version_str: "" }, - "=": { enabled: false, version_str: "" }, + "≥": { enabled: false, minor_version: "" }, + "≤": { enabled: false, minor_version: "" }, + "=": { enabled: false, minor_version: "" }, }; // Weird workaround to get a copy of the object $scope.version_filters = JSON.parse(JSON.stringify(DEFAULT_VERSION_FILTERS)); - $scope.version_regex = new RegExp('1\.\\d{2}\.\\d'); $scope.selectTheme = function (theme) { setTheme(theme, true); @@ -181,42 +180,42 @@ $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); + return ver.length === 2 && !isNaN(ver); } 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; + let lint_minor_verison = lint_version.substring(2, 4); for (const filter in filters) { - let version_str = filters[filter].version_str; + let minor_version = filters[filter].minor_version; // Skip the work for version strings with invalid lengths or characters - if (!validate_version_str(version_str)) { + if (!validate_version_str(minor_version)) { filters[filter].enabled = false; continue; } filters[filter].enabled = true; - let result = cmp_version(lint_version, version_str, filter); - if (result && filter === "==") { - return true; - } else if (!result) { + let result; + switch (filter) { + case "≥": + result = (lint_minor_verison >= minor_version); + break; + case "≤": + result = (lint_minor_verison <= minor_version); + break; + // "=" gets the highest priority, since all filters are inclusive + case "=": + return (lint_minor_verison === minor_version); + default: + return true + } + + if (!result) { return false; } @@ -227,12 +226,12 @@ cmp_filter = "≥"; } - let cmp_version_str = filters[cmp_filter].version_str; - if (!filters[cmp_filter].enabled || !validate_version_str(cmp_version_str)) { + let cmp_minor_version = filters[cmp_filter].minor_version; + if (!filters[cmp_filter].enabled || !validate_version_str(cmp_minor_version)) { return true; } - return cmp_version(lint_version, cmp_version_str, cmp_filter); + return (cmp_filter === "≥") ? (lint_minor_verison > minor_version) : (lint_minor_verison < minor_version); } return true; From dd7bc86f227ca30f1c8a77955c60bced3a9c92db Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Wed, 4 May 2022 20:43:08 -0400 Subject: [PATCH 5/9] Change input placeholder --- util/gh-pages/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/gh-pages/index.html b/util/gh-pages/index.html index 69dcd947dfbd..ec62b3682f23 100644 --- a/util/gh-pages/index.html +++ b/util/gh-pages/index.html @@ -454,7 +454,7 @@

Clippy Lints

ng-attr-id="filter-{filter}" class="version-filter-input form-control filter-input" maxlength="2" - placeholder="62" + placeholder="xx" ng-model="version_filters[filter].minor_version" ng-model-options="{debounce: 50}" /> .0 From 4ed52bf13ecdc69a31e7be6a0bc9ba2a3e1a1932 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Thu, 5 May 2022 18:27:56 -0400 Subject: [PATCH 6/9] Use CamelCase; Fix filter ranges --- util/gh-pages/index.html | 8 +++---- util/gh-pages/script.js | 46 +++++++++++++++++++++------------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/util/gh-pages/index.html b/util/gh-pages/index.html index ec62b3682f23..11d99f39b558 100644 --- a/util/gh-pages/index.html +++ b/util/gh-pages/index.html @@ -435,7 +435,7 @@

Clippy Lints

@@ -447,7 +447,7 @@

Clippy Lints

-
  • +
  • 1. Clippy Lints
  • class="version-filter-input form-control filter-input" maxlength="2" placeholder="xx" - ng-model="version_filters[filter].minor_version" + ng-model="versionFilters[filter].minorVersion" ng-model-options="{debounce: 50}" /> .0 @@ -536,4 +536,4 @@

    - \ No newline at end of file + diff --git a/util/gh-pages/script.js b/util/gh-pages/script.js index b04a93745749..8f6832aef539 100644 --- a/util/gh-pages/script.js +++ b/util/gh-pages/script.js @@ -136,13 +136,11 @@ }; $scope.themes = THEMES_DEFAULT; - const DEFAULT_VERSION_FILTERS = { - "≥": { enabled: false, minor_version: "" }, - "≤": { enabled: false, minor_version: "" }, - "=": { enabled: false, minor_version: "" }, + $scope.versionFilters = { + "≥": {enabled: false, minorVersion: ""}, + "≤": {enabled: false, minorVersion: ""}, + "=": {enabled: false, minorVersion: ""}, }; - // Weird workaround to get a copy of the object - $scope.version_filters = JSON.parse(JSON.stringify(DEFAULT_VERSION_FILTERS)); $scope.selectTheme = function (theme) { setTheme(theme, true); @@ -171,7 +169,9 @@ } $scope.clearVersionFilters = function () { - $scope.version_filters = JSON.parse(JSON.stringify(DEFAULT_VERSION_FILTERS)); + for (let filter in $scope.versionFilters) { + $scope.versionFilters[filter] = { enabled: false, minorVersion: "" }; + } } $scope.versionFilterCount = function(obj) { @@ -179,21 +179,21 @@ } $scope.byVersion = function(lint) { - function validate_version_str(ver) { + function validateVersionStr(ver) { return ver.length === 2 && !isNaN(ver); } - let filters = $scope.version_filters; + let filters = $scope.versionFilters; // 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; - let lint_minor_verison = lint_version.substring(2, 4); + let lintVersion = lint.version.startsWith("pre ") ? lint.version.substring(4, lint.version.length) : lint.version; + let lintMinorVersion = lintVersion.substring(2, 4); for (const filter in filters) { - let minor_version = filters[filter].minor_version; + let minorVersion = filters[filter].minorVersion; // Skip the work for version strings with invalid lengths or characters - if (!validate_version_str(minor_version)) { + if (!validateVersionStr(minorVersion)) { filters[filter].enabled = false; continue; } @@ -203,14 +203,14 @@ let result; switch (filter) { case "≥": - result = (lint_minor_verison >= minor_version); + result = (lintMinorVersion >= minorVersion); break; case "≤": - result = (lint_minor_verison <= minor_version); + result = (lintMinorVersion <= minorVersion); break; // "=" gets the highest priority, since all filters are inclusive case "=": - return (lint_minor_verison === minor_version); + return (lintMinorVersion === minorVersion); default: return true } @@ -219,19 +219,21 @@ return false; } - let cmp_filter; + let cmpFilter; if (filter === "≥") { - cmp_filter = "≤"; + cmpFilter = "≤"; } else { - cmp_filter = "≥"; + cmpFilter = "≥"; } - let cmp_minor_version = filters[cmp_filter].minor_version; - if (!filters[cmp_filter].enabled || !validate_version_str(cmp_minor_version)) { + let cmpMinorVersion = filters[cmpFilter].minorVersion; + if (!validateVersionStr(cmpMinorVersion)) { + filters[cmpFilter].enabled = false; return true; } - return (cmp_filter === "≥") ? (lint_minor_verison > minor_version) : (lint_minor_verison < minor_version); + filters[cmpFilter].enabled = true; + return (cmpFilter === "≥") ? (lintMinorVersion >= cmpMinorVersion) : (lintMinorVersion <= cmpMinorVersion); } return true; From a30587e0fe5bc35f4ca9ea885b27bc93dbfced89 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Sat, 14 May 2022 20:08:10 -0400 Subject: [PATCH 7/9] Switch input to `type=number`; Separate version validation out of `byVersion` --- util/gh-pages/index.html | 13 ++--- util/gh-pages/script.js | 102 +++++++++++++++++++-------------------- 2 files changed, 58 insertions(+), 57 deletions(-) diff --git a/util/gh-pages/index.html b/util/gh-pages/index.html index 11d99f39b558..8bba9640a774 100644 --- a/util/gh-pages/index.html +++ b/util/gh-pages/index.html @@ -291,7 +291,7 @@ border: 1px solid var(--theme-popup-border); } - #version-filter-selector .checkbox { + #version-filter-selector .item { display: flex; } @@ -440,23 +440,24 @@

    Clippy Lints

    diff --git a/util/gh-pages/script.js b/util/gh-pages/script.js index 8f6832aef539..f72fe8c7f8bb 100644 --- a/util/gh-pages/script.js +++ b/util/gh-pages/script.js @@ -137,9 +137,9 @@ $scope.themes = THEMES_DEFAULT; $scope.versionFilters = { - "≥": {enabled: false, minorVersion: ""}, - "≤": {enabled: false, minorVersion: ""}, - "=": {enabled: false, minorVersion: ""}, + "≥": {enabled: false, minorVersion: null }, + "≤": {enabled: false, minorVersion: null }, + "=": {enabled: false, minorVersion: null }, }; $scope.selectTheme = function (theme) { @@ -170,7 +170,7 @@ $scope.clearVersionFilters = function () { for (let filter in $scope.versionFilters) { - $scope.versionFilters[filter] = { enabled: false, minorVersion: "" }; + $scope.versionFilters[filter] = { enabled: false, minorVersion: null }; } } @@ -178,62 +178,62 @@ return Object.values(obj).filter(x => x.enabled).length; } - $scope.byVersion = function(lint) { - function validateVersionStr(ver) { - return ver.length === 2 && !isNaN(ver); - } + $scope.updateVersionFilters = function() { + for (const filter in $scope.versionFilters) { + let minorVersion = $scope.versionFilters[filter].minorVersion; - let filters = $scope.versionFilters; + // 1.29.0 and greater + if (minorVersion && minorVersion > 28) { + $scope.versionFilters[filter].enabled = true; + } - // 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; - let lintMinorVersion = lintVersion.substring(2, 4); + $scope.versionFilters[filter].enabled = false; + } + } + $scope.byVersion = function(lint) { + let filters = $scope.versionFilters; for (const filter in filters) { - let minorVersion = filters[filter].minorVersion; - - // Skip the work for version strings with invalid lengths or characters - if (!validateVersionStr(minorVersion)) { - filters[filter].enabled = false; - continue; - } + if (filters[filter].enabled) { + let minorVersion = filters[filter].minorVersion; + + // 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; + let lintMinorVersion = lintVersion.substring(2, 4); + + let result; + switch (filter) { + case "≥": + result = (lintMinorVersion >= minorVersion); + break; + case "≤": + result = (lintMinorVersion <= minorVersion); + break; + // "=" gets the highest priority, since all filters are inclusive + case "=": + return (lintMinorVersion == minorVersion); + default: + return true + } - filters[filter].enabled = true; - - let result; - switch (filter) { - case "≥": - result = (lintMinorVersion >= minorVersion); - break; - case "≤": - result = (lintMinorVersion <= minorVersion); - break; - // "=" gets the highest priority, since all filters are inclusive - case "=": - return (lintMinorVersion === minorVersion); - default: - return true - } + if (!result) { + return false; + } - if (!result) { - return false; - } + let cmpFilter; + if (filter === "≥") { + cmpFilter = "≤"; + } else { + cmpFilter = "≥"; + } - let cmpFilter; - if (filter === "≥") { - cmpFilter = "≤"; - } else { - cmpFilter = "≥"; - } + if (filters[cmpFilter].enabled) { + let cmpMinorVersion = filters[cmpFilter].minorVersion; + result = (cmpFilter === "≥") ? (lintMinorVersion >= cmpMinorVersion) : (lintMinorVersion <= cmpMinorVersion); + } - let cmpMinorVersion = filters[cmpFilter].minorVersion; - if (!validateVersionStr(cmpMinorVersion)) { - filters[cmpFilter].enabled = false; - return true; + return result; } - - filters[cmpFilter].enabled = true; - return (cmpFilter === "≥") ? (lintMinorVersion >= cmpMinorVersion) : (lintMinorVersion <= cmpMinorVersion); } return true; From b81d7039704d2b9f84c7a90eee923a4a7a5304ac Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Sun, 15 May 2022 11:30:00 -0400 Subject: [PATCH 8/9] Use early returns --- util/gh-pages/index.html | 7 ++++--- util/gh-pages/script.js | 20 ++++++++------------ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/util/gh-pages/index.html b/util/gh-pages/index.html index 8bba9640a774..2f586077af54 100644 --- a/util/gh-pages/index.html +++ b/util/gh-pages/index.html @@ -110,6 +110,7 @@ left: auto; } + #version-filter-count { display: none; } @@ -291,7 +292,7 @@ border: 1px solid var(--theme-popup-border); } - #version-filter-selector .item { + #version-filter-selector .checkbox { display: flex; } @@ -440,14 +441,14 @@

    Clippy Lints