Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments in list initializers are counted as elements #14

Closed
aheber opened this issue Oct 8, 2024 · 3 comments
Closed

Comments in list initializers are counted as elements #14

aheber opened this issue Oct 8, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@aheber
Copy link
Contributor

aheber commented Oct 8, 2024

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
Copy link
Contributor Author

aheber commented Oct 8, 2024

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

@aheber
Copy link
Contributor Author

aheber commented Oct 8, 2024

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) {
  }
}

@xixiaofinland xixiaofinland added the enhancement New feature or request label Oct 9, 2024
@xixiaofinland
Copy link
Owner

This is the format result in v0.1.0. They are reasonable now.

class TestClass {
  List<String> vals =
    new List<String>{
      // test comment 1
      'val1',
      'val2',
      // test comment 2
      'val3'
      // test comment 3
    };
}
class TestClass {
  {
    method1('foo' /* comment */ , 'bar');
  }

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants