Skip to content

Commit 8e88b5b

Browse files
committed
Use the library effective language version when formatting
1 parent 9c1a764 commit 8e88b5b

File tree

3 files changed

+7
-16
lines changed

3 files changed

+7
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 5.4.6
22

3-
* Pass actual language version of generating package to formatter.
3+
* When formatting a generated mocks library, use the language version of the
4+
library with the mockito annotation.
45

56
## 5.4.5
67

@@ -25,9 +26,9 @@
2526

2627
## 5.4.3
2728

28-
* Require analyzer 5.12.0, allow analyzer version 6.x;
29+
* Require analyzer 5.12.0, allow analyzer version 6.x.
2930
* Add example of writing a class to mock function objects.
30-
* Add support for the `build_extensions` build.yaml option
31+
* Add support for the `build_extensions` build.yaml option.
3132
* Require Dart >=3.1.0.
3233
* **Potentially breaking** Changed default `String` value returned by nice
3334
mocks' unstubbed method to include some useful info. This could break the

lib/src/builder.dart

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ import 'package:collection/collection.dart';
4444
import 'package:dart_style/dart_style.dart';
4545
import 'package:mockito/annotations.dart';
4646
import 'package:mockito/src/version.dart';
47-
import 'package:package_config/package_config_types.dart';
4847
import 'package:path/path.dart' as p;
49-
import 'package:pub_semver/pub_semver.dart';
5048
import 'package:source_gen/source_gen.dart';
5149

5250
/// For a source Dart library, generate the mocks referenced therein.
@@ -144,16 +142,9 @@ class MockBuilder implements Builder {
144142
useNullSafetySyntax: sourceLibIsNonNullable);
145143
final rawOutput = mockLibrary.accept(emitter).toString();
146144

147-
final packageConfig = await buildStep.packageConfig;
148-
var surroundingLanguageVersion = DartFormatter.latestLanguageVersion;
149-
if (packageConfig[mockLibraryAsset.package]
150-
case Package(:final languageVersion?)) {
151-
surroundingLanguageVersion =
152-
Version(languageVersion.major, languageVersion.minor, 0);
153-
}
154-
155145
final mockLibraryContent =
156-
DartFormatter(languageVersion: surroundingLanguageVersion).format('''
146+
DartFormatter(languageVersion: entryLib.languageVersion.effective)
147+
.format('''
157148
// Mocks generated by Mockito $packageVersion from annotations
158149
// in ${entryLib.definingCompilationUnit.source.uri.path}.
159150
// Do not manually edit this file.

pubspec.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ dependencies:
2020
dart_style: '>=2.3.7 <4.0.0'
2121
matcher: ^0.12.16
2222
meta: ^1.15.0
23-
package_config: ^2.1.1
2423
path: ^1.9.0
25-
pub_semver: ^2.1.5
2624
source_gen: ">=1.4.0 <3.0.0"
2725
test_api: ">=0.6.1 <0.8.0"
2826

@@ -32,4 +30,5 @@ dev_dependencies:
3230
build_web_compilers: ^4.0.11
3331
http: ^1.0.0
3432
lints: ^5.1.0
33+
package_config: ^2.1.1
3534
test: ^1.24.4

0 commit comments

Comments
 (0)