@@ -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