xixiaofinland / afmt

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

Comments in weird places in if statements are lost #10

Open aheber opened 6 days ago

aheber commented 6 days ago

If I add a comment after the if keyword or after the criteria expression then they are lost and not printed.

Example:

public class Me {
  {
    if // test comment 1
    (true) // test comment 2
    {
      // test comment 3
      Integer i = 1; // test comment 4
    } // test comment 5

    if // test comment 6
    (true) // test comment 7
      Integer i = 1; // test comment 8
    // test comment 9
  }
}

Formatted:

public class Me {
  {
    if (true) {
      // test comment 3
      Integer i = 1; // test comment 4
    } // test comment 5

    if (true) {
      Integer i = 1;
    } // test comment 8
    // test comment 9
  }
}
aheber commented 6 days ago

Also else clauses

Example:

class TestClass {
  {
    if(true){

    } else // comment 1
    {

    }
  }
}

Formatted:

class TestClass {
  {
    if (true) {
    } else {
    }
  }
}