Skip to content

Keep generated file comments on the first line #760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions source_gen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.1-WIP

- Keep `// GENERATED FILE` comments on the first line.

## 2.0.0

- **Breaking Change**: Change `formatOutput` function to accept a language
Expand Down
8 changes: 7 additions & 1 deletion source_gen/lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,13 @@ 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);
}

Expand Down
2 changes: 1 addition & 1 deletion source_gen/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: source_gen
version: 2.0.0
version: 2.0.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
Expand Down
10 changes: 5 additions & 5 deletions source_gen/test/builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1067,8 +1067,8 @@ final int foo = 42
''';

const _testGenPartContent = '''
$dartFormatWidth
// GENERATED CODE - DO NOT MODIFY BY HAND
$dartFormatWidth

part of 'test_lib.dart';

Expand All @@ -1081,8 +1081,8 @@ part of 'test_lib.dart';
''';

const _testGenPartContentForLibrary = '''
$dartFormatWidth
// GENERATED CODE - DO NOT MODIFY BY HAND
$dartFormatWidth

part of 'test_lib.dart';

Expand All @@ -1094,8 +1094,8 @@ part of 'test_lib.dart';
''';

const _testGenStandaloneContent = '''
$dartFormatWidth
// GENERATED CODE - DO NOT MODIFY BY HAND
$dartFormatWidth

// **************************************************************************
// CommentGenerator
Expand All @@ -1106,8 +1106,8 @@ $dartFormatWidth
''';

const _testGenPartContentForClassesAndLibrary = '''
$dartFormatWidth
// GENERATED CODE - DO NOT MODIFY BY HAND
$dartFormatWidth

part of 'test_lib.dart';

Expand All @@ -1121,8 +1121,8 @@ part of 'test_lib.dart';
''';

const _testGenNoLibrary = '''
$dartFormatWidth
// GENERATED CODE - DO NOT MODIFY BY HAND
$dartFormatWidth

part of 'test_lib.dart';

Expand Down
6 changes: 3 additions & 3 deletions source_gen/test/generator_for_annotation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ void main() {
_inputMap,
outputs: {
'a|lib/file.g.dart': '''
$dartFormatWidth
// GENERATED CODE - DO NOT MODIFY BY HAND
$dartFormatWidth

// **************************************************************************
// Generator: Repeating
Expand Down Expand Up @@ -129,8 +129,8 @@ $dartFormatWidth
},
outputs: {
'a|lib/file.g.dart': '''
$dartFormatWidth
// GENERATED CODE - DO NOT MODIFY BY HAND
$dartFormatWidth

// **************************************************************************
// Generator: Deprecated
Expand Down Expand Up @@ -166,8 +166,8 @@ $dartFormatWidth
},
outputs: {
'a|lib/file.g.dart': '''
$dartFormatWidth
// GENERATED CODE - DO NOT MODIFY BY HAND
$dartFormatWidth

// **************************************************************************
// Generator: Deprecated
Expand Down
Loading