Skip to content

Both format and fix may introduce changes that the other will change again #54021

Open
@mdazy

Description

@mdazy

dart fix --apply may produce changes that will require new formatting (e.g. adding a missing trailing comma before a closing bracket) and dart format --fix may produce changes that will require new fixes (e.g. splitting a long line without inserting the trailing comma):

  // 1. dart fix --apply is initially OK with this long line
  // 2. dart format --fix splits the line but does not insert the trailing comma
  // 3. dart fix --apply adds the trailing comma but leaves the trailing bracket
  // 4. dart format --fix splits the trailing bracket to a separate line
  foo('this is a very very very very very very long string', 'this is another very very very very very very long string');

As a result, it's not possible to use either fix + format or format + fix in a pre-commit hook and ensuring that the resulting code will not require yet more changes before it's stable. If then a CI process attempts to check that the code is lint-free and properly formatted, such a check may fail.

Please see this minimal reproduction.

Dart info

#### General info

- Dart 3.1.3 (stable) (Tue Sep 26 14:25:13 2023 +0000) on "macos_arm64"
- on macos / Version 14.1.1 (Build 23B81)
- locale is en-FR

#### Project info

- sdk constraint: '^3.1.3'
- dependencies: 
- dev_dependencies: lints, test

#### Process info

| Memory |  CPU | Elapsed time | Command line                                                                    |
| -----: | ---: | -----------: | ------------------------------------------------------------------------------- |
|   9 MB | 0.0% |        19:05 | dart devtools --machine --try-ports 10 --allow-embedding                        |
|  25 MB | 0.0% |        19:05 | dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.76.1 |
|  15 MB | 0.0% |        19:05 | dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.76.1 |
|  35 MB | 0.4% |        19:05 | flutter_tools.snapshot daemon                                                   |

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart-cliUse area-dart-cli for issues related to the 'dart' command like tool.area-toolsA meta category for issues that should be addressed by tooling (prefer more concrete areas).dart-cli-fixdart-cli-formatIssues related to the 'dart format' tool

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions