xixiaofinland / afmt

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

Comment amidst SOQL #16

Open aheber opened 5 days ago

aheber commented 5 days ago

Comments embedded into SOQL can do some WEIRD things.

Example:

class TestClass {
  {
    List<SObject> records = [ // test comment 1
      SELECT // test comment 2
      // test comment 3
    Id, Name, // test comment 4
    // test comment 5
    Phone // test comment 6
    // test comment 7
    FROM // test comment 8
    Account // test comment 9
    ];
  }
}

Formatted:

class TestClass {
  {
    List<SObject> records = [    // test comment 1
];
  }
}

Example:

class TestClass {
  {
    List<SObject> records = [
      SELECT // test comment 2
      // test comment 3
    Id, Name, // test comment 4
    // test comment 5
    Phone // test comment 6
    // test comment 7
    FROM // test comment 8
    Account // test comment 9
    ];
  }
}

Formatted:

class TestClass {
  {
    List<SObject> records = [SELECT // test comment 2, // test comment 3, Id, Name, // test comment 4, // test comment 5, Phone // test comment 6
     // test comment 7
 FROM     // test comment 8
 Account];
  }
}

I'm sure the other SOQL clauses are problematic as well but didn't thoroughly test them yet.

xixiaofinland commented 5 days ago

Thanks! Comments need a total redesign of how to handle various scenarios.

The current logic can't scale up at all, so please hold the horse for comments.

I will keep the issue open and tackle it once I start to work on comment feature :).