@@ -24,7 +24,6 @@ import 'package:dartdoc/src/tuple.dart';
24
24
import 'package:dartdoc/src/utils.dart' ;
25
25
import 'package:dartdoc/src/version.dart' ;
26
26
import 'package:dartdoc/src/warnings.dart' ;
27
- import 'package:html/dom.dart' show Element, Document;
28
27
import 'package:html/parser.dart' show parse;
29
28
import 'package:path/path.dart' as path;
30
29
@@ -49,22 +48,22 @@ class DartdocFileWriter implements FileWriter {
49
48
final String outputDir;
50
49
final Map <String , Warnable > _fileElementMap = {};
51
50
@override
52
- final Set <String > writtenFiles = Set () ;
51
+ final Set <String > writtenFiles = {} ;
53
52
54
53
DartdocFileWriter (this .outputDir);
55
54
56
55
@override
57
56
void write (String filePath, Object content,
58
57
{bool allowOverwrite, Warnable element}) {
59
58
// Replace '/' separators with proper separators for the platform.
60
- String outFile = path.joinAll (filePath.split ('/' ));
59
+ var outFile = path.joinAll (filePath.split ('/' ));
61
60
62
61
allowOverwrite ?? = false ;
63
62
if (! allowOverwrite) {
64
63
if (_fileElementMap.containsKey (outFile)) {
65
64
assert (element != null ,
66
65
'Attempted overwrite of ${outFile } without corresponding element' );
67
- Warnable originalElement = _fileElementMap[outFile];
66
+ var originalElement = _fileElementMap[outFile];
68
67
Iterable <Warnable > referredFrom =
69
68
originalElement != null ? [originalElement] : null ;
70
69
element? .warn (PackageWarning .duplicateFile,
@@ -97,7 +96,7 @@ class DartdocFileWriter implements FileWriter {
97
96
/// directory.
98
97
class Dartdoc extends PackageBuilder {
99
98
final Generator generator;
100
- final Set <String > writtenFiles = Set () ;
99
+ final Set <String > writtenFiles = {} ;
101
100
Directory outputDir;
102
101
103
102
// Fires when the self checks make progress.
@@ -149,21 +148,21 @@ class Dartdoc extends PackageBuilder {
149
148
/// thrown if dartdoc fails in an expected way, for example if there is an
150
149
/// analysis error in the code.
151
150
Future <DartdocResults > generateDocsBase () async {
152
- Stopwatch _stopwatch = Stopwatch ()..start ();
151
+ var _stopwatch = Stopwatch ()..start ();
153
152
double seconds;
154
153
packageGraph = await buildPackageGraph ();
155
154
seconds = _stopwatch.elapsedMilliseconds / 1000.0 ;
156
- int libs = packageGraph.libraries.length;
155
+ var libs = packageGraph.libraries.length;
157
156
logInfo ("Initialized dartdoc with ${libs } librar${libs == 1 ? 'y' : 'ies' } "
158
- " in ${seconds .toStringAsFixed (1 )} seconds" );
157
+ ' in ${seconds .toStringAsFixed (1 )} seconds' );
159
158
_stopwatch.reset ();
160
159
161
160
final generator = this .generator;
162
161
if (generator != null ) {
163
162
// Create the out directory.
164
163
if (! outputDir.existsSync ()) outputDir.createSync (recursive: true );
165
164
166
- DartdocFileWriter writer = DartdocFileWriter (outputDir.path);
165
+ var writer = DartdocFileWriter (outputDir.path);
167
166
await generator.generate (packageGraph, writer);
168
167
169
168
writtenFiles.addAll (writer.writtenFiles);
@@ -172,10 +171,10 @@ class Dartdoc extends PackageBuilder {
172
171
}
173
172
}
174
173
175
- int warnings = packageGraph.packageWarningCounter.warningCount;
176
- int errors = packageGraph.packageWarningCounter.errorCount;
174
+ var warnings = packageGraph.packageWarningCounter.warningCount;
175
+ var errors = packageGraph.packageWarningCounter.errorCount;
177
176
if (warnings == 0 && errors == 0 ) {
178
- logInfo (" no issues found" );
177
+ logInfo (' no issues found' );
179
178
} else {
180
179
logWarning ("found ${warnings } ${pluralize ('warning' , warnings )} "
181
180
"and ${errors } ${pluralize ('error' , errors )}" );
@@ -184,23 +183,23 @@ class Dartdoc extends PackageBuilder {
184
183
seconds = _stopwatch.elapsedMilliseconds / 1000.0 ;
185
184
libs = packageGraph.localPublicLibraries.length;
186
185
logInfo ("Documented ${libs } public librar${libs == 1 ? 'y' : 'ies' } "
187
- " in ${seconds .toStringAsFixed (1 )} seconds" );
186
+ ' in ${seconds .toStringAsFixed (1 )} seconds' );
188
187
return DartdocResults (config.topLevelPackageMeta, packageGraph, outputDir);
189
188
}
190
189
191
190
Future <DartdocResults > generateDocs () async {
192
- logInfo (" Documenting ${config .topLevelPackageMeta }..." );
191
+ logInfo (' Documenting ${config .topLevelPackageMeta }...' );
193
192
194
- DartdocResults dartdocResults = await generateDocsBase ();
193
+ var dartdocResults = await generateDocsBase ();
195
194
if (dartdocResults.packageGraph.localPublicLibraries.isEmpty) {
196
- throw DartdocFailure (" dartdoc could not find any libraries to document" );
195
+ throw DartdocFailure (' dartdoc could not find any libraries to document' );
197
196
}
198
197
199
- final int errorCount =
198
+ final errorCount =
200
199
dartdocResults.packageGraph.packageWarningCounter.errorCount;
201
200
if (errorCount > 0 ) {
202
201
throw DartdocFailure (
203
- " dartdoc encountered $errorCount errors while processing." );
202
+ ' dartdoc encountered $errorCount errors while processing.' );
204
203
}
205
204
logInfo (
206
205
'Success! Docs generated into ${dartdocResults .outDir .absolute .path }' );
@@ -214,7 +213,7 @@ class Dartdoc extends PackageBuilder {
214
213
// Ordinarily this would go in [Package.warn], but we don't actually know what
215
214
// ModelElement to warn on yet.
216
215
Warnable warnOnElement;
217
- Set < Warnable > referredFromElements = Set () ;
216
+ var referredFromElements = < Warnable > {} ;
218
217
Set <Warnable > warnOnElements;
219
218
220
219
// Make all paths relative to origin.
@@ -247,20 +246,19 @@ class Dartdoc extends PackageBuilder {
247
246
if (referredFromElements.isEmpty && referredFrom == 'index.html' ) {
248
247
referredFromElements.add (packageGraph.defaultPackage);
249
248
}
250
- String message = warnOn;
249
+ var message = warnOn;
251
250
if (referredFrom == 'index.json' ) message = '$warnOn (from index.json)' ;
252
251
packageGraph.warnOnElement (warnOnElement, kind,
253
252
message: message, referredFrom: referredFromElements);
254
253
}
255
254
256
255
void _doOrphanCheck (
257
256
PackageGraph packageGraph, String origin, Set <String > visited) {
258
- String normalOrigin = path.normalize (origin);
259
- String staticAssets = path.joinAll ([normalOrigin, 'static-assets' , '' ]);
260
- String indexJson = path.joinAll ([normalOrigin, 'index.json' ]);
261
- bool foundIndexJson = false ;
262
- for (FileSystemEntity f
263
- in Directory (normalOrigin).listSync (recursive: true )) {
257
+ var normalOrigin = path.normalize (origin);
258
+ var staticAssets = path.joinAll ([normalOrigin, 'static-assets' , '' ]);
259
+ var indexJson = path.joinAll ([normalOrigin, 'index.json' ]);
260
+ var foundIndexJson = false ;
261
+ for (var f in Directory (normalOrigin).listSync (recursive: true )) {
264
262
var fullPath = path.normalize (f.path);
265
263
if (f is Directory ) {
266
264
continue ;
@@ -274,7 +272,7 @@ class Dartdoc extends PackageBuilder {
274
272
continue ;
275
273
}
276
274
if (visited.contains (fullPath)) continue ;
277
- String relativeFullPath = path.relative (fullPath, from: normalOrigin);
275
+ var relativeFullPath = path.relative (fullPath, from: normalOrigin);
278
276
if (! writtenFiles.contains (relativeFullPath)) {
279
277
// This isn't a file we wrote (this time); don't claim we did.
280
278
_warn (packageGraph, PackageWarning .unknownFile, fullPath, normalOrigin);
@@ -298,18 +296,18 @@ class Dartdoc extends PackageBuilder {
298
296
// This is extracted to save memory during the check; be careful not to hang
299
297
// on to anything referencing the full file and doc tree.
300
298
Tuple2 <Iterable <String >, String > _getStringLinksAndHref (String fullPath) {
301
- File file = File (" $fullPath " );
299
+ var file = File (' $fullPath ' );
302
300
if (! file.existsSync ()) {
303
301
return null ;
304
302
}
305
- Document doc = parse (file.readAsBytesSync ());
306
- Element base = doc.querySelector ('base' );
303
+ var doc = parse (file.readAsBytesSync ());
304
+ var base = doc.querySelector ('base' );
307
305
String baseHref;
308
306
if (base != null ) {
309
307
baseHref = base .attributes['href' ];
310
308
}
311
- List < Element > links = doc.querySelectorAll ('a' );
312
- List < String > stringLinks = links
309
+ var links = doc.querySelectorAll ('a' );
310
+ var stringLinks = links
313
311
.map ((link) => link.attributes['href' ])
314
312
.where ((href) => href != null )
315
313
.toList ();
@@ -319,23 +317,23 @@ class Dartdoc extends PackageBuilder {
319
317
320
318
void _doSearchIndexCheck (
321
319
PackageGraph packageGraph, String origin, Set <String > visited) {
322
- String fullPath = path.joinAll ([origin, 'index.json' ]);
323
- String indexPath = path.joinAll ([origin, 'index.html' ]);
324
- File file = File (" $fullPath " );
320
+ var fullPath = path.joinAll ([origin, 'index.json' ]);
321
+ var indexPath = path.joinAll ([origin, 'index.html' ]);
322
+ var file = File (' $fullPath ' );
325
323
if (! file.existsSync ()) {
326
324
return null ;
327
325
}
328
- JsonDecoder decoder = JsonDecoder ();
326
+ var decoder = JsonDecoder ();
329
327
List jsonData = decoder.convert (file.readAsStringSync ());
330
328
331
- Set < String > found = Set () ;
329
+ var found = < String > {} ;
332
330
found.add (fullPath);
333
331
// The package index isn't supposed to be in the search, so suppress the
334
332
// warning.
335
333
found.add (indexPath);
336
334
for (Map <String , dynamic > entry in jsonData) {
337
335
if (entry.containsKey ('href' )) {
338
- String entryPath = path.joinAll ([origin, entry['href' ]]);
336
+ var entryPath = path.joinAll ([origin, entry['href' ]]);
339
337
if (! visited.contains (entryPath)) {
340
338
_warn (packageGraph, PackageWarning .brokenLink, entryPath,
341
339
path.normalize (origin),
@@ -345,8 +343,8 @@ class Dartdoc extends PackageBuilder {
345
343
}
346
344
}
347
345
// Missing from search index
348
- Set < String > missing_from_search = visited.difference (found);
349
- for (String s in missing_from_search) {
346
+ var missing_from_search = visited.difference (found);
347
+ for (var s in missing_from_search) {
350
348
_warn (packageGraph, PackageWarning .missingFromSearchIndex, s,
351
349
path.normalize (origin),
352
350
referredFrom: fullPath);
@@ -380,10 +378,10 @@ class Dartdoc extends PackageBuilder {
380
378
// here instead -- occasionally, very large jobs have overflowed
381
379
// the stack without this.
382
380
// (newPathToCheck, newFullPath)
383
- Set <Tuple2 <String , String >> toVisit = Set () ;
381
+ var toVisit = < Tuple2 <String , String >> {} ;
384
382
385
- final RegExp ignoreHyperlinks = RegExp (r'^(https:|http:|mailto:|ftp:)' );
386
- for (String href in stringLinks) {
383
+ final ignoreHyperlinks = RegExp (r'^(https:|http:|mailto:|ftp:)' );
384
+ for (var href in stringLinks) {
387
385
if (! href.startsWith (ignoreHyperlinks)) {
388
386
Uri uri;
389
387
try {
@@ -400,7 +398,7 @@ class Dartdoc extends PackageBuilder {
400
398
full = '${path .dirname (pathToCheck )}/$href ' ;
401
399
}
402
400
var newPathToCheck = path.normalize (full);
403
- String newFullPath = path.joinAll ([origin, newPathToCheck]);
401
+ var newFullPath = path.joinAll ([origin, newPathToCheck]);
404
402
newFullPath = path.normalize (newFullPath);
405
403
if (! visited.contains (newFullPath)) {
406
404
toVisit.add (Tuple2 (newPathToCheck, newFullPath));
@@ -424,8 +422,8 @@ class Dartdoc extends PackageBuilder {
424
422
assert (_hrefs == null );
425
423
_hrefs = packageGraph.allHrefs;
426
424
427
- final Set < String > visited = Set () ;
428
- final String start = 'index.html' ;
425
+ final visited = < String > {} ;
426
+ final start = 'index.html' ;
429
427
logInfo ('Validating docs...' );
430
428
_doCheck (packageGraph, origin, visited, start);
431
429
_doOrphanCheck (packageGraph, origin, visited);
0 commit comments