-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-- f9f3ade by Robert Nystrom <[email protected]>: Pass a language version to DartFormatter(). We're in [the process of](dart-lang/dart_style#1403) moving dart_style to [a new formatting style](dart-lang/dart_style#1253). That involves making the formatter [aware of the language version of what it's formatting](dart-lang/dart_style#1402). That in turn means that the library API now lets you pass in a language version. In dart_style 2.3.7 [you can pass in a language version but the parameter is optional](https://pub.dev/documentation/dart_style/latest/dart_style/DartFormatter/DartFormatter.html). In the forthcoming 3.0.0 release, that parameter will become mandatory. This updates the two calls to `DartFormatter()` in intl_translation/bin to pass in a language version. It attempts to look for a surrounding package_config.json file and uses the language version from that (which is what other Dart tools do). If that files, it just defaults to using the latest language version that the formatter supports. PiperOrigin-RevId: 689754530
- Loading branch information
1 parent
f30ad0f
commit 656b91c
Showing
4 changed files
with
41 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'package:package_config/package_config.dart'; | ||
import 'package:pub_semver/pub_semver.dart'; | ||
|
||
/// Looks for a package surrounding [file] and, if found, returns the default | ||
/// language version specified by that package. | ||
Future<Version?> findPackageLanguageVersion(File file) async { | ||
try { | ||
var config = await findPackageConfig(file.parent); | ||
if (config?.packageOf(file.absolute.uri)?.languageVersion | ||
case var languageVersion?) { | ||
return Version(languageVersion.major, languageVersion.minor, 0); | ||
} | ||
} catch (error) { | ||
// If we fail to find or read a config, just silently do nothing and | ||
// default to the latest language version. | ||
} | ||
|
||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters