Skip to content

Commit

Permalink
chore: pass languageVersion to DartFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
halildurmus committed Dec 9, 2024
1 parent d95b9ec commit 8fc4d79
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
18 changes: 12 additions & 6 deletions packages/generator/bin/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ int generateStructs(List<Scope> scopes, Map<String, String> structs) {

final structsFile = [structFileHeader, ...structProjections].join();

file.writeAsStringSync(DartFormatter().format(structsFile));
file.writeAsStringSync(
DartFormatter(languageVersion: DartFormatter.latestLanguageVersion)
.format(structsFile));
return structProjections.length;
}

Expand Down Expand Up @@ -73,8 +75,9 @@ void generateDllFile(String library, List<Method> filteredMethods,
''');
}

File('../win32/lib/src/win32/$libraryDartName.g.dart')
.writeAsStringSync(DartFormatter().format(buffer.toString()));
File('../win32/lib/src/win32/$libraryDartName.g.dart').writeAsStringSync(
DartFormatter(languageVersion: DartFormatter.latestLanguageVersion)
.format(buffer.toString()));
}

void generateFunctions(
Expand Down Expand Up @@ -127,8 +130,9 @@ void main() {
}
''';

File('../win32/test/api_test.dart')
.writeAsStringSync(DartFormatter().format(testFile));
File('../win32/test/api_test.dart').writeAsStringSync(
DartFormatter(languageVersion: DartFormatter.latestLanguageVersion)
.format(testFile));
}

String generateFunctionTests(String library, Iterable<Method> methods,
Expand Down Expand Up @@ -211,7 +215,9 @@ void generateComApis(Scope scope, Map<String, String> comTypesToGenerate) {
stripAnsiUnicodeSuffix(lastComponent(interface)).toLowerCase();
final classOutputPath = '../win32/lib/src/com/$classOutputFilename.dart';

File(classOutputPath).writeAsStringSync(DartFormatter().format(dartClass));
File(classOutputPath).writeAsStringSync(
DartFormatter(languageVersion: DartFormatter.latestLanguageVersion)
.format(dartClass));
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/generator/example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ void printComSetProperty(String interface, String propertyName) {
}

extension on Object {
String format() => DartFormatter(lineEnding: '\n').format(toString());
String format() => DartFormatter(
languageVersion: DartFormatter.latestLanguageVersion,
lineEnding: '\n',
).format(toString());
}

void main() async {
Expand Down
6 changes: 4 additions & 2 deletions packages/generator/test/goldens_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ library;
import 'dart:io';

import 'package:dart_style/dart_style.dart';
import 'package:test/test.dart';
import 'package:generator/generator.dart';
import 'package:test/test.dart';
import 'package:winmd/winmd.dart';

void main() {
Expand Down Expand Up @@ -48,5 +48,7 @@ extension on String {
String convertLineEndingsToLF() => replaceAll('\r\n', '\n');

/// Formats this string.
String format() => DartFormatter().format(this);
String format() =>
DartFormatter(languageVersion: DartFormatter.latestLanguageVersion)
.format(this);
}

0 comments on commit 8fc4d79

Please sign in to comment.