Skip to content

[flutter_tools] Deprecate flutter format sub-command in favor of dart format #115809

Closed

Description

@christopherfujino

The flutter format ... sub-command is essentially just a wrapper around a dart format ... sub-process call: https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/commands/format.dart#L36. However, it still has bugs: #109553 which are non-trivial to work around. We should deprecate this flutter format, with a message directing users to migrate to directly using dart format.

Deprecation plan:

  • on Flutter's main branch, land a PR to add a deprecation warning to the flutter format sub-command, warning users that it will be removed in a future Flutter release and that all uses of it should be replaced by dart format with the same command line arguments
  • once the code from the previous step reaches a stable release, a new change can be made to main that fails with a non-zero exit code, again with directions to start using dart format. This will catch users who either did not see the deprecation warning or chose to ignore it.
  • once the code from the previous step reaches a stable release, the command can be deleted from main.

If at any point it is found that customers have a legitimate use of flutter format that cannot be trivially met by substituting dart format for flutter format, we can discuss reverting the change and restoring flutter format.

Activity

  1. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Nov 22, 2022
  2. christopherfujino commented on Dec 1, 2022

    @christopherfujino
    ContributorAuthor

    Deprecation warning was added in #116145

  3. added
    P1High-priority issues at the top of the work list
    on Dec 1, 2022
  4. InMatrix commented on Dec 7, 2022

    @InMatrix

    Are we tracking the # of invocations of flutter format and dart format? If this migration is successful, this total # shouldn't change much.

  5. tjarvstrand commented on May 14, 2023

    @tjarvstrand

    Hello!

    While I understand the reasoning behind this change, unfortunately there is now no full proof way of ensuring that formatting is run using the same version of dart format that is shipped with Flutter which means that there is a higher risk of getting results that are inconsistent e.g. between different developer machines or between a developer machine and CI.

    To circumvent this, it would be great if we could at least get a way of reliably locating the Dart SDK inside the Flutter installation.

    When using a system-wide installation of Flutter, this location might be predictable but this is not always the case. For example, I routinely have work on projects that support different minimum versions of Flutter, and I manage these using asdf-vm, which means that e.g. which flutter will always return $HOME/.asdf/shims/flutter and there might be others on my team using similar solutions.

  6. christopherfujino commented on May 30, 2023

    @christopherfujino
    ContributorAuthor

    Hello!

    While I understand the reasoning behind this change, unfortunately there is now no full proof way of ensuring that formatting is run using the same version of dart format that is shipped with Flutter which means that there is a higher risk of getting results that are inconsistent e.g. between different developer machines or between a developer machine and CI.

    To circumvent this, it would be great if we could at least get a way of reliably locating the Dart SDK inside the Flutter installation.

    When using a system-wide installation of Flutter, this location might be predictable but this is not always the case. For example, I routinely have work on projects that support different minimum versions of Flutter, and I manage these using asdf-vm, which means that e.g. which flutter will always return $HOME/.asdf/shims/flutter and there might be others on my team using similar solutions.

    @tjarvstrand thanks for raising this concern. The officially recommended way to setup the Flutter SDK is to add flutter/bin to your PATH variable: https://github.com/flutter/flutter/blob/master/bin/dart. This directory includes a bash (and batch) entrypoint that will ensure you are using the version of the Dart SDK that is vendored with the Flutter SDK. Also note that flutter doctor -v will test if this path is on your path, and give you a hint as to the path to add if it is not. I would recommend using this Dart entrypoint in order to format Dart code.

  7. christopherfujino commented on May 30, 2023

    @christopherfujino
    ContributorAuthor

    As this command has already been deprecated on stable, we can now delete it: https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/commands/format.dart

  8. tjarvstrand commented on May 31, 2023

    @tjarvstrand

    @tjarvstrand thanks for raising this concern. The officially recommended way to setup the Flutter SDK is to add flutter/bin to your PATH variable: https://github.com/flutter/flutter/blob/master/bin/dart. This directory includes a bash (and batch) entrypoint that will ensure you are using the version of the Dart SDK that is vendored with the Flutter SDK. Also note that flutter doctor -v will test if this path is on your path, and give you a hint as to the path to add if it is not. I would recommend using this Dart entrypoint in order to format Dart code.

    I'm afraid that takes a rather narrow view of how developers can be expected to set up their environments. Even if you put this bin-directory on your PATH, you have to also make sure it's the first directory containing a dart-executable. I realize that this probably won't change because of my complaining here but I just want to say that I think that will make things very inconvenient for a lot of people. A simple flutter dart ... command would make things so much easier.

  9. christopherfujino commented on May 31, 2023

    @christopherfujino
    ContributorAuthor

    Even if you put this bin-directory on your PATH, you have to also make sure it's the first directory containing a dart-executable

    The doctor validator does validate what binary is resolved from the path, so at least it would catch this situation.

    A simple flutter dart ... command would make things so much easier.

    that's a good idea :). If you file a feature request for that and tag me we can start discussing. I would need to give more thought on the implications of that and how to do it right, but off-hand that sounds very reasonable to me.

  10. tjarvstrand commented on Jun 2, 2023

    @tjarvstrand

    that's a good idea :). If you file a feature request for that and tag me we can start discussing. I would need to give more thought on the implications of that and how to do it right, but off-hand that sounds very reasonable to me.

    Thanks! I opened a request for it.

  11. github-actions commented on Jul 6, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  12. locked as resolved and limited conversation to collaborators on Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P1High-priority issues at the top of the work listc: proposalA detailed proposal for a change to FluttertoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions