Skip to content

Commit

Permalink
Add more tests for doc comment fix and fix an edge case. (#741)
Browse files Browse the repository at this point in the history
A line that didn't have a leading "*" but did have a "*" elsewhere in
the line would have everything before the "*" trimmed.
  • Loading branch information
munificent committed Sep 17, 2018
1 parent 6622671 commit 011ac71
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/src/chunk_builder.dart
Expand Up @@ -22,8 +22,8 @@ final _trailingIdentifierChar = new RegExp(r"[a-zA-Z0-9_]$");
/// "*/" or "**/". /// "*/" or "**/".
final _javaDocComment = new RegExp(r"^/\*\*([^*/][\s\S]*?)\*?\*/$"); final _javaDocComment = new RegExp(r"^/\*\*([^*/][\s\S]*?)\*?\*/$");


/// Matches an intermediate "*" line in the middle of a JavaDoc-style comment. /// Matches the leading "*" in a line in the middle of a JavaDoc-style comment.
var _javaDocLine = new RegExp(r"\s*\*(.*)"); var _javaDocLine = new RegExp(r"^\s*\*(.*)");


/// Takes the incremental serialized output of [SourceVisitor]--the source text /// Takes the incremental serialized output of [SourceVisitor]--the source text
/// along with any comments and preserved whitespace--and produces a coherent /// along with any comments and preserved whitespace--and produces a coherent
Expand Down Expand Up @@ -357,13 +357,9 @@ class ChunkBuilder {
return; return;
} }


// Trim the first and last lines if empty.
var lines = match.group(1).split("\n").toList();
if (lines.first.trim().isEmpty) lines.removeAt(0);
if (lines.isNotEmpty && lines.last.trim().isEmpty) lines.removeLast();

// Remove a leading "*" from the middle lines. // Remove a leading "*" from the middle lines.
for (var i = 0; i < lines.length; i++) { var lines = match.group(1).split("\n").toList();
for (var i = 1; i < lines.length - 1; i++) {
var line = lines[i]; var line = lines[i];
var match = _javaDocLine.firstMatch(line); var match = _javaDocLine.firstMatch(line);
if (match != null) { if (match != null) {
Expand All @@ -376,6 +372,10 @@ class ChunkBuilder {
lines[i] = line; lines[i] = line;
} }


// Trim the first and last lines if empty.
if (lines.first.trim().isEmpty) lines.removeAt(0);
if (lines.isNotEmpty && lines.last.trim().isEmpty) lines.removeLast();

// Don't completely eliminate an empty block comment. // Don't completely eliminate an empty block comment.
if (lines.isEmpty) lines.add(""); if (lines.isEmpty) lines.add("");


Expand Down
46 changes: 46 additions & 0 deletions test/fixes/doc_comments.stmt
Expand Up @@ -110,4 +110,50 @@ m() {}
/******* /*******
* STUFF * STUFF
*******/ *******/
m() {}
>>> nested comment
/**
* Floo the grumshack.
*
* Example:
* ```dart
* /** Doc comment */
* var grumshack = getGrumshack();
* /* Do the floo */
* grumshack.floo();
* ```
*/
m() {}
<<<
/// Floo the grumshack.
///
/// Example:
/// ```dart
/// /** Doc comment */
/// var grumshack = getGrumshack();
/// /* Do the floo */
/// grumshack.floo();
/// ```
m() {}
>>>
/** Does a [foo](http://example.org/*example*/doc). **/
m() {}
<<<
/// Does a [foo](http://example.org/*example*/doc).
m() {}
>>>
/** Does a [foo](http://example.org/*example*/doc). */
m() {}
<<<
/// Does a [foo](http://example.org/*example*/doc).
m() {}
>>> non-leading "*"
/**
* Thing.
Another * thing.
*/
m() {}
<<<
/// Thing.
/// Another * thing.
m() {} m() {}

0 comments on commit 011ac71

Please sign in to comment.