-
Notifications
You must be signed in to change notification settings - Fork 66
Conversation
Package publishing
Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation. |
@@ -45,7 +45,7 @@ void main() { | |||
), | |||
equalsDart(r''' | |||
// Generated by foo! | |||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like there should still be a way to get this output. Not sure how though... comments
could be a list of nullable strings, and then null means something different from a blank string. Or a string that is only whitespace vs blank? I can't think of anything great...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know that it's an important use case to support //
lines? But the easiest and most clear way would likely be by supporting null strings.
An alternative approach would be to support line wrapping. So, multiple lines would mean multiple groups of comments, with each line automatically wrapped at ~80 cols.
I may implement the 1st solution as that seems like the smallest API diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I don't have any examples, but I can imagine that it's more common to write a multi-paragraph comment (with blank //
lines) than adjacent comments. Like if you have two paragraphs, or an example, like a code block separated from test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This functionality is just affecting leading library line comments; mostly this is used for the ~3 line copyright headers for files.
The use case I have here is that I also want a // Generated by ...
message at the top of the file. Currently this is emitted as part of the file copyright header, which is really not intended or desired. So, I want to go from:
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
//
// Generated from Web IDL definitions.
to:
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Generated from Web IDL definitions.
(see https://github.com/dart-lang/web/blob/main/lib/src/dom/accelerometer.dart)
ptal - updated to support both empty line comments as well as having groups of line comments |
I'm not a huge fan of the nullable String API, where null is sort of a "magic value." But I do think it is extremely pragmatic, functional, easy to understand... I think I'd like another opinion like @natebosch before landing. If we go a nullable String API then it would be a pain to bring it back to a non-nullable String API. I'd almost prefer an API where "a comment" is a |
Agree w/ the nullability aspect; I think it doesn't improve the API. I've reverted back to a simplier form of this PR; happy to wait for an opinion from Nate. For context, this PR is to improve the output of the files we generate for package:web. |
It's currently a bug to have a newline in a comment. We could allow this flexibility by splitting each diff --git a/lib/src/emitter.dart b/lib/src/emitter.dart
index 591b992..fe4a898 100644
--- a/lib/src/emitter.dart
+++ b/lib/src/emitter.dart
@@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+import 'dart:convert';
+
import 'allocator.dart';
import 'base.dart';
import 'specs/class.dart';
@@ -479,8 +481,16 @@ class DartEmitter extends Object
output ??= StringBuffer();
if (spec.comments.isNotEmpty) {
- spec.comments.map((line) => '// $line').forEach(output.writeln);
- output.writeln();
+ for (final comment in spec.comments) {
+ for (final line in const LineSplitter().convert(comment)) {
+ if (line.isEmpty) {
+ output.writeln('//');
+ } else {
+ output.writeln('// $line');
+ }
+ }
+ output.writeln();
+ }
}
if (spec.ignoreForFile.isNotEmpty) {
diff --git a/test/specs/library_test.dart b/test/specs/library_test.dart
index 3c5502e..a525ae2 100644
--- a/test/specs/library_test.dart
+++ b/test/specs/library_test.dart
@@ -35,9 +35,7 @@ void main() {
Library(
(b) => b
..comments.addAll([
- 'Generated by foo!',
- '',
- 'Avoid editing by hand.',
+ 'Generated by foo!\n\nAvoid editing by hand.',
])
..body.add(
Class((b) => b..name = 'Foo'), I think this change, either my diff or as is in the PR, breaks the meaning of some usage in the same way. The line splitting gives users an escape hatch to get back to the old output if that is what they prefer. |
Thinking about the comments above:
I have a separate PR now - #441 - which adds a new field for that specific use case - a |
This is to allow us to do things like:
Contribution guidelines:
dart format
.Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.