Skip to content

Commit bd75e44

Browse files
committed
Auto merge of #12655 - SpencerAWill:Add-applicability-filter, r=xFrednet
Add applicability filter to lint list page changelog: Add applicability filter to lint list website. Fixes #7958 Desktop view: ![image](https://github.com/rust-lang/rust-clippy/assets/43732866/ef16dff1-c1c5-48a7-aa5c-ddd504280c90) Mobile view: ![image](https://github.com/rust-lang/rust-clippy/assets/43732866/9e6f54d9-b079-443f-a6b0-ca8ee4ed1eed)
2 parents 7e1ed1a + c8a7e6e commit bd75e44

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

util/gh-pages/index.html

+30-4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
@media (min-width: 405px) {
104104
#upper-filters {
105105
display: flex;
106+
flex-wrap: wrap;
106107
}
107108
}
108109

@@ -404,7 +405,7 @@ <h1>Clippy Lints</h1>
404405

405406
<div class="panel panel-default" ng-show="data">
406407
<div class="panel-body row">
407-
<div id="upper-filters" class="col-12 col-md-4">
408+
<div id="upper-filters" class="col-12 col-md-6">
408409
<div class="btn-group" filter-dropdown>
409410
<button type="button" class="btn btn-default dropdown-toggle">
410411
Lint levels <span class="badge">{{selectedValuesCount(levels)}}</span> <span class="caret"></span>
@@ -496,9 +497,34 @@ <h1>Clippy Lints</h1>
496497
</ul>
497498
</div>
498499
</div>
499-
500+
<div class="btn-group" filter-dropdown>
501+
<button type="button" class="btn btn-default dropdown-toggle">
502+
Applicability <span class="badge">{{selectedValuesCount(applicabilities)}}</span> <span class="caret"></span>
503+
</button>
504+
<ul class="dropdown-menu">
505+
<li class="checkbox">
506+
<label ng-click="toggleApplicabilities(true)">
507+
<input type="checkbox" class="invisible" />
508+
All
509+
</label>
510+
</li>
511+
<li class="checkbox">
512+
<label ng-click="toggleApplicabilities(false)">
513+
<input type="checkbox" class="invisible" />
514+
None
515+
</label>
516+
</li>
517+
<li role="separator" class="divider"></li>
518+
<li class="checkbox" ng-repeat="(applicability, enabled) in applicabilities">
519+
<label class="text-capitalize">
520+
<input type="checkbox" ng-model="applicabilities[applicability]" />
521+
{{applicability}}
522+
</label>
523+
</li>
524+
</ul>
525+
</div>
500526
</div>
501-
<div class="col-12 col-md-7 search-control">
527+
<div class="col-12 col-md-6 search-control">
502528
<div class="input-group">
503529
<label class="input-group-addon" id="filter-label" for="search-input">Filter:</label>
504530
<input type="text" class="form-control filter-input" placeholder="Keywords or search string" id="search-input"
@@ -514,7 +540,7 @@ <h1>Clippy Lints</h1>
514540
</div>
515541
</div>
516542
<!-- The order of the filters should be from most likely to remove a lint to least likely to improve performance. -->
517-
<article class="panel panel-default" id="{{lint.id}}" ng-repeat="lint in data | filter:bySearch | filter:byGroups | filter:byLevels | filter:byVersion">
543+
<article class="panel panel-default" id="{{lint.id}}" ng-repeat="lint in data | filter:bySearch | filter:byGroups | filter:byLevels | filter:byVersion | filter:byApplicabilities">
518544
<header class="panel-heading" ng-click="open[lint.id] = !open[lint.id]">
519545
<h2 class="panel-title">
520546
<div class="panel-title-name">

util/gh-pages/script.js

+33
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,18 @@
156156
Object.entries(versionFilterKeyMap).map(([key, value]) => [value, key])
157157
);
158158

159+
const APPLICABILITIES_FILTER_DEFAULT = {
160+
Unspecified: true,
161+
Unresolved: true,
162+
MachineApplicable: true,
163+
MaybeIncorrect: true,
164+
HasPlaceholders: true
165+
};
166+
167+
$scope.applicabilities = {
168+
...APPLICABILITIES_FILTER_DEFAULT
169+
}
170+
159171
// loadFromURLParameters retrieves filter settings from the URL parameters and assigns them
160172
// to corresponding $scope variables.
161173
function loadFromURLParameters() {
@@ -182,6 +194,7 @@
182194

183195
handleParameter('levels', $scope.levels, LEVEL_FILTERS_DEFAULT);
184196
handleParameter('groups', $scope.groups, GROUPS_FILTER_DEFAULT);
197+
handleParameter('applicabilities', $scope.applicabilities, APPLICABILITIES_FILTER_DEFAULT);
185198

186199
// Handle 'versions' parameter separately because it needs additional processing
187200
if (urlParameters.versions) {
@@ -249,6 +262,7 @@
249262
updateURLParameter($scope.levels, 'levels', LEVEL_FILTERS_DEFAULT);
250263
updateURLParameter($scope.groups, 'groups', GROUPS_FILTER_DEFAULT);
251264
updateVersionURLParameter($scope.versionFilters);
265+
updateURLParameter($scope.applicabilities, 'applicabilities', APPLICABILITIES_FILTER_DEFAULT);
252266
}
253267

254268
// Add $watches to automatically update URL parameters when the data changes
@@ -270,6 +284,12 @@
270284
}
271285
}, true);
272286

287+
$scope.$watch('applicabilities', function (newVal, oldVal) {
288+
if (newVal !== oldVal) {
289+
updateURLParameter(newVal, 'applicabilities', APPLICABILITIES_FILTER_DEFAULT)
290+
}
291+
}, true);
292+
273293
// Watch for changes in the URL path and update the search and lint display
274294
$scope.$watch(function () { return $location.path(); }, function (newPath) {
275295
const searchParameter = newPath.substring(1);
@@ -327,6 +347,15 @@
327347
}
328348
};
329349

350+
$scope.toggleApplicabilities = function (value) {
351+
const applicabilities = $scope.applicabilities;
352+
for (const key in applicabilities) {
353+
if (applicabilities.hasOwnProperty(key)) {
354+
applicabilities[key] = value;
355+
}
356+
}
357+
}
358+
330359
$scope.resetGroupsToDefault = function () {
331360
$scope.groups = {
332361
...GROUPS_FILTER_DEFAULT
@@ -430,6 +459,10 @@
430459
return true;
431460
}
432461

462+
$scope.byApplicabilities = function (lint) {
463+
return $scope.applicabilities[lint.applicability.applicability];
464+
};
465+
433466
// Show details for one lint
434467
$scope.openLint = function (lint) {
435468
$scope.open[lint.id] = true;

0 commit comments

Comments
 (0)