xixiaofinland / afmt

Salesforce Apex code formatter written in Rust
MIT License
23 stars 3 forks source link

Comments in list initializers are counted as elements #14

Open aheber opened 1 month ago

aheber commented 1 month ago

Similar to #12, if I have a comment inside of an array initializer then that comment is counted as a valid element and is joined with a comma.

Example:

class TestClass {
  List<String> vals = new List<String>{
    // test comment 1
    'val1',
    'val2',
    // test comment 2
    'val3'
    // test comment 3
  };
}

Formatted:

class TestClass {
  List<String> vals = new List<String>{   // test comment 1
, 'val1', 'val2',   // test comment 2
, 'val3',   // test comment 3 };
}
aheber commented 1 month ago

I'm not sure there is very easy way for me to help that at the parser level. Open to suggestions.

aheber commented 1 month ago

I'll place this here as a similar problem, we can break this out as a separate issue if you'd prefer.

Same problem but in the list of params for a method

Example:

class TestClass {
  {
    method1('foo', /* comment */ 'bar');
  }

  void method1(String param1, String param2){}
}

Formatted:

class TestClass {
  {
    method1('foo', /* comment */
, 'bar');
  }  

  void method1(String param1, String param2) {
  }
}