Skip to content
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

Don't emit code for empty files #1443

Merged
merged 2 commits into from
Dec 4, 2023
Merged
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* None

### Fixed
* None
* Fixed warnings being emitted by the realm generator requesting that `xyz.g.dart` be included with `part 'xyz.g.dart';` for `xyz.dart` files that import `realm` but don't have realm models defined. Those should not need generated parts and including the part file would have resulted in an empty file with `// ignore_for_file: type=lint` being generated. (PR [#1443](https://github.com/realm/realm-dart/pull/1443))

### Compatibility
* Realm Studio: 13.0.0 or later.
Expand Down
7 changes: 6 additions & 1 deletion generator/lib/src/realm_object_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ class RealmObjectGenerator extends Generator {
return await measure(
() async {
final result = await _getResolvedLibrary(library.element, buildStep.resolver);

return scopeSession(
result,
() {
return ['// ignore_for_file: type=lint', ...library.classes.realmInfo.expand((m) => m.toCode())].join('\n');
final codeLines = library.classes.realmInfo.expand((m) => m.toCode())..toList();
if (codeLines.isEmpty) {
return '';
}
return ['// ignore_for_file: type=lint', ...codeLines].join('\n');
},
color: stdout.supportsAnsiEscapes,
);
Expand Down
Loading