Skip to content

Commit 12a35ab

Browse files
committed
Auto merge of #6477 - xFrednet:0000-enable-search-with-dashes, r=ebroto
Adapted the website search for better matching * This adds the ability to search for ids with dashes and spaces in the name. * Example: `missing-errors-doc` and `missing errors doc` are now valid aliases for lint names * It also improves the fuzzy search in the description. This search will now match any lint that where all searched words are inside the description. * Example: `doc section` finds two lints in our selection This was suggested/discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Enable.20lint.20search.20with.20dashes/near/220469464) ### Testing These changes can be tested locally by: 1. Clone this branch 2. Download the current lint index from the [gh-pages branch](https://github.com/rust-lang/rust-clippy/blob/gh-pages/master/lints.json) 3. Put it next to the `util/gh-pages/index.html` and open the html file. Make sure that it can load the lint data. (Browsers can be a bit iffy when opening a loacl html page and loading data) ### Note I found that searching only a few characters (< 3) seams slow and deleting one even more as almost every lint description contains them. This also happens in our current [lint list](https://rust-lang.github.io/rust-clippy/master/index.html). We could change the search to only be triggered if the search field contains more than 3 letters to slightly improve performance. --- changelog: Adapted the website search for better matching
2 parents 9f9e9f7 + 2814ee4 commit 12a35ab

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

util/gh-pages/index.html

+41-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ <h1>ALL the Clippy Lints</h1>
8989
</div>
9090

9191
<article class="panel panel-default" id="{{lint.id}}"
92-
ng-repeat="lint in data | filter:byLevels | filter:byGroups | filter:search | orderBy:'id' track by lint.id" on-finish-render="ngRepeatFinished">
92+
ng-repeat="lint in data | filter:byLevels | filter:byGroups | filter:bySearch | orderBy:'id' track by lint.id">
9393
<header class="panel-heading" ng-click="open[lint.id] = !open[lint.id]">
9494
<h2 class="panel-title">
9595
<div class="panel-title-name">
@@ -215,6 +215,46 @@ <h4 class="list-group-item-heading">
215215
return $scope.groups[lint.group];
216216
};
217217

218+
$scope.bySearch = function (lint, index, array) {
219+
let search_str = $scope.search;
220+
// It can be `null` I haven't missed this value
221+
if (search_str == null || search_str.length == 0) {
222+
return true;
223+
}
224+
search_str = search_str.toLowerCase();
225+
226+
// Search by id
227+
let id_search = search_str.trim().replace(/(\-| )/g, "_");
228+
if (lint.id.includes(id_search)) {
229+
return true;
230+
}
231+
232+
// Search the description
233+
// The use of `for`-loops instead of `foreach` enables us to return early
234+
let search_lint = (lint, therm) => {
235+
for (const field in lint.docs) {
236+
// Continue if it's not a property
237+
if (!lint.docs.hasOwnProperty(field)) {
238+
continue;
239+
}
240+
241+
// Return if not found
242+
if (lint.docs[field].toLowerCase().includes(therm)) {
243+
return true;
244+
}
245+
}
246+
return false;
247+
};
248+
let therms = search_str.split(" ");
249+
for (index = 0; index < therms.length; index++) {
250+
if (!search_lint(lint, therms[index])) {
251+
return false;
252+
}
253+
}
254+
255+
return true;
256+
}
257+
218258
// Get data
219259
$scope.open = {};
220260
$scope.loading = true;

0 commit comments

Comments
 (0)