Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: tool/doc.dart

Issue 1710213003: Doc generation improvements. (Closed) Base URL: https://github.com/dart-lang/linter.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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';
(...skipping 20 matching lines...) Expand all
31 print("Directory '${d.path}' does not exist"); 31 print("Directory '${d.path}' does not exist");
32 return; 32 return;
33 } 33 }
34 } 34 }
35 35
36 // Generate index 36 // Generate index
37 new Indexer(ruleRegistry).generate(outDir); 37 new Indexer(ruleRegistry).generate(outDir);
38 38
39 // Generate rule files 39 // Generate rule files
40 rules.forEach((l) => new Generator(l).generate(outDir)); 40 rules.forEach((l) => new Generator(l).generate(outDir));
41
42 // Generate options samples.
43 new OptionsSample(rules).generate(outDir);
41 } 44 }
42 45
43 const ruleFootMatter = ''' 46 const ruleFootMatter = '''
44 In addition, rules can be further distinguished by *maturity*. Unqualified 47 In addition, rules can be further distinguished by *maturity*. Unqualified
45 rules are considered stable, while others may be marked **experimental** 48 rules are considered stable, while others may be marked **experimental**
46 to indicate that they are under review. 49 to indicate that they are under review.
47 50
51 Rules can be selectively enabled in the analyzer using
52 [analysis options](https://pub.dartlang.org/packages/analyzer). An
53 auto-generated list enabling all options is provided
54 [here](options/options.html). As some lints may contradict each other, only
55 some lints will be enabled in practice, but this list should provide a
56 convenient jumping-off point.
57
48 These rules are under active development. Feedback is 58 These rules are under active development. Feedback is
49 [welcome](https://github.com/dart-lang/linter/issues)! 59 [welcome](https://github.com/dart-lang/linter/issues)!
50 '''; 60 ''';
51 61
52 const ruleLeadMatter = 'Rules are organized into familiar rule groups.'; 62 const ruleLeadMatter = 'Rules are organized into familiar rule groups.';
53 63
54 /// Sorted list of contributed lint rules. 64 /// Sorted list of contributed lint rules.
55 final List<LintRule> rules = 65 final List<LintRule> rules =
56 new List<LintRule>.from(ruleRegistry, growable: false)..sort(); 66 new List<LintRule>.from(ruleRegistry, growable: false)..sort();
57 67
(...skipping 10 matching lines...) Expand all
68 String get enumeratePubRules => rules 78 String get enumeratePubRules => rules
69 .where((r) => r.group == Group.pub) 79 .where((r) => r.group == Group.pub)
70 .map((r) => '${toDescription(r)}') 80 .map((r) => '${toDescription(r)}')
71 .join('\n\n'); 81 .join('\n\n');
72 82
73 String get enumerateStyleRules => rules 83 String get enumerateStyleRules => rules
74 .where((r) => r.group == Group.style) 84 .where((r) => r.group == Group.style)
75 .map((r) => '${toDescription(r)}') 85 .map((r) => '${toDescription(r)}')
76 .join('\n\n'); 86 .join('\n\n');
77 87
88 List<String> get sortedRules => rules.map((r) => r.name).toList()..sort();
89
78 void printUsage(ArgParser parser, [String error]) { 90 void printUsage(ArgParser parser, [String error]) {
79 var message = 'Generates lint docs.'; 91 var message = 'Generates lint docs.';
80 if (error != null) { 92 if (error != null) {
81 message = error; 93 message = error;
82 } 94 }
83 95
84 stdout.write('''$message 96 stdout.write('''$message
85 Usage: doc 97 Usage: doc
86 ${parser.usage} 98 ${parser.usage}
87 '''); 99 ''');
88 } 100 }
89 101
90 String qualify(LintRule r) => r.name.toString() + 102 String qualify(LintRule r) =>
103 r.name.toString() +
91 (r.maturity == Maturity.stable ? '' : ' (${r.maturity.name})'); 104 (r.maturity == Maturity.stable ? '' : ' (${r.maturity.name})');
92 105
93 String toDescription(LintRule r) => 106 String toDescription(LintRule r) =>
94 '<strong><a href = "${r.name}.html">${qualify(r)}</a></strong><br/>${markdow nToHtml(r.description)}'; 107 '<strong><a href = "${r.name}.html">${qualify(r)}</a></strong><br/>${markdow nToHtml(r.description)}';
95 108
96 class Generator { 109 class Generator {
97 LintRule rule; 110 LintRule rule;
98 Generator(this.rule); 111 Generator(this.rule);
99 112
100 String get details => rule.details ?? ''; 113 String get details => rule.details ?? '';
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 <h1>$humanReadableName</h1> 148 <h1>$humanReadableName</h1>
136 <p>Group: $group</p> 149 <p>Group: $group</p>
137 <p>Maturity: $maturity</p> 150 <p>Maturity: $maturity</p>
138 <p class="view"><a href="https://github.com/dart-lang/linter">View t he Project on GitHub <small>dart-lang/linter</small></a></p> 151 <p class="view"><a href="https://github.com/dart-lang/linter">View t he Project on GitHub <small>dart-lang/linter</small></a></p>
139 <ul> 152 <ul>
140 <li><a href="https://www.dartlang.org/articles/style-guide/">See the <strong>Style Guide</strong></a></li> 153 <li><a href="https://www.dartlang.org/articles/style-guide/">See the <strong>Style Guide</strong></a></li>
141 <li><a href="http://dart-lang.github.io/linter/lints/">List of <s trong>Lint Rules</strong></a></li> 154 <li><a href="http://dart-lang.github.io/linter/lints/">List of <s trong>Lint Rules</strong></a></li>
142 </ul> 155 </ul>
143 </header> 156 </header>
144 <section> 157 <section>
145 158
146 ${markdownToHtml(details)} 159 ${markdownToHtml(details)}
147 160
148 </section> 161 </section>
149 </div> 162 </div>
150 <footer> 163 <footer>
151 <p>Project maintained by <a href="https://github.com/dart-lang">dart-la ng</a></p> 164 <p>Project maintained by <a href="https://github.com/dart-lang">dart-la ng</a></p>
152 <p>Hosted on GitHub Pages &mdash; Theme by <a href="https://github.com/ orderedlist">orderedlist</a></p> 165 <p>Hosted on GitHub Pages &mdash; Theme by <a href="https://github.com/ orderedlist">orderedlist</a></p>
153 </footer> 166 </footer>
154 <!--[if !IE]><script>fixScale(document);</script><![endif]--> 167 <!--[if !IE]><script>fixScale(document);</script><![endif]-->
155 </body> 168 </body>
156 </html> 169 </html>
157 '''; 170 ''';
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 234
222 $enumerateErrorRules 235 $enumerateErrorRules
223 236
224 <h2 id="styleguide-rules">Style Rules</h2> 237 <h2 id="styleguide-rules">Style Rules</h2>
225 238
226 $enumerateStyleRules 239 $enumerateStyleRules
227 240
228 <h2 id="styleguide-rules">Pub Rules</h2> 241 <h2 id="styleguide-rules">Pub Rules</h2>
229 242
230 $enumeratePubRules 243 $enumeratePubRules
231 244
232 </section> 245 </section>
233 </div> 246 </div>
234 <footer> 247 <footer>
248 <p>Project maintained by <a href="https://github.com/google">google</a> </p>
249 <p>Hosted on GitHub Pages &mdash; Theme by <a href="https://github.com/ orderedlist">orderedlist</a></p>
250 </footer>
251 <!--[if !IE]><script>fixScale(document);</script><![endif]-->
252 <script type="text/javascript">
253 var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl ." : "http://www.");
254 document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytic s.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
255 </script>
256 <script type="text/javascript">
257 try {
258 var pageTracker = _gat._getTracker("UA-34425814-2");
259 pageTracker._trackPageview();
260 } catch(err) {}
261 </script>
262 </body>
263 </html>
264 ''';
265 }
266
267 class OptionsSample {
268 Iterable<LintRule> rules;
269 OptionsSample(this.rules);
270
271 generate(String filePath) {
272 var generated = _generate();
273 if (filePath != null) {
274 var outPath = '$filePath/options/options.html';
275 print('Writing to $outPath');
276 new File(outPath).writeAsStringSync(generated);
277 } else {
278 print(generated);
279 }
280 }
281
282 String generateOptions() {
283 StringBuffer sb = new StringBuffer('''
284 ```
285 linter:
286 rules:
287 ''');
288 for (String rule in sortedRules) {
289 sb.write(' - $rule\n');
290 }
291 sb.write('```');
292
293 return sb.toString();
294 }
295
296 String _generate() => '''
297 <!doctype html>
298 <html>
299 <head>
300 <meta charset="utf-8">
301 <meta http-equiv="X-UA-Compatible" content="chrome=1">
302 <title>Analysis Options</title>
303 <link rel="stylesheet" href="../../stylesheets/styles.css">
304 <link rel="stylesheet" href="../../stylesheets/pygment_trac.css">
305 <script src="../../javascripts/scale.fix.js"></script>
306 <meta name="viewport" content="width=device-width, initial-scale=1, user-s calable=no">
307 <!--[if lt IE 9]>
308 <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
309 <![endif]-->
310 </head>
311 <body>
312 <div class="wrapper">
313 <header>
314 <a href="http://dart-lang.github.io/linter/">
315 <h1>Dart Lint</h1>
316 </a>
317 <p>Analysis Options</p>
318 <p class="view"><a href="https://github.com/dart-lang/linter">View t he Project on GitHub <small>dart-lang/linter</small></a></p>
319 <ul>
320 <li><a href="http://dart-lang.github.io/linter/lints/">List of <st rong>Lint Rules</strong></a></li>
321 <li><a href="https://github.com/dart-lang/linter">View On <strong> GitHub</strong></a></li>
322 </ul>
323 </header>
324 <section>
325
326 <h1 id="analysis-options">Analysis Options</h1>
327 <p>
328 Auto-generated options enabling all lints; tailor to fit!
329 </p>
330
331 ${markdownToHtml(generateOptions())}
332
333 </section>
334 </div>
335 <footer>
235 <p>Project maintained by <a href="https://github.com/google">google</a> </p> 336 <p>Project maintained by <a href="https://github.com/google">google</a> </p>
236 <p>Hosted on GitHub Pages &mdash; Theme by <a href="https://github.com/ orderedlist">orderedlist</a></p> 337 <p>Hosted on GitHub Pages &mdash; Theme by <a href="https://github.com/ orderedlist">orderedlist</a></p>
237 </footer> 338 </footer>
238 <!--[if !IE]><script>fixScale(document);</script><![endif]--> 339 <!--[if !IE]><script>fixScale(document);</script><![endif]-->
239 <script type="text/javascript"> 340 <script type="text/javascript">
240 var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl ." : "http://www."); 341 var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl ." : "http://www.");
241 document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytic s.com/ga.js' type='text/javascript'%3E%3C/script%3E")); 342 document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytic s.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
242 </script> 343 </script>
243 <script type="text/javascript"> 344 <script type="text/javascript">
244 try { 345 try {
245 var pageTracker = _gat._getTracker("UA-34425814-2"); 346 var pageTracker = _gat._getTracker("UA-34425814-2");
246 pageTracker._trackPageview(); 347 pageTracker._trackPageview();
247 } catch(err) {} 348 } catch(err) {}
248 </script> 349 </script>
249 </body> 350 </body>
250 </html> 351 </html>
251 '''; 352 ''';
252 } 353 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698