@@ -44,41 +44,36 @@ impl Config {
4444
4545 /// Save configuration to a file
4646 pub fn save ( & self , path : & str ) -> Result < ( ) > {
47+ // Use standard serde_yaml serialization
4748 let yaml = serde_yaml:: to_string ( self ) ?;
4849
49- // Fix indentation for yamllint compliance
50- // yamllint expects array items to be indented relative to their parent
51- let fixed_yaml = Self :: fix_yaml_indentation ( & yaml) ;
52-
53- // Make yamllint compliant by adding document separator and ensuring newline at end
50+ // Minimal fix for yamllint: indent array items under 'repositories:' and 'recipes:'
51+ // This is the only formatting adjustment needed for yamllint compliance
52+ let fixed_yaml = yaml
53+ . lines ( )
54+ . map ( |line| {
55+ // If line starts with "- " and previous non-empty line ends with ":"
56+ // then it's an array item that needs indenting
57+ if line. starts_with ( "- " ) {
58+ format ! ( " {}" , line)
59+ } else if line. starts_with ( " " ) && !line. starts_with ( " " ) {
60+ // Lines with 1-2 spaces are properties of array items, need to be 4 spaces
61+ format ! ( " {}" , line)
62+ } else {
63+ line. to_string ( )
64+ }
65+ } )
66+ . collect :: < Vec < _ > > ( )
67+ . join ( "\n " ) ;
68+
69+ // Add document marker for yamllint compliance
5470 let yaml_content = format ! ( "---\n {}\n " , fixed_yaml) ;
5571
5672 std:: fs:: write ( path, yaml_content) ?;
5773
5874 Ok ( ( ) )
5975 }
6076
61- /// Fix YAML indentation to be yamllint compliant
62- fn fix_yaml_indentation ( yaml : & str ) -> String {
63- let lines: Vec < & str > = yaml. lines ( ) . collect ( ) ;
64- let mut result = Vec :: new ( ) ;
65-
66- for line in lines {
67- // If line starts with a dash (array item), indent it by 2 spaces
68- if line. starts_with ( "- " ) {
69- result. push ( format ! ( " {}" , line) ) ;
70- } else if line. starts_with ( " " ) && !line. starts_with ( " " ) {
71- // If line is already indented by 2 spaces but not 4, make it 4 spaces
72- // This handles the properties of array items
73- result. push ( format ! ( " {}" , line) ) ;
74- } else {
75- result. push ( line. to_string ( ) ) ;
76- }
77- }
78-
79- result. join ( "\n " )
80- }
81-
8277 /// Filter repositories by specific names
8378 pub fn filter_by_names ( & self , names : & [ String ] ) -> Vec < Repository > {
8479 filters:: filter_by_names ( & self . repositories , names)
@@ -468,28 +463,6 @@ mod tests {
468463 assert_eq ! ( config. repositories. len( ) , 1 ) ;
469464 }
470465
471- #[ test]
472- fn test_fix_yaml_indentation ( ) {
473- // Test basic array item indentation
474- let yaml = "repositories:\n - name: test\n url: test.git" ;
475- let fixed = Config :: fix_yaml_indentation ( yaml) ;
476- assert ! ( fixed. contains( " - name: test" ) ) ;
477- assert ! ( fixed. contains( " url: test.git" ) ) ;
478-
479- // Test already correctly indented yaml
480- let yaml = "repositories:\n - name: test\n url: test.git" ;
481- let fixed = Config :: fix_yaml_indentation ( yaml) ;
482- assert ! ( fixed. contains( " - name: test" ) ) ;
483- assert ! ( fixed. contains( " url: test.git" ) ) ;
484-
485- // Test lines with different indentation levels
486- let yaml = "key: value\n array:\n - item1\n subkey: subvalue" ;
487- let fixed = Config :: fix_yaml_indentation ( yaml) ;
488- assert ! ( fixed. contains( "key: value" ) ) ;
489- assert ! ( fixed. contains( " - item1" ) ) ;
490- assert ! ( fixed. contains( " subkey: subvalue" ) ) ;
491- }
492-
493466 #[ test]
494467 fn test_find_recipe ( ) {
495468 let mut config = Config :: new ( ) ;
0 commit comments