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 |
5 import 'dart:io'; | 6 import 'dart:io'; |
6 | 7 |
7 import '../pkg/path/lib/path.dart' as path; | 8 import '../pkg/path/lib/path.dart' as path; |
8 | 9 |
9 final oneLineBlock = new RegExp(r'^(\s*)/\*\*\s?(.*)\*/\s*$'); | 10 final oneLineBlock = new RegExp(r'^(\s*)/\*\*\s?(.*)\*/\s*$'); |
10 final startBlock = new RegExp(r'^(\s*)/\*\*(.*)$'); | 11 final startBlock = new RegExp(r'^(\s*)/\*\*(.*)$'); |
11 final blockLine = new RegExp(r'^\s*\*\s?(.*)$'); | 12 final blockLine = new RegExp(r'^\s*\*\s?(.*)$'); |
12 final endBlock = new RegExp(r'^\s*\*/\s*$'); | 13 final endBlock = new RegExp(r'^\s*\*/\s*$'); |
13 | 14 |
14 main(List<String> args) { | 15 main(List<String> args) { |
15 if (args.length != 1) { | 16 if (args.length != 1) { |
16 print('Converts "/**"-style block doc comments in a directory '); | 17 print('Converts "/**"-style block doc comments in a directory '); |
17 print('containing Dart code to "///"-style line doc comments.'); | 18 print('containing Dart code to "///"-style line doc comments.'); |
18 print(''); | 19 print(''); |
19 print('Usage: line_doc_coments.dart <dir>'); | 20 print('Usage: line_doc_coments.dart <dir>'); |
20 return; | 21 return; |
21 } | 22 } |
22 | 23 |
23 var dir = new Directory(args[0]); | 24 var dir = new Directory(args[0]); |
24 dir.list(recursive: true, followLinks: false).listen( | 25 dir.list(recursive: true, followLinks: false).listen((entity) { |
25 (entity) { | 26 if (entity is File) { |
26 if (entity is File) { | 27 var file = entity.path; |
27 var file = entity.path; | 28 if (path.extension(file) != '.dart') return; |
28 if (path.extension(file) != '.dart') return; | 29 fixFile(file); |
29 fixFile(file); | 30 } |
30 } | 31 }); |
31 }); | |
32 } | 32 } |
33 | 33 |
34 void fixFile(String path) { | 34 void fixFile(String path) { |
35 var file = new File(path); | 35 var file = new File(path); |
36 file.readAsLines().then((lines) => fixContents(lines, path)).then((fixed) { | 36 file.readAsLines().then((lines) => fixContents(lines, path)).then((fixed) { |
37 return new File(path).writeAsString(fixed); | 37 return new File(path).writeAsString(fixed); |
38 }).then((file) { | 38 }).then((file) { |
39 print(file.path); | 39 print(file.path); |
40 }); | 40 }); |
41 } | 41 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 print('$_PURPLE$path$_NO_COLOR:$_RED$linesOut$_NO_COLOR: ' | 109 print('$_PURPLE$path$_NO_COLOR:$_RED$linesOut$_NO_COLOR: ' |
110 'line exceeds 80 cols:\n $line'); | 110 'line exceeds 80 cols:\n $line'); |
111 } | 111 } |
112 | 112 |
113 buffer.write('$line\n'); | 113 buffer.write('$line\n'); |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 return buffer.toString(); | 117 return buffer.toString(); |
118 } | 118 } |
OLD | NEW |