@@ -24,7 +24,6 @@ import 'package:dartdoc/src/tuple.dart';
2424import 'package:dartdoc/src/utils.dart' ;
2525import 'package:dartdoc/src/version.dart' ;
2626import 'package:dartdoc/src/warnings.dart' ;
27- import 'package:html/dom.dart' show Element, Document;
2827import 'package:html/parser.dart' show parse;
2928import 'package:path/path.dart' as path;
3029
@@ -49,22 +48,22 @@ class DartdocFileWriter implements FileWriter {
4948 final String outputDir;
5049 final Map <String , Warnable > _fileElementMap = {};
5150 @override
52- final Set <String > writtenFiles = Set () ;
51+ final Set <String > writtenFiles = {} ;
5352
5453 DartdocFileWriter (this .outputDir);
5554
5655 @override
5756 void write (String filePath, Object content,
5857 {bool allowOverwrite, Warnable element}) {
5958 // Replace '/' separators with proper separators for the platform.
60- String outFile = path.joinAll (filePath.split ('/' ));
59+ var outFile = path.joinAll (filePath.split ('/' ));
6160
6261 allowOverwrite ?? = false ;
6362 if (! allowOverwrite) {
6463 if (_fileElementMap.containsKey (outFile)) {
6564 assert (element != null ,
6665 'Attempted overwrite of ${outFile } without corresponding element' );
67- Warnable originalElement = _fileElementMap[outFile];
66+ var originalElement = _fileElementMap[outFile];
6867 Iterable <Warnable > referredFrom =
6968 originalElement != null ? [originalElement] : null ;
7069 element? .warn (PackageWarning .duplicateFile,
@@ -97,7 +96,7 @@ class DartdocFileWriter implements FileWriter {
9796/// directory.
9897class Dartdoc extends PackageBuilder {
9998 final Generator generator;
100- final Set <String > writtenFiles = Set () ;
99+ final Set <String > writtenFiles = {} ;
101100 Directory outputDir;
102101
103102 // Fires when the self checks make progress.
@@ -149,21 +148,21 @@ class Dartdoc extends PackageBuilder {
149148 /// thrown if dartdoc fails in an expected way, for example if there is an
150149 /// analysis error in the code.
151150 Future <DartdocResults > generateDocsBase () async {
152- Stopwatch _stopwatch = Stopwatch ()..start ();
151+ var _stopwatch = Stopwatch ()..start ();
153152 double seconds;
154153 packageGraph = await buildPackageGraph ();
155154 seconds = _stopwatch.elapsedMilliseconds / 1000.0 ;
156- int libs = packageGraph.libraries.length;
155+ var libs = packageGraph.libraries.length;
157156 logInfo ("Initialized dartdoc with ${libs } librar${libs == 1 ? 'y' : 'ies' } "
158- " in ${seconds .toStringAsFixed (1 )} seconds" );
157+ ' in ${seconds .toStringAsFixed (1 )} seconds' );
159158 _stopwatch.reset ();
160159
161160 final generator = this .generator;
162161 if (generator != null ) {
163162 // Create the out directory.
164163 if (! outputDir.existsSync ()) outputDir.createSync (recursive: true );
165164
166- DartdocFileWriter writer = DartdocFileWriter (outputDir.path);
165+ var writer = DartdocFileWriter (outputDir.path);
167166 await generator.generate (packageGraph, writer);
168167
169168 writtenFiles.addAll (writer.writtenFiles);
@@ -172,10 +171,10 @@ class Dartdoc extends PackageBuilder {
172171 }
173172 }
174173
175- int warnings = packageGraph.packageWarningCounter.warningCount;
176- int errors = packageGraph.packageWarningCounter.errorCount;
174+ var warnings = packageGraph.packageWarningCounter.warningCount;
175+ var errors = packageGraph.packageWarningCounter.errorCount;
177176 if (warnings == 0 && errors == 0 ) {
178- logInfo (" no issues found" );
177+ logInfo (' no issues found' );
179178 } else {
180179 logWarning ("found ${warnings } ${pluralize ('warning' , warnings )} "
181180 "and ${errors } ${pluralize ('error' , errors )}" );
@@ -184,23 +183,23 @@ class Dartdoc extends PackageBuilder {
184183 seconds = _stopwatch.elapsedMilliseconds / 1000.0 ;
185184 libs = packageGraph.localPublicLibraries.length;
186185 logInfo ("Documented ${libs } public librar${libs == 1 ? 'y' : 'ies' } "
187- " in ${seconds .toStringAsFixed (1 )} seconds" );
186+ ' in ${seconds .toStringAsFixed (1 )} seconds' );
188187 return DartdocResults (config.topLevelPackageMeta, packageGraph, outputDir);
189188 }
190189
191190 Future <DartdocResults > generateDocs () async {
192- logInfo (" Documenting ${config .topLevelPackageMeta }..." );
191+ logInfo (' Documenting ${config .topLevelPackageMeta }...' );
193192
194- DartdocResults dartdocResults = await generateDocsBase ();
193+ var dartdocResults = await generateDocsBase ();
195194 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' );
197196 }
198197
199- final int errorCount =
198+ final errorCount =
200199 dartdocResults.packageGraph.packageWarningCounter.errorCount;
201200 if (errorCount > 0 ) {
202201 throw DartdocFailure (
203- " dartdoc encountered $errorCount errors while processing." );
202+ ' dartdoc encountered $errorCount errors while processing.' );
204203 }
205204 logInfo (
206205 'Success! Docs generated into ${dartdocResults .outDir .absolute .path }' );
@@ -214,7 +213,7 @@ class Dartdoc extends PackageBuilder {
214213 // Ordinarily this would go in [Package.warn], but we don't actually know what
215214 // ModelElement to warn on yet.
216215 Warnable warnOnElement;
217- Set < Warnable > referredFromElements = Set () ;
216+ var referredFromElements = < Warnable > {} ;
218217 Set <Warnable > warnOnElements;
219218
220219 // Make all paths relative to origin.
@@ -247,20 +246,19 @@ class Dartdoc extends PackageBuilder {
247246 if (referredFromElements.isEmpty && referredFrom == 'index.html' ) {
248247 referredFromElements.add (packageGraph.defaultPackage);
249248 }
250- String message = warnOn;
249+ var message = warnOn;
251250 if (referredFrom == 'index.json' ) message = '$warnOn (from index.json)' ;
252251 packageGraph.warnOnElement (warnOnElement, kind,
253252 message: message, referredFrom: referredFromElements);
254253 }
255254
256255 void _doOrphanCheck (
257256 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 )) {
264262 var fullPath = path.normalize (f.path);
265263 if (f is Directory ) {
266264 continue ;
@@ -274,7 +272,7 @@ class Dartdoc extends PackageBuilder {
274272 continue ;
275273 }
276274 if (visited.contains (fullPath)) continue ;
277- String relativeFullPath = path.relative (fullPath, from: normalOrigin);
275+ var relativeFullPath = path.relative (fullPath, from: normalOrigin);
278276 if (! writtenFiles.contains (relativeFullPath)) {
279277 // This isn't a file we wrote (this time); don't claim we did.
280278 _warn (packageGraph, PackageWarning .unknownFile, fullPath, normalOrigin);
@@ -298,18 +296,18 @@ class Dartdoc extends PackageBuilder {
298296 // This is extracted to save memory during the check; be careful not to hang
299297 // on to anything referencing the full file and doc tree.
300298 Tuple2 <Iterable <String >, String > _getStringLinksAndHref (String fullPath) {
301- File file = File (" $fullPath " );
299+ var file = File (' $fullPath ' );
302300 if (! file.existsSync ()) {
303301 return null ;
304302 }
305- Document doc = parse (file.readAsBytesSync ());
306- Element base = doc.querySelector ('base' );
303+ var doc = parse (file.readAsBytesSync ());
304+ var base = doc.querySelector ('base' );
307305 String baseHref;
308306 if (base != null ) {
309307 baseHref = base .attributes['href' ];
310308 }
311- List < Element > links = doc.querySelectorAll ('a' );
312- List < String > stringLinks = links
309+ var links = doc.querySelectorAll ('a' );
310+ var stringLinks = links
313311 .map ((link) => link.attributes['href' ])
314312 .where ((href) => href != null )
315313 .toList ();
@@ -319,23 +317,23 @@ class Dartdoc extends PackageBuilder {
319317
320318 void _doSearchIndexCheck (
321319 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 ' );
325323 if (! file.existsSync ()) {
326324 return null ;
327325 }
328- JsonDecoder decoder = JsonDecoder ();
326+ var decoder = JsonDecoder ();
329327 List jsonData = decoder.convert (file.readAsStringSync ());
330328
331- Set < String > found = Set () ;
329+ var found = < String > {} ;
332330 found.add (fullPath);
333331 // The package index isn't supposed to be in the search, so suppress the
334332 // warning.
335333 found.add (indexPath);
336334 for (Map <String , dynamic > entry in jsonData) {
337335 if (entry.containsKey ('href' )) {
338- String entryPath = path.joinAll ([origin, entry['href' ]]);
336+ var entryPath = path.joinAll ([origin, entry['href' ]]);
339337 if (! visited.contains (entryPath)) {
340338 _warn (packageGraph, PackageWarning .brokenLink, entryPath,
341339 path.normalize (origin),
@@ -345,8 +343,8 @@ class Dartdoc extends PackageBuilder {
345343 }
346344 }
347345 // 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) {
350348 _warn (packageGraph, PackageWarning .missingFromSearchIndex, s,
351349 path.normalize (origin),
352350 referredFrom: fullPath);
@@ -380,10 +378,10 @@ class Dartdoc extends PackageBuilder {
380378 // here instead -- occasionally, very large jobs have overflowed
381379 // the stack without this.
382380 // (newPathToCheck, newFullPath)
383- Set <Tuple2 <String , String >> toVisit = Set () ;
381+ var toVisit = < Tuple2 <String , String >> {} ;
384382
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) {
387385 if (! href.startsWith (ignoreHyperlinks)) {
388386 Uri uri;
389387 try {
@@ -400,7 +398,7 @@ class Dartdoc extends PackageBuilder {
400398 full = '${path .dirname (pathToCheck )}/$href ' ;
401399 }
402400 var newPathToCheck = path.normalize (full);
403- String newFullPath = path.joinAll ([origin, newPathToCheck]);
401+ var newFullPath = path.joinAll ([origin, newPathToCheck]);
404402 newFullPath = path.normalize (newFullPath);
405403 if (! visited.contains (newFullPath)) {
406404 toVisit.add (Tuple2 (newPathToCheck, newFullPath));
@@ -424,8 +422,8 @@ class Dartdoc extends PackageBuilder {
424422 assert (_hrefs == null );
425423 _hrefs = packageGraph.allHrefs;
426424
427- final Set < String > visited = Set () ;
428- final String start = 'index.html' ;
425+ final visited = < String > {} ;
426+ final start = 'index.html' ;
429427 logInfo ('Validating docs...' );
430428 _doCheck (packageGraph, origin, visited, start);
431429 _doOrphanCheck (packageGraph, origin, visited);
0 commit comments