@@ -5,7 +5,8 @@ import path from 'path';
5
5
import { stripHtml } from 'string-strip-html' ;
6
6
import lunr , { Token } from 'lunr' ;
7
7
8
- import { IndexedRule , IndexStore , Severity , Type , IndexAggregates } from '../types/IndexStore' ;
8
+ import { Severity , maxSeverity } from '../types/Severities' ;
9
+ import { IndexedRule , IndexStore , Type , IndexAggregates } from '../types/IndexStore' ;
9
10
import { logger as rootLogger } from './deploymentLogger' ;
10
11
import { LanguageSupport } from '../types/RuleMetadata' ;
11
12
@@ -52,8 +53,12 @@ function buildOneRuleRecord(allLanguages: string[], rulesPath: string, ruleDir:
52
53
metadata . extra ?. legacyKeys ?. forEach ( ( legacyKey : string ) => allKeys . add ( legacyKey ) ) ;
53
54
titles . add ( metadata . title ) ;
54
55
types . add ( metadata . type ) ;
55
- severities . add ( metadata . defaultSeverity as Severity ) ;
56
- supportedLanguages . push ( { name : lang , status : metadata . status } ) ;
56
+ if ( ! metadata . hasOwnProperty ( 'code' ) ) {
57
+ severities . add ( Severity . INFO ) ;
58
+ } else {
59
+ severities . add ( maxSeverity ( metadata . code . impacts ) ) ;
60
+ }
61
+ supportedLanguages . push ( { name : lang , status : metadata . status } ) ;
57
62
if ( metadata . tags ) {
58
63
for ( const tag of metadata . tags ) {
59
64
tags . add ( tag ) ;
@@ -105,7 +110,7 @@ function buildOneRuleIndexedRecord(rulesPath: string, ruleDir: string)
105
110
id : ruleDir ,
106
111
supportedLanguages : Array . from ( record . supportedLanguages ) . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ,
107
112
types : Array . from ( record . types ) . sort ( ( a , b ) => a . localeCompare ( b ) ) ,
108
- severities : Array . from ( record . severities ) . sort ( ( a , b ) => a . localeCompare ( b ) ) ,
113
+ severities : Array . from ( record . severities ) . sort ( ( a , b ) => b - a ) ,
109
114
all_keys : Array . from ( record . allKeys ) . sort ( ( a , b ) => a . localeCompare ( b ) ) ,
110
115
titles : Array . from ( record . titles ) . sort ( ( a , b ) => a . localeCompare ( b ) ) ,
111
116
tags : Array . from ( record . tags ) . sort ( ( a , b ) => a . localeCompare ( b ) ) ,
@@ -192,7 +197,7 @@ export function buildSearchIndex(ruleIndexStore: IndexStore) {
192
197
this . field ( 'titles' , { extractor : ( doc ) => ( doc as IndexedRule ) . titles . join ( '\n' ) } ) ;
193
198
this . field ( 'types' ) ;
194
199
this . field ( 'languages' , { extractor : ( doc ) => ( doc as IndexedRule ) . supportedLanguages . map ( lang => lang . name ) } ) ;
195
- this . field ( 'defaultSeverity ' ) ;
200
+ this . field ( 'severity ' ) ;
196
201
this . field ( 'tags' ) ;
197
202
this . field ( 'qualityProfiles' ) ;
198
203
this . field ( 'descriptions' ) ;
0 commit comments