Skip to content

Commit 036d76e

Browse files
authored
Avoid raw types, like Future or List. (#2257)
This reduces dynamicism by reducing implicit dynamics. It also reduces casts. This is accomplished by replacing types with `var`, or by adding type annotations.
1 parent 3729ad4 commit 036d76e

20 files changed

+83
-83
lines changed

lib/dartdoc.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ class Dartdoc {
355355
return null;
356356
}
357357
var decoder = JsonDecoder();
358-
List jsonData = decoder.convert(file.readAsStringSync());
358+
List<Object> jsonData = decoder.convert(file.readAsStringSync());
359359

360360
var found = <String>{};
361361
found.add(fullPath);
@@ -390,7 +390,7 @@ class Dartdoc {
390390
fullPath = path.normalize(fullPath);
391391
}
392392

393-
Tuple2 stringLinksAndHref = _getStringLinksAndHref(fullPath);
393+
var stringLinksAndHref = _getStringLinksAndHref(fullPath);
394394
if (stringLinksAndHref == null) {
395395
_warn(packageGraph, PackageWarning.brokenLink, pathToCheck,
396396
path.normalize(origin),
@@ -402,8 +402,8 @@ class Dartdoc {
402402
return null;
403403
}
404404
visited.add(fullPath);
405-
Iterable<String> stringLinks = stringLinksAndHref.item1;
406-
String baseHref = stringLinksAndHref.item2;
405+
var stringLinks = stringLinksAndHref.item1;
406+
var baseHref = stringLinksAndHref.item2;
407407

408408
// Prevent extremely large stacks by storing the paths we are using
409409
// here instead -- occasionally, very large jobs have overflowed
@@ -438,7 +438,7 @@ class Dartdoc {
438438
}
439439
}
440440
}
441-
for (Tuple2 visitPaths in toVisit) {
441+
for (var visitPaths in toVisit) {
442442
_doCheck(packageGraph, origin, visited, visitPaths.item1, pathToCheck,
443443
visitPaths.item2);
444444
}

lib/options.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class DartdocProgramOptionContext extends DartdocGeneratorOptionContext
1515
bool get version => optionSet['version'].valueAt(context);
1616
}
1717

18-
Future<List<DartdocOption>> createDartdocProgramOptions() async {
19-
return <DartdocOption>[
18+
Future<List<DartdocOption<bool>>> createDartdocProgramOptions() async {
19+
return [
2020
DartdocOptionArgOnly<bool>('generateDocs', true,
2121
help:
2222
'Generate docs into the output directory (or only display warnings if false).',

lib/src/dartdoc_options.dart

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class Snapshot {
190190
File _snapshotFile;
191191

192192
File get snapshotFile => _snapshotFile;
193-
final Completer _snapshotCompleter = Completer();
193+
final Completer<void> _snapshotCompleter = Completer();
194194

195195
Snapshot(Directory snapshotCache, String toolPath, int serial) {
196196
if (toolPath.endsWith('.snapshot')) {
@@ -406,7 +406,7 @@ class ToolConfiguration {
406406
/// A container class to keep track of where our yaml data came from.
407407
class _YamlFileData {
408408
/// The map from the yaml file.
409-
final Map data;
409+
final Map<Object, Object> data;
410410

411411
/// The path to the directory containing the yaml file.
412412
final String canonicalDirectoryPath;
@@ -521,10 +521,10 @@ abstract class DartdocOption<T> {
521521

522522
bool get _isDouble => _kDoubleVal is T;
523523

524-
DartdocOption _parent;
524+
DartdocOption<Object> _parent;
525525

526526
/// The parent of this DartdocOption, or null if this is the root.
527-
DartdocOption get parent => _parent;
527+
DartdocOption<Object> get parent => _parent;
528528

529529
final Map<String, _YamlFileData> __yamlAtCanonicalPathCache = {};
530530

@@ -549,10 +549,10 @@ abstract class DartdocOption<T> {
549549
/// Throw [DartdocFileMissing] with a detailed error message indicating where
550550
/// the error came from when a file or directory option is missing.
551551
void _onMissing(
552-
_OptionValueWithContext valueWithContext, String missingFilename);
552+
_OptionValueWithContext<Object> valueWithContext, String missingFilename);
553553

554554
/// Call [_onMissing] for every path that does not exist.
555-
void _validatePaths(_OptionValueWithContext valueWithContext) {
555+
void _validatePaths(_OptionValueWithContext<dynamic> valueWithContext) {
556556
if (!mustExist) return;
557557
assert(isDir || isFile);
558558
List<String> resolvedPaths;
@@ -578,7 +578,7 @@ abstract class DartdocOption<T> {
578578

579579
/// For a [List<String>] or [String] value, if [isDir] or [isFile] is set,
580580
/// resolve paths in value relative to canonicalPath.
581-
T _handlePathsInContext(_OptionValueWithContext valueWithContext) {
581+
T _handlePathsInContext(_OptionValueWithContext<Object> valueWithContext) {
582582
if (valueWithContext?.value == null || !(isDir || isFile)) {
583583
return valueWithContext?.value;
584584
}
@@ -594,15 +594,15 @@ abstract class DartdocOption<T> {
594594
ArgResults get _argResults => root.__argResults;
595595

596596
/// Set the parent of this [DartdocOption]. Do not call more than once.
597-
set parent(DartdocOption newParent) {
597+
set parent(DartdocOption<Object> newParent) {
598598
assert(_parent == null);
599599
_parent = newParent;
600600
}
601601

602602
/// The root [DartdocOption] containing this object, or [this] if the object
603603
/// has no parent.
604-
DartdocOption get root {
605-
DartdocOption p = this;
604+
DartdocOption<Object> get root {
605+
DartdocOption<Object> p = this;
606606
while (p.parent != null) {
607607
p = p.parent;
608608
}
@@ -612,7 +612,7 @@ abstract class DartdocOption<T> {
612612
/// All object names starting at the root.
613613
Iterable<String> get keys {
614614
var keyList = <String>[];
615-
DartdocOption option = this;
615+
DartdocOption<Object> option = this;
616616
while (option?.name != null) {
617617
keyList.add(option.name);
618618
option = option.parent;
@@ -621,7 +621,7 @@ abstract class DartdocOption<T> {
621621
}
622622

623623
/// Direct children of this node, mapped by name.
624-
final Map<String, DartdocOption> _children = {};
624+
final Map<String, DartdocOption<Object>> _children = {};
625625

626626
/// Return the calculated value of this option, given the directory as context.
627627
///
@@ -643,7 +643,7 @@ abstract class DartdocOption<T> {
643643
valueAt(Directory(p.canonicalize(p.basename(element.source.fullName))));
644644

645645
/// Adds a DartdocOption to the children of this DartdocOption.
646-
void add(DartdocOption option) {
646+
void add(DartdocOption<Object> option) {
647647
if (_children.containsKey(option.name)) {
648648
throw DartdocOptionError(
649649
'Tried to add two children with the same name: ${option.name}');
@@ -657,16 +657,16 @@ abstract class DartdocOption<T> {
657657
void _onAdd() {}
658658

659659
/// Adds a list of dartdoc options to the children of this DartdocOption.
660-
void addAll(Iterable<DartdocOption> options) =>
660+
void addAll(Iterable<DartdocOption<Object>> options) =>
661661
options.forEach((o) => add(o));
662662

663663
/// Get the immediate child of this node named [name].
664-
DartdocOption operator [](String name) {
664+
DartdocOption<dynamic> operator [](String name) {
665665
return _children[name];
666666
}
667667

668668
/// Apply the function [visit] to [this] and all children.
669-
void traverse(void Function(DartdocOption option) visit) {
669+
void traverse(void Function(DartdocOption<Object> option) visit) {
670670
visit(this);
671671
_children.values.forEach((d) => d.traverse(visit));
672672
}
@@ -702,7 +702,7 @@ class DartdocOptionFileSynth<T> extends DartdocOption<T>
702702

703703
@override
704704
void _onMissing(
705-
_OptionValueWithContext valueWithContext, String missingPath) {
705+
_OptionValueWithContext<Object> valueWithContext, String missingPath) {
706706
if (valueWithContext.definingFile != null) {
707707
_onMissingFromFiles(valueWithContext, missingPath);
708708
} else {
@@ -744,7 +744,7 @@ class DartdocOptionArgSynth<T> extends DartdocOption<T>
744744

745745
@override
746746
void _onMissing(
747-
_OptionValueWithContext valueWithContext, String missingPath) {
747+
_OptionValueWithContext<Object> valueWithContext, String missingPath) {
748748
_onMissingFromArgs(valueWithContext, missingPath);
749749
}
750750

@@ -794,25 +794,24 @@ abstract class DartdocSyntheticOption<T> implements DartdocOption<T> {
794794
T valueAt(Directory dir) => _valueAtFromSynthetic(dir);
795795

796796
T _valueAtFromSynthetic(Directory dir) {
797-
_OptionValueWithContext context =
798-
_OptionValueWithContext<T>(_compute(this, dir), dir.path);
797+
var context = _OptionValueWithContext<T>(_compute(this, dir), dir.path);
799798
return _handlePathsInContext(context);
800799
}
801800

802801
@override
803-
void _onMissing(
804-
_OptionValueWithContext valueWithContext, String missingPath) =>
802+
void _onMissing(_OptionValueWithContext<Object> valueWithContext,
803+
String missingPath) =>
805804
_onMissingFromSynthetic(valueWithContext, missingPath);
806805

807806
void _onMissingFromSynthetic(
808-
_OptionValueWithContext valueWithContext, String missingPath) {
807+
_OptionValueWithContext<Object> valueWithContext, String missingPath) {
809808
var description = 'Synthetic configuration option ${name} from <internal>';
810809
throw DartdocFileMissing(
811810
'$description, computed as ${valueWithContext.value}, resolves to missing path: "${missingPath}"');
812811
}
813812
}
814813

815-
typedef OptionGenerator = Future<List<DartdocOption>> Function();
814+
typedef OptionGenerator = Future<List<DartdocOption<Object>>> Function();
816815

817816
/// A [DartdocOption] that only contains other [DartdocOption]s and is not an option itself.
818817
class DartdocOptionSet extends DartdocOption<Null> {
@@ -840,12 +839,12 @@ class DartdocOptionSet extends DartdocOption<Null> {
840839

841840
/// Since we have no value, [_onMissing] does nothing.
842841
@override
843-
void _onMissing(
844-
_OptionValueWithContext valueWithContext, String missingFilename) {}
842+
void _onMissing(_OptionValueWithContext<Object> valueWithContext,
843+
String missingFilename) {}
845844

846845
/// Traverse skips this node, because it doesn't represent a real configuration object.
847846
@override
848-
void traverse(void Function(DartdocOption option) visitor) {
847+
void traverse(void Function(DartdocOption<Object> option) visitor) {
849848
_children.values.forEach((d) => d.traverse(visitor));
850849
}
851850
}
@@ -917,7 +916,7 @@ class DartdocOptionArgFile<T> extends DartdocOption<T>
917916

918917
@override
919918
void _onMissing(
920-
_OptionValueWithContext valueWithContext, String missingPath) {
919+
_OptionValueWithContext<Object> valueWithContext, String missingPath) {
921920
if (valueWithContext.definingFile != null) {
922921
_onMissingFromFiles(valueWithContext, missingPath);
923922
} else {
@@ -988,12 +987,12 @@ abstract class _DartdocFileOption<T> implements DartdocOption<T> {
988987
String get fieldName => keys.join('.');
989988

990989
@override
991-
void _onMissing(
992-
_OptionValueWithContext valueWithContext, String missingPath) =>
990+
void _onMissing(_OptionValueWithContext<Object> valueWithContext,
991+
String missingPath) =>
993992
_onMissingFromFiles(valueWithContext, missingPath);
994993

995994
void _onMissingFromFiles(
996-
_OptionValueWithContext valueWithContext, String missingPath) {
995+
_OptionValueWithContext<Object> valueWithContext, String missingPath) {
997996
var dartdocYaml = p.join(
998997
valueWithContext.canonicalDirectoryPath, valueWithContext.definingFile);
999998
throw DartdocFileMissing(
@@ -1015,7 +1014,7 @@ abstract class _DartdocFileOption<T> implements DartdocOption<T> {
10151014
T _valueAtFromFiles(Directory dir) {
10161015
var key = p.canonicalize(dir.path);
10171016
if (!__valueAtFromFiles.containsKey(key)) {
1018-
_OptionValueWithContext valueWithContext;
1017+
_OptionValueWithContext<Object> valueWithContext;
10191018
if (parentDirOverridesChild) {
10201019
valueWithContext = _valueAtFromFilesLastFound(dir);
10211020
} else {
@@ -1029,8 +1028,8 @@ abstract class _DartdocFileOption<T> implements DartdocOption<T> {
10291028
/// Searches all dartdoc_options files through parent directories,
10301029
/// starting at [dir], for the option and returns one once
10311030
/// found.
1032-
_OptionValueWithContext _valueAtFromFilesFirstFound(Directory dir) {
1033-
_OptionValueWithContext value;
1031+
_OptionValueWithContext<Object> _valueAtFromFilesFirstFound(Directory dir) {
1032+
_OptionValueWithContext<Object> value;
10341033
while (true) {
10351034
value = _valueAtFromFile(dir);
10361035
if (value != null || p.equals(dir.parent.path, dir.path)) break;
@@ -1042,8 +1041,8 @@ abstract class _DartdocFileOption<T> implements DartdocOption<T> {
10421041
/// Searches all dartdoc_options files for the option, and returns the
10431042
/// value in the top-most parent directory dartdoc_options.yaml file it is
10441043
/// mentioned in.
1045-
_OptionValueWithContext _valueAtFromFilesLastFound(Directory dir) {
1046-
_OptionValueWithContext value;
1044+
_OptionValueWithContext<Object> _valueAtFromFilesLastFound(Directory dir) {
1045+
_OptionValueWithContext<Object> value;
10471046
while (true) {
10481047
var tmpValue = _valueAtFromFile(dir);
10491048
if (tmpValue != null) value = tmpValue;
@@ -1055,7 +1054,7 @@ abstract class _DartdocFileOption<T> implements DartdocOption<T> {
10551054

10561055
/// Returns null if not set in the yaml file in this directory (or its
10571056
/// parents).
1058-
_OptionValueWithContext _valueAtFromFile(Directory dir) {
1057+
_OptionValueWithContext<Object> _valueAtFromFile(Directory dir) {
10591058
var yamlFileData = _yamlAtDirectory(dir);
10601059
var contextPath = yamlFileData.canonicalDirectoryPath;
10611060
dynamic yamlData = yamlFileData.data;
@@ -1177,12 +1176,12 @@ abstract class _DartdocArgOption<T> implements DartdocOption<T> {
11771176
}
11781177

11791178
@override
1180-
void _onMissing(
1181-
_OptionValueWithContext valueWithContext, String missingPath) =>
1179+
void _onMissing(_OptionValueWithContext<Object> valueWithContext,
1180+
String missingPath) =>
11821181
_onMissingFromArgs(valueWithContext, missingPath);
11831182

11841183
void _onMissingFromArgs(
1185-
_OptionValueWithContext valueWithContext, String missingPath) {
1184+
_OptionValueWithContext<Object> valueWithContext, String missingPath) {
11861185
throw DartdocFileMissing(
11871186
'Argument --${argName}, set to ${valueWithContext.value}, resolves to missing path: "${missingPath}"');
11881187
}
@@ -1191,7 +1190,7 @@ abstract class _DartdocArgOption<T> implements DartdocOption<T> {
11911190
/// the [argParser] and the working directory from [directoryCurrent].
11921191
///
11931192
/// Throws [UnsupportedError] if [T] is not a supported type.
1194-
_OptionValueWithContext _valueAtFromArgsWithContext() {
1193+
_OptionValueWithContext<Object> _valueAtFromArgsWithContext() {
11951194
if (!_argResults.wasParsed(argName)) return null;
11961195

11971196
T retval;
@@ -1429,10 +1428,10 @@ class DartdocOptionContext extends DartdocOptionContextBase
14291428

14301429
/// Instantiate dartdoc's configuration file and options parser with the
14311430
/// given command line arguments.
1432-
Future<List<DartdocOption>> createDartdocOptions(
1431+
Future<List<DartdocOption<Object>>> createDartdocOptions(
14331432
PackageMetaProvider packageMetaProvider,
14341433
) async {
1435-
return <DartdocOption>[
1434+
return [
14361435
DartdocOptionArgOnly<bool>('allowTools', false,
14371436
help: 'Execute user-defined tools to fill in @tool directives.',
14381437
negatable: true),

lib/src/experiment_options.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ abstract class DartdocExperimentOptionContext
2121

2222
// TODO(jcollins-g): Implement YAML parsing for these flags and generation
2323
// of [DartdocExperimentOptionContext], once a YAML file is available.
24-
Future<List<DartdocOption>> createExperimentOptions() async {
25-
return <DartdocOption>[
24+
Future<List<DartdocOption<Object>>> createExperimentOptions() async {
25+
return [
2626
// TODO(jcollins-g): Consider loading experiment values from dartdoc_options.yaml?
2727
DartdocOptionArgOnly<List<String>>('enable-experiment', [],
2828
help: 'Enable or disable listed experiments.\n' +

lib/src/generator/empty_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'package:dartdoc/src/model_utils.dart';
1313
/// it were.
1414
class EmptyGenerator extends Generator {
1515
@override
16-
Future generate(PackageGraph _packageGraph, FileWriter writer) {
16+
Future<void> generate(PackageGraph _packageGraph, FileWriter writer) {
1717
logProgress(_packageGraph.defaultPackage.documentationAsHtml);
1818
for (var package in {_packageGraph.defaultPackage}
1919
..addAll(_packageGraph.localPackages)) {

lib/src/generator/generator.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ abstract class FileWriter {
2828
abstract class Generator {
2929
/// Generate the documentation for the given package using the specified
3030
/// writer. Completes the returned future when done.
31-
Future generate(PackageGraph packageGraph, FileWriter writer);
31+
Future<void> generate(PackageGraph packageGraph, FileWriter writer);
3232
}
3333

3434
/// Dartdoc options related to generators generally.
@@ -55,8 +55,8 @@ mixin GeneratorContext on DartdocOptionContextBase {
5555
bool get useBaseHref => optionSet['useBaseHref'].valueAt(context);
5656
}
5757

58-
Future<List<DartdocOption>> createGeneratorOptions() async {
59-
return <DartdocOption>[
58+
Future<List<DartdocOption<Object>>> createGeneratorOptions() async {
59+
return [
6060
DartdocOptionArgFile<List<String>>('footer', [],
6161
isFile: true,
6262
help:

lib/src/generator/generator_frontend.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class GeneratorFrontEnd implements Generator {
1818
GeneratorFrontEnd(this._generatorBackend);
1919

2020
@override
21-
Future generate(PackageGraph packageGraph, FileWriter writer) async {
21+
Future<void> generate(PackageGraph packageGraph, FileWriter writer) async {
2222
var indexElements = <Indexable>[];
2323
_generateDocs(packageGraph, writer, indexElements);
2424
await _generatorBackend.generateAdditionalFiles(writer, packageGraph);

0 commit comments

Comments
 (0)