@@ -273,12 +273,8 @@ class Dartdoc {
273
273
referredFromElements.removeWhere ((e) => ! e.isCanonical);
274
274
}
275
275
if (warnOnElements != null ) {
276
- if (warnOnElements.any ((e) => e.isCanonical)) {
277
- warnOnElement = warnOnElements.firstWhere ((e) => e.isCanonical);
278
- } else {
279
- // If we don't have a canonical element, just pick one.
280
- warnOnElement = warnOnElements.isEmpty ? null : warnOnElements.first;
281
- }
276
+ warnOnElement = warnOnElements.firstWhere ((e) => e.isCanonical,
277
+ orElse: () => warnOnElements.isEmpty ? null : warnOnElements.first);
282
278
}
283
279
284
280
if (referredFromElements.isEmpty && referredFrom == 'index.html' ) {
@@ -321,8 +317,7 @@ class Dartdoc {
321
317
} else {
322
318
// Error messages are orphaned by design and do not appear in the search
323
319
// index.
324
- if (< String > ['__404error.html' , 'categories.json' ]
325
- .contains (fullPath)) {
320
+ if (const {'__404error.html' , 'categories.json' }.contains (fullPath)) {
326
321
_warn (packageGraph, PackageWarning .orphanedFile, fullPath,
327
322
normalOrigin);
328
323
}
@@ -342,7 +337,7 @@ class Dartdoc {
342
337
// This is extracted to save memory during the check; be careful not to hang
343
338
// on to anything referencing the full file and doc tree.
344
339
Tuple2 <Iterable <String >, String > _getStringLinksAndHref (String fullPath) {
345
- var file = config.resourceProvider.getFile ('$ fullPath ' );
340
+ var file = config.resourceProvider.getFile (fullPath);
346
341
if (! file.exists) {
347
342
return null ;
348
343
}
@@ -368,7 +363,7 @@ class Dartdoc {
368
363
PackageGraph packageGraph, String origin, Set <String > visited) {
369
364
var fullPath = path.joinAll ([origin, 'index.json' ]);
370
365
var indexPath = path.joinAll ([origin, 'index.html' ]);
371
- var file = config.resourceProvider.getFile ('$ fullPath ' );
366
+ var file = config.resourceProvider.getFile (fullPath);
372
367
if (! file.exists) {
373
368
return null ;
374
369
}
@@ -403,10 +398,7 @@ class Dartdoc {
403
398
void _doCheck (PackageGraph packageGraph, String origin, Set <String > visited,
404
399
String pathToCheck,
405
400
[String source, String fullPath]) {
406
- if (fullPath == null ) {
407
- fullPath = path.joinAll ([origin, pathToCheck]);
408
- fullPath = path.normalize (fullPath);
409
- }
401
+ fullPath ?? = path.normalize (path.joinAll ([origin, pathToCheck]));
410
402
411
403
var stringLinksAndHref = _getStringLinksAndHref (fullPath);
412
404
if (stringLinksAndHref == null ) {
@@ -430,14 +422,9 @@ class Dartdoc {
430
422
var toVisit = < Tuple2 <String , String >> {};
431
423
432
424
final ignoreHyperlinks = RegExp (r'^(https:|http:|mailto:|ftp:)' );
433
- for (var href in stringLinks) {
425
+ for (final href in stringLinks) {
434
426
if (! href.startsWith (ignoreHyperlinks)) {
435
- Uri uri;
436
- try {
437
- uri = Uri .parse (href);
438
- } on FormatException {
439
- // ignore
440
- }
427
+ final uri = Uri .tryParse (href);
441
428
442
429
if (uri == null || ! uri.hasAuthority && ! uri.hasFragment) {
443
430
String full;
@@ -446,9 +433,10 @@ class Dartdoc {
446
433
} else {
447
434
full = '${path .dirname (pathToCheck )}/$href ' ;
448
435
}
449
- var newPathToCheck = path.normalize (full);
450
- var newFullPath = path.joinAll ([origin, newPathToCheck]);
451
- newFullPath = path.normalize (newFullPath);
436
+
437
+ final newPathToCheck = path.normalize (full);
438
+ final newFullPath =
439
+ path.normalize (path.joinAll ([origin, newPathToCheck]));
452
440
if (! visited.contains (newFullPath)) {
453
441
toVisit.add (Tuple2 (newPathToCheck, newFullPath));
454
442
visited.add (newFullPath);
@@ -472,9 +460,8 @@ class Dartdoc {
472
460
_hrefs = packageGraph.allHrefs;
473
461
474
462
final visited = < String > {};
475
- final start = 'index.html' ;
476
463
logInfo ('Validating docs...' );
477
- _doCheck (packageGraph, origin, visited, start );
464
+ _doCheck (packageGraph, origin, visited, 'index.html' );
478
465
_doOrphanCheck (packageGraph, origin, visited);
479
466
_doSearchIndexCheck (packageGraph, origin, visited);
480
467
}
0 commit comments