OLD | NEW |
1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
2 | 2 |
3 /// Converts block-style Doc comments in Dart code to line style. | 3 /// Converts block-style Doc comments in Dart code to line style. |
4 library line_doc_comments; | 4 library line_doc_comments; |
5 import 'dart:io'; | 5 import 'dart:io'; |
6 | 6 |
7 import '../pkg/path/lib/path.dart' as path; | 7 import '../pkg/path/lib/path.dart' as path; |
8 | 8 |
9 final oneLineBlock = new RegExp(r'^(\s*)/\*\*\s?(.*)\*/\s*$'); | 9 final oneLineBlock = new RegExp(r'^(\s*)/\*\*\s?(.*)\*/\s*$'); |
10 final startBlock = new RegExp(r'^(\s*)/\*\*(.*)$'); | 10 final startBlock = new RegExp(r'^(\s*)/\*\*(.*)$'); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 var oldLine = line; | 50 var oldLine = line; |
51 if (inBlock) { | 51 if (inBlock) { |
52 // See if it's the end of the comment. | 52 // See if it's the end of the comment. |
53 if (endBlock.hasMatch(line)) { | 53 if (endBlock.hasMatch(line)) { |
54 inBlock = false; | 54 inBlock = false; |
55 | 55 |
56 // Just a pointless line, delete it! | 56 // Just a pointless line, delete it! |
57 line = null; | 57 line = null; |
58 } else { | 58 } else { |
59 var match = blockLine.firstMatch(line); | 59 var match = blockLine.firstMatch(line); |
60 var comment = match[1]; | 60 if (match != null) { |
61 if (comment != '') { | 61 var comment = match[1]; |
62 line = '$indent/// $comment'; | 62 if (comment != '') { |
63 } else { | 63 line = '$indent/// $comment'; |
64 line = '$indent///'; | 64 } else { |
| 65 line = '$indent///'; |
| 66 } |
65 } | 67 } |
66 } | 68 } |
67 } else { | 69 } else { |
68 // See if it's a one-line block comment like: /** Blah. */ | 70 // See if it's a one-line block comment like: /** Blah. */ |
69 var match = oneLineBlock.firstMatch(line); | 71 var match = oneLineBlock.firstMatch(line); |
70 if (match != null) { | 72 if (match != null) { |
71 var comment = match[2]; | 73 var comment = match[2]; |
72 if (comment != '') { | 74 if (comment != '') { |
73 // Remove the extra space before the `*/` | 75 // Remove the extra space before the `*/` |
74 if (comment.endsWith(' ')) { | 76 if (comment.endsWith(' ')) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 print('$_PURPLE$path$_NO_COLOR:$_RED$linesOut$_NO_COLOR: ' | 109 print('$_PURPLE$path$_NO_COLOR:$_RED$linesOut$_NO_COLOR: ' |
108 'line exceeds 80 cols:\n $line'); | 110 'line exceeds 80 cols:\n $line'); |
109 } | 111 } |
110 | 112 |
111 buffer.write('$line\n'); | 113 buffer.write('$line\n'); |
112 } | 114 } |
113 } | 115 } |
114 | 116 |
115 return buffer.toString(); | 117 return buffer.toString(); |
116 } | 118 } |
OLD | NEW |