11use crate :: lang:: { CustomLang , LanguageGlobs , SerializableInjection , SgLang } ;
2- use crate :: utils:: ErrorContext as EC ;
2+ use crate :: utils:: { ErrorContext as EC , RuleStats } ;
33
44use anyhow:: { Context , Result } ;
55use ast_grep_config:: {
@@ -57,7 +57,7 @@ pub struct AstGrepConfig {
5757pub fn find_rules (
5858 config_path : Option < PathBuf > ,
5959 rule_filter : Option < & Regex > ,
60- ) -> Result < RuleCollection < SgLang > > {
60+ ) -> Result < ( RuleCollection < SgLang > , RuleStats ) > {
6161 let config_path =
6262 find_config_path_with_default ( config_path, None ) . context ( EC :: ReadConfiguration ) ?;
6363 let config_str = read_to_string ( & config_path) . context ( EC :: ReadConfiguration ) ?;
@@ -132,7 +132,7 @@ fn read_directory_yaml(
132132 rule_dirs : Vec < PathBuf > ,
133133 global_rules : GlobalRules < SgLang > ,
134134 rule_filter : Option < & Regex > ,
135- ) -> Result < RuleCollection < SgLang > > {
135+ ) -> Result < ( RuleCollection < SgLang > , RuleStats ) > {
136136 let mut configs = vec ! [ ] ;
137137 for dir in rule_dirs {
138138 let dir_path = base_dir. join ( dir) ;
@@ -154,14 +154,20 @@ fn read_directory_yaml(
154154 configs. extend ( new_configs) ;
155155 }
156156 }
157+ let total_rule_count = configs. len ( ) ;
157158
158159 let configs = if let Some ( filter) = rule_filter {
159160 filter_rule_by_regex ( configs, filter) ?
160161 } else {
161162 configs
162163 } ;
163-
164- RuleCollection :: try_new ( configs) . context ( EC :: GlobPattern )
164+ let collection = RuleCollection :: try_new ( configs) . context ( EC :: GlobPattern ) ?;
165+ let effective_rule_count = collection. total_rule_count ( ) ;
166+ let stats = RuleStats {
167+ effective_rule_count,
168+ skipped_rule_count : total_rule_count - effective_rule_count,
169+ } ;
170+ Ok ( ( collection, stats) )
165171}
166172
167173fn filter_rule_by_regex (
0 commit comments