diff --git a/example_usage/lib/library_source.info.dart b/example_usage/lib/library_source.info.dart index 47ff6ea3..99b7457e 100644 --- a/example_usage/lib/library_source.info.dart +++ b/example_usage/lib/library_source.info.dart @@ -1,5 +1,5 @@ -// dart format width=80 // GENERATED CODE - DO NOT MODIFY BY HAND +// dart format width=80 // ************************************************************************** // MemberCountLibraryGenerator diff --git a/source_gen/CHANGELOG.md b/source_gen/CHANGELOG.md index 9f6dba4b..44f763b9 100644 --- a/source_gen/CHANGELOG.md +++ b/source_gen/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.1.1-wip + +- Keep `// GENERATED FILE` comments on the first line. + ## 3.1.0 - Prepare to stop using `dart:mirrors`: deprecate `TypeChecker.fromRuntime`. diff --git a/source_gen/lib/src/builder.dart b/source_gen/lib/src/builder.dart index 6eaba0ff..0892ec42 100644 --- a/source_gen/lib/src/builder.dart +++ b/source_gen/lib/src/builder.dart @@ -433,7 +433,14 @@ String _defaultFormatOutput(String code, Version version) => /// Prefixes a dart format width and formats [code]. String _defaultFormatUnit(String code, Version version) { - code = '$dartFormatWidth\n$code'; + if (code.startsWith('$defaultFileHeader\n')) { + code = + '$defaultFileHeader\n' + '$dartFormatWidth\n' + '${code.substring(defaultFileHeader.length)}'; + } else { + code = '$dartFormatWidth\n$code'; + } return _defaultFormatOutput(code, version); } diff --git a/source_gen/pubspec.yaml b/source_gen/pubspec.yaml index 546c6ed5..80c7efc9 100644 --- a/source_gen/pubspec.yaml +++ b/source_gen/pubspec.yaml @@ -1,5 +1,5 @@ name: source_gen -version: 3.1.0 +version: 3.1.1-wip description: >- Source code generation builders and utilities for the Dart build system repository: https://github.com/dart-lang/source_gen/tree/master/source_gen diff --git a/source_gen/test/builder_test.dart b/source_gen/test/builder_test.dart index f097d01b..d2dff25f 100644 --- a/source_gen/test/builder_test.dart +++ b/source_gen/test/builder_test.dart @@ -1058,8 +1058,8 @@ final int foo = 42 '''; const _testGenPartContent = ''' -$dartFormatWidth // GENERATED CODE - DO NOT MODIFY BY HAND +$dartFormatWidth part of 'test_lib.dart'; @@ -1072,8 +1072,8 @@ part of 'test_lib.dart'; '''; const _testGenPartContentForLibrary = ''' -$dartFormatWidth // GENERATED CODE - DO NOT MODIFY BY HAND +$dartFormatWidth part of 'test_lib.dart'; @@ -1085,8 +1085,8 @@ part of 'test_lib.dart'; '''; const _testGenStandaloneContent = ''' -$dartFormatWidth // GENERATED CODE - DO NOT MODIFY BY HAND +$dartFormatWidth // ************************************************************************** // CommentGenerator @@ -1097,8 +1097,8 @@ $dartFormatWidth '''; const _testGenPartContentForClassesAndLibrary = ''' -$dartFormatWidth // GENERATED CODE - DO NOT MODIFY BY HAND +$dartFormatWidth part of 'test_lib.dart'; @@ -1112,8 +1112,8 @@ part of 'test_lib.dart'; '''; const _testGenNoLibrary = ''' -$dartFormatWidth // GENERATED CODE - DO NOT MODIFY BY HAND +$dartFormatWidth part of 'test_lib.dart'; diff --git a/source_gen/test/generator_for_annotation_test.dart b/source_gen/test/generator_for_annotation_test.dart index 900e547a..88b2220d 100644 --- a/source_gen/test/generator_for_annotation_test.dart +++ b/source_gen/test/generator_for_annotation_test.dart @@ -52,8 +52,8 @@ void main() { _inputMap, outputs: { 'a|lib/file.g.dart': ''' -$dartFormatWidth // GENERATED CODE - DO NOT MODIFY BY HAND +$dartFormatWidth // ************************************************************************** // Generator: Repeating @@ -150,8 +150,8 @@ main() {}''', }, outputs: { 'a|lib/file.g.dart': ''' -$dartFormatWidth // GENERATED CODE - DO NOT MODIFY BY HAND +$dartFormatWidth // ************************************************************************** // Generator: Deprecated @@ -195,8 +195,8 @@ $dartFormatWidth }, outputs: { 'a|lib/file.g.dart': ''' -$dartFormatWidth // GENERATED CODE - DO NOT MODIFY BY HAND +$dartFormatWidth // ************************************************************************** // Generator: Deprecated