Skip to content

Commit

Permalink
Pass in a language version when calling the formatter.
Browse files Browse the repository at this point in the history
There is an upcoming version of dart_style that makes this argument
required, so every DartFormatter() constructor callsite needs to pass
it in. These are the last two I could find in the Dart SDK.

I'm not familiar with the surrounding code, but I believe passing in
DartFormatter.latestLanguage version will do the right thing:

* For the benchmark script, that's generated code that we will always
  want to be valid on the latest version of Dart.

* For the text_outline_suite, my understanding is that CFE tests that
  require older language versions always use the "// @Dart=x.y" comment
  to opt in to that version. Those comments are also respected by the
  formatter and override the languageVersion argument passed to the
  constructor. So I think passing in latestSupportedVersion will do the
  right thing.

Bug: #56687

Change-Id: If29188df479c7b41beb68ac889d56be13a395a16
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389622
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
  • Loading branch information
munificent authored and Commit Queue committed Oct 11, 2024
1 parent a99556b commit 8a9fb7c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pkg/front_end/benchmarks/patterns/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ class SeriesSet {
sb.write(']),');
}
sb.write(']);');
return new DartFormatter().format(sb.toString());
return new DartFormatter(
languageVersion: DartFormatter.latestLanguageVersion)
.format(sb.toString());
}
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/front_end/test/fasta/textual_outline_suite.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,13 @@ class TextualOutline extends Step<TestDescription, TestDescription, Context> {
experimentFlags.add(entry.key.name);
}
}
result = new DartFormatter(experimentFlags: experimentFlags)

// Default to the latest language version. If the test should be at
// an older language version, it will contain a `// @dart=x.y`
// comment, which takes precedence over this argument.
result = new DartFormatter(
languageVersion: DartFormatter.latestLanguageVersion,
experimentFlags: experimentFlags)
.format(result);
} catch (e, st) {
formatterException = e;
Expand Down

0 comments on commit 8a9fb7c

Please sign in to comment.