@@ -12,7 +12,7 @@ mod signatures;
1212mod test_gen_fixes;
1313
1414use crate :: code_audit:: { AuditFinding , CodeAuditResult } ;
15- use crate :: core:: refactor:: auto:: { DecomposeFixPlan , Fix , FixResult , SkippedFile } ;
15+ use crate :: core:: refactor:: auto:: { DecomposeFixPlan , Fix , FixPolicy , FixResult , SkippedFile } ;
1616use crate :: core:: refactor:: decompose;
1717use crate :: core:: refactor:: plan:: file_intent:: { FileIntent , FileIntentMap } ;
1818use std:: path:: Path ;
@@ -30,8 +30,8 @@ pub(crate) use signatures::{
3030 primary_type_name_from_declaration,
3131} ;
3232
33- pub fn generate_audit_fixes ( result : & CodeAuditResult , root : & Path ) -> FixResult {
34- generate_fixes_impl ( result, root)
33+ pub fn generate_audit_fixes ( result : & CodeAuditResult , root : & Path , policy : & FixPolicy ) -> FixResult {
34+ generate_fixes_impl ( result, root, policy )
3535}
3636
3737pub ( crate ) fn merge_fixes_per_file ( fixes : Vec < Fix > ) -> Vec < Fix > {
@@ -63,9 +63,16 @@ pub(crate) fn merge_fixes_per_file(fixes: Vec<Fix>) -> Vec<Fix> {
6363 . collect ( )
6464}
6565
66- pub ( crate ) fn generate_fixes_impl ( result : & CodeAuditResult , root : & Path ) -> FixResult {
66+ pub ( crate ) fn generate_fixes_impl ( result : & CodeAuditResult , root : & Path , policy : & FixPolicy ) -> FixResult {
6767 let mut fixes = Vec :: new ( ) ;
6868 let mut skipped = Vec :: new ( ) ;
69+ let finding_enabled = |finding : & AuditFinding | {
70+ policy
71+ . only
72+ . as_ref ( )
73+ . is_none_or ( |only| only. contains ( finding) )
74+ && !policy. exclude . contains ( finding)
75+ } ;
6976
7077 // ── Phase 0: Build file intent map ─────────────────────────────────
7178 // Identify structural operations (decompose, move, delete) planned for
@@ -75,6 +82,9 @@ pub(crate) fn generate_fixes_impl(result: &CodeAuditResult, root: &Path) -> FixR
7582 // declarative conflict rules.
7683 let mut intent_map = FileIntentMap :: new ( ) ;
7784 for finding in & result. findings {
85+ if !finding_enabled ( & finding. kind ) {
86+ continue ;
87+ }
7888 if matches ! (
7989 finding. kind,
8090 AuditFinding :: GodFile | AuditFinding :: HighItemCount
@@ -87,68 +97,100 @@ pub(crate) fn generate_fixes_impl(result: &CodeAuditResult, root: &Path) -> FixR
8797 // ── Phase 1: Generate all content fixes ────────────────────────────
8898 // Fixers run freely against the audit data. Conflicts with structural
8999 // intents are resolved after generation, not during.
90- apply_convention_fixes ( result, root, & mut fixes, & mut skipped) ;
100+ if policy. only . is_none ( ) && policy. exclude . is_empty ( ) {
101+ apply_convention_fixes ( result, root, & mut fixes, & mut skipped) ;
102+ }
91103
92104 let mut new_files = Vec :: new ( ) ;
93- generate_unreferenced_export_fixes ( result, root, & mut fixes, & mut skipped) ;
94- generate_duplicate_function_fixes ( result, root, & mut fixes, & mut new_files, & mut skipped) ;
95- orphaned_test_fixes:: generate_orphaned_test_fixes ( result, root, & mut fixes, & mut skipped) ;
105+ if finding_enabled ( & AuditFinding :: UnreferencedExport ) {
106+ generate_unreferenced_export_fixes ( result, root, & mut fixes, & mut skipped) ;
107+ }
108+ if finding_enabled ( & AuditFinding :: DuplicateFunction ) {
109+ generate_duplicate_function_fixes ( result, root, & mut fixes, & mut new_files, & mut skipped) ;
110+ }
111+ if finding_enabled ( & AuditFinding :: OrphanedTest ) {
112+ orphaned_test_fixes:: generate_orphaned_test_fixes ( result, root, & mut fixes, & mut skipped) ;
113+ }
96114
97115 // ── Phase 2: Build decompose plans ─────────────────────────────────
98116 let mut decompose_plans = Vec :: new ( ) ;
99117 let mut decompose_seen = std:: collections:: HashSet :: new ( ) ;
100- for finding in & result. findings {
101- if !matches ! (
102- finding. kind,
103- AuditFinding :: GodFile | AuditFinding :: HighItemCount
104- ) {
105- continue ;
106- }
107- // A file can trigger both GodFile and HighItemCount — only plan once.
108- if decompose_seen. contains ( & finding. file ) {
109- continue ;
110- }
111- let is_test = crate :: code_audit:: walker:: is_test_path ( & finding. file ) ;
112- if is_test {
113- continue ;
114- }
115- match decompose:: build_plan ( & finding. file , root, "grouped" ) {
116- Ok ( plan) => {
117- if plan. groups . len ( ) > 1 {
118+ if finding_enabled ( & AuditFinding :: GodFile ) || finding_enabled ( & AuditFinding :: HighItemCount ) {
119+ for finding in & result. findings {
120+ if !finding_enabled ( & finding. kind ) {
121+ continue ;
122+ }
123+ if !matches ! (
124+ finding. kind,
125+ AuditFinding :: GodFile | AuditFinding :: HighItemCount
126+ ) {
127+ continue ;
128+ }
129+ if decompose_seen. contains ( & finding. file ) {
130+ continue ;
131+ }
132+ let is_test = crate :: code_audit:: walker:: is_test_path ( & finding. file ) ;
133+ if is_test {
134+ continue ;
135+ }
136+ match decompose:: build_plan ( & finding. file , root, "grouped" ) {
137+ Ok ( plan) => {
138+ if plan. groups . len ( ) > 1 {
139+ decompose_seen. insert ( finding. file . clone ( ) ) ;
140+ decompose_plans. push ( DecomposeFixPlan {
141+ file : finding. file . clone ( ) ,
142+ plan,
143+ source_finding : finding. kind . clone ( ) ,
144+ applied : false ,
145+ } ) ;
146+ }
147+ }
148+ Err ( error) => {
118149 decompose_seen. insert ( finding. file . clone ( ) ) ;
119- decompose_plans . push ( DecomposeFixPlan {
150+ skipped . push ( SkippedFile {
120151 file : finding. file . clone ( ) ,
121- plan,
122- source_finding : finding. kind . clone ( ) ,
123- applied : false ,
152+ reason : format ! ( "Decompose plan failed: {}" , error) ,
124153 } ) ;
125154 }
126155 }
127- Err ( error) => {
128- decompose_seen. insert ( finding. file . clone ( ) ) ;
129- skipped. push ( SkippedFile {
130- file : finding. file . clone ( ) ,
131- reason : format ! ( "Decompose plan failed: {}" , error) ,
132- } ) ;
133- }
134156 }
135157 }
136158
137- doc_fixes:: apply_stale_doc_reference_fixes ( result, & mut fixes) ;
138- doc_fixes:: apply_broken_doc_reference_fixes ( result, root, & mut fixes) ;
139- parameter_fixes:: generate_parameter_fixes ( result, root, & mut fixes, & mut skipped) ;
140- test_gen_fixes:: generate_test_file_fixes (
141- result,
142- root,
143- & mut new_files,
144- & mut fixes,
145- & mut skipped,
146- ) ;
147- test_gen_fixes:: generate_test_method_fixes ( result, root, & mut fixes, & mut skipped) ;
148- compiler_warning_fixes:: generate_compiler_warning_fixes ( result, root, & mut fixes, & mut skipped) ;
149- comment_fixes:: generate_comment_fixes ( result, root, & mut fixes, & mut skipped) ;
150- near_duplicate_fixes:: generate_near_duplicate_fixes ( result, root, & mut fixes, & mut skipped) ;
151- intra_duplicate_fixes:: generate_intra_duplicate_fixes ( result, root, & mut fixes, & mut skipped) ;
159+ if finding_enabled ( & AuditFinding :: StaleDocReference ) {
160+ doc_fixes:: apply_stale_doc_reference_fixes ( result, & mut fixes) ;
161+ }
162+ if finding_enabled ( & AuditFinding :: BrokenDocReference ) {
163+ doc_fixes:: apply_broken_doc_reference_fixes ( result, root, & mut fixes) ;
164+ }
165+ if finding_enabled ( & AuditFinding :: UnusedParameter ) {
166+ parameter_fixes:: generate_parameter_fixes ( result, root, & mut fixes, & mut skipped) ;
167+ }
168+ if finding_enabled ( & AuditFinding :: MissingTestFile ) {
169+ test_gen_fixes:: generate_test_file_fixes (
170+ result,
171+ root,
172+ & mut new_files,
173+ & mut fixes,
174+ & mut skipped,
175+ ) ;
176+ }
177+ if finding_enabled ( & AuditFinding :: MissingTestMethod ) {
178+ test_gen_fixes:: generate_test_method_fixes ( result, root, & mut fixes, & mut skipped) ;
179+ }
180+ if finding_enabled ( & AuditFinding :: CompilerWarning ) {
181+ compiler_warning_fixes:: generate_compiler_warning_fixes ( result, root, & mut fixes, & mut skipped) ;
182+ }
183+ if finding_enabled ( & AuditFinding :: TodoMarker )
184+ || finding_enabled ( & AuditFinding :: LegacyComment )
185+ {
186+ comment_fixes:: generate_comment_fixes ( result, root, & mut fixes, & mut skipped) ;
187+ }
188+ if finding_enabled ( & AuditFinding :: NearDuplicate ) {
189+ near_duplicate_fixes:: generate_near_duplicate_fixes ( result, root, & mut fixes, & mut skipped) ;
190+ }
191+ if finding_enabled ( & AuditFinding :: IntraMethodDuplicate ) {
192+ intra_duplicate_fixes:: generate_intra_duplicate_fixes ( result, root, & mut fixes, & mut skipped) ;
193+ }
152194
153195 let mut fixes = merge_fixes_per_file ( fixes) ;
154196
0 commit comments