Skip to content

Commit

Permalink
Use correct language version for formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
simolus3 committed Dec 19, 2024
1 parent 5cb8433 commit c89ceaf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.4.6

* Pass actual language version of generating package to formatter.

## 5.4.5

* Ignore "must_be_immutable" warning in generated files. Mocks cannot be made
Expand Down
17 changes: 12 additions & 5 deletions lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ import 'package:collection/collection.dart';
import 'package:dart_style/dart_style.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/src/version.dart';
import 'package:package_config/package_config_types.dart';
import 'package:path/path.dart' as p;
import 'package:pub_semver/pub_semver.dart';
import 'package:source_gen/source_gen.dart';

/// For a source Dart library, generate the mocks referenced therein.
Expand Down Expand Up @@ -141,12 +143,17 @@ class MockBuilder implements Builder {
orderDirectives: true,
useNullSafetySyntax: sourceLibIsNonNullable);
final rawOutput = mockLibrary.accept(emitter).toString();
// The source lib may be pre-null-safety because of an explicit opt-out
// (`// @dart=2.9`), as opposed to living in a pre-null-safety package. To
// allow for this situation, we must also add an opt-out comment here.

final packageConfig = await buildStep.packageConfig;
var surroundingLanguageVersion = DartFormatter.latestLanguageVersion;
if (packageConfig[mockLibraryAsset.package]
case Package(:final languageVersion?)) {
surroundingLanguageVersion =
Version(languageVersion.major, languageVersion.minor, 0);
}

final mockLibraryContent =
DartFormatter(languageVersion: DartFormatter.latestLanguageVersion)
.format('''
DartFormatter(languageVersion: surroundingLanguageVersion).format('''
// Mocks generated by Mockito $packageVersion from annotations
// in ${entryLib.definingCompilationUnit.source.uri.path}.
// Do not manually edit this file.
Expand Down
5 changes: 3 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: mockito
version: 5.4.5
version: 5.4.6
description: >-
A mock framework inspired by Mockito with APIs for Fakes, Mocks,
behavior verification, and stubbing.
Expand All @@ -20,7 +20,9 @@ dependencies:
dart_style: '>=2.3.7 <4.0.0'
matcher: ^0.12.16
meta: ^1.15.0
package_config: ^2.1.1
path: ^1.9.0
pub_semver: ^2.1.5
source_gen: ">=1.4.0 <3.0.0"
test_api: ">=0.6.1 <0.8.0"

Expand All @@ -30,5 +32,4 @@ dev_dependencies:
build_web_compilers: ^4.0.11
http: ^1.0.0
lints: ^5.1.0
package_config: ^2.1.0
test: ^1.24.4

0 comments on commit c89ceaf

Please sign in to comment.