| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:io'; | 5 import 'dart:io'; |
| 6 | 6 |
| 7 import 'package:args/args.dart'; | 7 import 'package:args/args.dart'; |
| 8 import 'package:linter/src/linter.dart'; | 8 import 'package:linter/src/linter.dart'; |
| 9 import 'package:linter/src/rules.dart'; | 9 import 'package:linter/src/rules.dart'; |
| 10 import 'package:markdown/markdown.dart'; | 10 import 'package:markdown/markdown.dart'; |
| 11 | 11 |
| 12 /// Generates lint rule docs for publishing to http://dart-lang.github.io/ | 12 /// Generates lint rule docs for publishing to http://dart-lang.github.io/ |
| 13 void main([List<String> args]) { | 13 void main([List<String> args]) { |
| 14 var parser = new ArgParser(allowTrailingOptions: true); | 14 var parser = new ArgParser(allowTrailingOptions: true); |
| 15 | 15 |
| 16 parser.addOption('out', abbr: 'o', help: 'Specifies output directory.'); | 16 parser.addOption('out', abbr: 'o', help: 'Specifies output directory.'); |
| 17 | 17 |
| 18 var options; | 18 var options; |
| 19 try { | 19 try { |
| 20 options = parser.parse(args); | 20 options = parser.parse(args); |
| 21 } on FormatException catch (err) { | 21 } on FormatException catch (err) { |
| 22 printUsage(parser, err.message); | 22 printUsage(parser, err.message); |
| 23 return; | 23 return; |
| 24 } | 24 } |
| 25 | 25 |
| 26 var outDir = options['out']; | 26 var outDir = options['out']; |
| 27 | 27 generateDocs(outDir); |
| 28 if (outDir != null) { | |
| 29 Directory d = new Directory(outDir); | |
| 30 if (!d.existsSync()) { | |
| 31 print("Directory '${d.path}' does not exist"); | |
| 32 return; | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 // Generate index | |
| 37 new Indexer(ruleRegistry).generate(outDir); | |
| 38 | |
| 39 // Generate rule files | |
| 40 rules.forEach((l) => new Generator(l).generate(outDir)); | |
| 41 | |
| 42 // Generate options samples. | |
| 43 new OptionsSample(rules).generate(outDir); | |
| 44 } | 28 } |
| 45 | 29 |
| 46 const ruleFootMatter = ''' | 30 const ruleFootMatter = ''' |
| 47 In addition, rules can be further distinguished by *maturity*. Unqualified | 31 In addition, rules can be further distinguished by *maturity*. Unqualified |
| 48 rules are considered stable, while others may be marked **experimental** | 32 rules are considered stable, while others may be marked **experimental** |
| 49 to indicate that they are under review. | 33 to indicate that they are under review. |
| 50 | 34 |
| 51 Rules can be selectively enabled in the analyzer using | 35 Rules can be selectively enabled in the analyzer using |
| 52 [analysis options](https://pub.dartlang.org/packages/analyzer). An | 36 [analysis options](https://pub.dartlang.org/packages/analyzer). An |
| 53 auto-generated list enabling all options is provided | 37 auto-generated list enabling all options is provided |
| (...skipping 26 matching lines...) Expand all Loading... |
| 80 .map((r) => '${toDescription(r)}') | 64 .map((r) => '${toDescription(r)}') |
| 81 .join('\n\n'); | 65 .join('\n\n'); |
| 82 | 66 |
| 83 String get enumerateStyleRules => rules | 67 String get enumerateStyleRules => rules |
| 84 .where((r) => r.group == Group.style) | 68 .where((r) => r.group == Group.style) |
| 85 .map((r) => '${toDescription(r)}') | 69 .map((r) => '${toDescription(r)}') |
| 86 .join('\n\n'); | 70 .join('\n\n'); |
| 87 | 71 |
| 88 List<String> get sortedRules => rules.map((r) => r.name).toList()..sort(); | 72 List<String> get sortedRules => rules.map((r) => r.name).toList()..sort(); |
| 89 | 73 |
| 74 void generateDocs(String outDir) { |
| 75 if (outDir != null) { |
| 76 Directory d = new Directory(outDir); |
| 77 if (!d.existsSync()) { |
| 78 print("Directory '${d.path}' does not exist"); |
| 79 return; |
| 80 } |
| 81 } |
| 82 |
| 83 // Generate index |
| 84 new Indexer(ruleRegistry).generate(outDir); |
| 85 |
| 86 // Generate rule files |
| 87 rules.forEach((l) => new Generator(l).generate(outDir)); |
| 88 |
| 89 // Generate options samples. |
| 90 new OptionsSample(rules).generate(outDir); |
| 91 } |
| 92 |
| 90 void printUsage(ArgParser parser, [String error]) { | 93 void printUsage(ArgParser parser, [String error]) { |
| 91 var message = 'Generates lint docs.'; | 94 var message = 'Generates lint docs.'; |
| 92 if (error != null) { | 95 if (error != null) { |
| 93 message = error; | 96 message = error; |
| 94 } | 97 } |
| 95 | 98 |
| 96 stdout.write('''$message | 99 stdout.write('''$message |
| 97 Usage: doc | 100 Usage: doc |
| 98 ${parser.usage} | 101 ${parser.usage} |
| 99 '''); | 102 '''); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 <script type="text/javascript"> | 347 <script type="text/javascript"> |
| 345 try { | 348 try { |
| 346 var pageTracker = _gat._getTracker("UA-34425814-2"); | 349 var pageTracker = _gat._getTracker("UA-34425814-2"); |
| 347 pageTracker._trackPageview(); | 350 pageTracker._trackPageview(); |
| 348 } catch(err) {} | 351 } catch(err) {} |
| 349 </script> | 352 </script> |
| 350 </body> | 353 </body> |
| 351 </html> | 354 </html> |
| 352 '''; | 355 '''; |
| 353 } | 356 } |
| OLD | NEW |