xixiaofinland / afmt

Salesforce Apex code formatter written in Rust
20 stars 3 forks source link

Comment spacing following initialization block #13

Open aheber opened 6 days ago

aheber commented 6 days ago

An initialization block on a class (and static initialization) will subsume the following comment. In my actual code it was a doc comment for the following method but it had the same behavior as these simpler examples.

This doesn't seem like it would be the correct behavior.

Example:

class TestClass {
  Integer i;

  /*
    test block
   */

  {

  }

  /*
    test block
  */
  Integer i2;

  {

  }

  // line
  Integer i3;
}

Formatted:

class TestClass {
  Integer i;

  /*
    test block
   */

  {
  }  /*
    test block
  */
  Integer i2;

  {
  }  // line
  Integer i3;
}
aheber commented 6 days ago

For bonus points, Prettier also seems to do something weird to this though it is less weird. I'll have to submit something on that project too.

class TestClass {
  Integer i;

  {
    /*
    test block
   */
  }

  /*
    test block
  */
  Integer i2;

  {
  }

  // line
  Integer i3;
}
aheber commented 6 days ago

Additional note, I think this is a problem with initialization blocks in general, less about comments.

Example:

class TestClass {
  {

  }

  Integer i2;
}

Formatted:

class TestClass {
  {
  }  Integer i2;
}