Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Commit 659448d

Browse files
committed
Doc generation improvements.
Besides a bit of cleanup, introduces an options file template. BUG= [email protected] Review URL: https://codereview.chromium.org//1710213003 .
1 parent 242de4b commit 659448d

File tree

1 file changed

+105
-4
lines changed

1 file changed

+105
-4
lines changed

tool/doc.dart

Lines changed: 105 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,23 @@ void main([args]) {
3838

3939
// Generate rule files
4040
rules.forEach((l) => new Generator(l).generate(outDir));
41+
42+
// Generate options samples.
43+
new OptionsSample(rules).generate(outDir);
4144
}
4245

4346
const ruleFootMatter = '''
4447
In addition, rules can be further distinguished by *maturity*. Unqualified
4548
rules are considered stable, while others may be marked **experimental**
4649
to indicate that they are under review.
4750
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+
4858
These rules are under active development. Feedback is
4959
[welcome](https://github.com/dart-lang/linter/issues)!
5060
''';
@@ -75,6 +85,8 @@ String get enumerateStyleRules => rules
7585
.map((r) => '${toDescription(r)}')
7686
.join('\n\n');
7787

88+
List<String> get sortedRules => rules.map((r) => r.name).toList()..sort();
89+
7890
void printUsage(ArgParser parser, [String error]) {
7991
var message = 'Generates lint docs.';
8092
if (error != null) {
@@ -87,7 +99,8 @@ ${parser.usage}
8799
''');
88100
}
89101

90-
String qualify(LintRule r) => r.name.toString() +
102+
String qualify(LintRule r) =>
103+
r.name.toString() +
91104
(r.maturity == Maturity.stable ? '' : ' (${r.maturity.name})');
92105

93106
String toDescription(LintRule r) =>
@@ -142,9 +155,9 @@ class Generator {
142155
</ul>
143156
</header>
144157
<section>
145-
158+
146159
${markdownToHtml(details)}
147-
160+
148161
</section>
149162
</div>
150163
<footer>
@@ -228,7 +241,95 @@ class Indexer {
228241
<h2 id="styleguide-rules">Pub Rules</h2>
229242
230243
$enumeratePubRules
231-
244+
245+
</section>
246+
</div>
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-analytics.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-scalable=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 the 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 <strong>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+
232333
</section>
233334
</div>
234335
<footer>

0 commit comments

Comments
 (0)