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

Multiple passes needed to get final formatting #1625

Open
goderbauer opened this issue Dec 17, 2024 · 1 comment
Open

Multiple passes needed to get final formatting #1625

goderbauer opened this issue Dec 17, 2024 · 1 comment

Comments

@goderbauer
Copy link

Running dart format on the following code...

import 'dart:io';

bool foo() {
  if (
  // Explicitly stated to not be a bot.
  Platform.environment['BOT'] == 'false'
  ) {
    return false;
  }
  return true;
}

... produces this output:

import 'dart:io';

bool foo() {
  if (// Explicitly stated to not be a bot.
  Platform.environment['BOT'] == 'false') {
    return false;
  }
  return true;
}

Running dort format over that output again reformats it to the following (notice the added space before the //):

import 'dart:io';

bool foo() {
  if ( // Explicitly stated to not be a bot.
  Platform.environment['BOT'] == 'false') {
    return false;
  }
  return true;
}

Expectation: dart format produces the final output after one run. Subsequent runs do not change the output further.

@munificent
Copy link
Member

Yeah, the formatter is intended to be idempotent. But, unfortunately, I've never been able to figure out a way to systematically ensure that it is in all cases. We do at least test now that all of the test cases are idempotent.

Most of the places where it fails to be have to do with comments in uncommon locations like here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants