Skip to content

Avoid raw types, like Future or List. #2257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class Dartdoc {
return null;
}
var decoder = JsonDecoder();
List jsonData = decoder.convert(file.readAsStringSync());
List<Object> jsonData = decoder.convert(file.readAsStringSync());

var found = <String>{};
found.add(fullPath);
Expand Down Expand Up @@ -390,7 +390,7 @@ class Dartdoc {
fullPath = path.normalize(fullPath);
}

Tuple2 stringLinksAndHref = _getStringLinksAndHref(fullPath);
var stringLinksAndHref = _getStringLinksAndHref(fullPath);
if (stringLinksAndHref == null) {
_warn(packageGraph, PackageWarning.brokenLink, pathToCheck,
path.normalize(origin),
Expand All @@ -402,8 +402,8 @@ class Dartdoc {
return null;
}
visited.add(fullPath);
Iterable<String> stringLinks = stringLinksAndHref.item1;
String baseHref = stringLinksAndHref.item2;
var stringLinks = stringLinksAndHref.item1;
var baseHref = stringLinksAndHref.item2;

// Prevent extremely large stacks by storing the paths we are using
// here instead -- occasionally, very large jobs have overflowed
Expand Down Expand Up @@ -438,7 +438,7 @@ class Dartdoc {
}
}
}
for (Tuple2 visitPaths in toVisit) {
for (var visitPaths in toVisit) {
_doCheck(packageGraph, origin, visited, visitPaths.item1, pathToCheck,
visitPaths.item2);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class DartdocProgramOptionContext extends DartdocGeneratorOptionContext
bool get version => optionSet['version'].valueAt(context);
}

Future<List<DartdocOption>> createDartdocProgramOptions() async {
return <DartdocOption>[
Future<List<DartdocOption<bool>>> createDartdocProgramOptions() async {
return [
DartdocOptionArgOnly<bool>('generateDocs', true,
help:
'Generate docs into the output directory (or only display warnings if false).',
Expand Down
85 changes: 42 additions & 43 deletions lib/src/dartdoc_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class Snapshot {
File _snapshotFile;

File get snapshotFile => _snapshotFile;
final Completer _snapshotCompleter = Completer();
final Completer<void> _snapshotCompleter = Completer();

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

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

bool get _isDouble => _kDoubleVal is T;

DartdocOption _parent;
DartdocOption<Object> _parent;

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

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

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

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

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

/// Set the parent of this [DartdocOption]. Do not call more than once.
set parent(DartdocOption newParent) {
set parent(DartdocOption<Object> newParent) {
assert(_parent == null);
_parent = newParent;
}

/// The root [DartdocOption] containing this object, or [this] if the object
/// has no parent.
DartdocOption get root {
DartdocOption p = this;
DartdocOption<Object> get root {
DartdocOption<Object> p = this;
while (p.parent != null) {
p = p.parent;
}
Expand All @@ -612,7 +612,7 @@ abstract class DartdocOption<T> {
/// All object names starting at the root.
Iterable<String> get keys {
var keyList = <String>[];
DartdocOption option = this;
DartdocOption<Object> option = this;
while (option?.name != null) {
keyList.add(option.name);
option = option.parent;
Expand All @@ -621,7 +621,7 @@ abstract class DartdocOption<T> {
}

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

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

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

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

/// Get the immediate child of this node named [name].
DartdocOption operator [](String name) {
DartdocOption<dynamic> operator [](String name) {
return _children[name];
}

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

@override
void _onMissing(
_OptionValueWithContext valueWithContext, String missingPath) {
_OptionValueWithContext<Object> valueWithContext, String missingPath) {
if (valueWithContext.definingFile != null) {
_onMissingFromFiles(valueWithContext, missingPath);
} else {
Expand Down Expand Up @@ -744,7 +744,7 @@ class DartdocOptionArgSynth<T> extends DartdocOption<T>

@override
void _onMissing(
_OptionValueWithContext valueWithContext, String missingPath) {
_OptionValueWithContext<Object> valueWithContext, String missingPath) {
_onMissingFromArgs(valueWithContext, missingPath);
}

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

T _valueAtFromSynthetic(Directory dir) {
_OptionValueWithContext context =
_OptionValueWithContext<T>(_compute(this, dir), dir.path);
var context = _OptionValueWithContext<T>(_compute(this, dir), dir.path);
return _handlePathsInContext(context);
}

@override
void _onMissing(
_OptionValueWithContext valueWithContext, String missingPath) =>
void _onMissing(_OptionValueWithContext<Object> valueWithContext,
String missingPath) =>
_onMissingFromSynthetic(valueWithContext, missingPath);

void _onMissingFromSynthetic(
_OptionValueWithContext valueWithContext, String missingPath) {
_OptionValueWithContext<Object> valueWithContext, String missingPath) {
var description = 'Synthetic configuration option ${name} from <internal>';
throw DartdocFileMissing(
'$description, computed as ${valueWithContext.value}, resolves to missing path: "${missingPath}"');
}
}

typedef OptionGenerator = Future<List<DartdocOption>> Function();
typedef OptionGenerator = Future<List<DartdocOption<Object>>> Function();

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

/// Since we have no value, [_onMissing] does nothing.
@override
void _onMissing(
_OptionValueWithContext valueWithContext, String missingFilename) {}
void _onMissing(_OptionValueWithContext<Object> valueWithContext,
String missingFilename) {}

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

@override
void _onMissing(
_OptionValueWithContext valueWithContext, String missingPath) {
_OptionValueWithContext<Object> valueWithContext, String missingPath) {
if (valueWithContext.definingFile != null) {
_onMissingFromFiles(valueWithContext, missingPath);
} else {
Expand Down Expand Up @@ -988,12 +987,12 @@ abstract class _DartdocFileOption<T> implements DartdocOption<T> {
String get fieldName => keys.join('.');

@override
void _onMissing(
_OptionValueWithContext valueWithContext, String missingPath) =>
void _onMissing(_OptionValueWithContext<Object> valueWithContext,
String missingPath) =>
_onMissingFromFiles(valueWithContext, missingPath);

void _onMissingFromFiles(
_OptionValueWithContext valueWithContext, String missingPath) {
_OptionValueWithContext<Object> valueWithContext, String missingPath) {
var dartdocYaml = p.join(
valueWithContext.canonicalDirectoryPath, valueWithContext.definingFile);
throw DartdocFileMissing(
Expand All @@ -1015,7 +1014,7 @@ abstract class _DartdocFileOption<T> implements DartdocOption<T> {
T _valueAtFromFiles(Directory dir) {
var key = p.canonicalize(dir.path);
if (!__valueAtFromFiles.containsKey(key)) {
_OptionValueWithContext valueWithContext;
_OptionValueWithContext<Object> valueWithContext;
if (parentDirOverridesChild) {
valueWithContext = _valueAtFromFilesLastFound(dir);
} else {
Expand All @@ -1029,8 +1028,8 @@ abstract class _DartdocFileOption<T> implements DartdocOption<T> {
/// Searches all dartdoc_options files through parent directories,
/// starting at [dir], for the option and returns one once
/// found.
_OptionValueWithContext _valueAtFromFilesFirstFound(Directory dir) {
_OptionValueWithContext value;
_OptionValueWithContext<Object> _valueAtFromFilesFirstFound(Directory dir) {
_OptionValueWithContext<Object> value;
while (true) {
value = _valueAtFromFile(dir);
if (value != null || p.equals(dir.parent.path, dir.path)) break;
Expand All @@ -1042,8 +1041,8 @@ abstract class _DartdocFileOption<T> implements DartdocOption<T> {
/// Searches all dartdoc_options files for the option, and returns the
/// value in the top-most parent directory dartdoc_options.yaml file it is
/// mentioned in.
_OptionValueWithContext _valueAtFromFilesLastFound(Directory dir) {
_OptionValueWithContext value;
_OptionValueWithContext<Object> _valueAtFromFilesLastFound(Directory dir) {
_OptionValueWithContext<Object> value;
while (true) {
var tmpValue = _valueAtFromFile(dir);
if (tmpValue != null) value = tmpValue;
Expand All @@ -1055,7 +1054,7 @@ abstract class _DartdocFileOption<T> implements DartdocOption<T> {

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

@override
void _onMissing(
_OptionValueWithContext valueWithContext, String missingPath) =>
void _onMissing(_OptionValueWithContext<Object> valueWithContext,
String missingPath) =>
_onMissingFromArgs(valueWithContext, missingPath);

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

T retval;
Expand Down Expand Up @@ -1429,10 +1428,10 @@ class DartdocOptionContext extends DartdocOptionContextBase

/// Instantiate dartdoc's configuration file and options parser with the
/// given command line arguments.
Future<List<DartdocOption>> createDartdocOptions(
Future<List<DartdocOption<Object>>> createDartdocOptions(
PackageMetaProvider packageMetaProvider,
) async {
return <DartdocOption>[
return [
DartdocOptionArgOnly<bool>('allowTools', false,
help: 'Execute user-defined tools to fill in @tool directives.',
negatable: true),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/experiment_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ abstract class DartdocExperimentOptionContext

// TODO(jcollins-g): Implement YAML parsing for these flags and generation
// of [DartdocExperimentOptionContext], once a YAML file is available.
Future<List<DartdocOption>> createExperimentOptions() async {
return <DartdocOption>[
Future<List<DartdocOption<Object>>> createExperimentOptions() async {
return [
// TODO(jcollins-g): Consider loading experiment values from dartdoc_options.yaml?
DartdocOptionArgOnly<List<String>>('enable-experiment', [],
help: 'Enable or disable listed experiments.\n' +
Expand Down
2 changes: 1 addition & 1 deletion lib/src/generator/empty_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:dartdoc/src/model_utils.dart';
/// it were.
class EmptyGenerator extends Generator {
@override
Future generate(PackageGraph _packageGraph, FileWriter writer) {
Future<void> generate(PackageGraph _packageGraph, FileWriter writer) {
logProgress(_packageGraph.defaultPackage.documentationAsHtml);
for (var package in {_packageGraph.defaultPackage}
..addAll(_packageGraph.localPackages)) {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/generator/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class FileWriter {
abstract class Generator {
/// Generate the documentation for the given package using the specified
/// writer. Completes the returned future when done.
Future generate(PackageGraph packageGraph, FileWriter writer);
Future<void> generate(PackageGraph packageGraph, FileWriter writer);
}

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

Future<List<DartdocOption>> createGeneratorOptions() async {
return <DartdocOption>[
Future<List<DartdocOption<Object>>> createGeneratorOptions() async {
return [
DartdocOptionArgFile<List<String>>('footer', [],
isFile: true,
help:
Expand Down
2 changes: 1 addition & 1 deletion lib/src/generator/generator_frontend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GeneratorFrontEnd implements Generator {
GeneratorFrontEnd(this._generatorBackend);

@override
Future generate(PackageGraph packageGraph, FileWriter writer) async {
Future<void> generate(PackageGraph packageGraph, FileWriter writer) async {
var indexElements = <Indexable>[];
_generateDocs(packageGraph, writer, indexElements);
await _generatorBackend.generateAdditionalFiles(writer, packageGraph);
Expand Down
Loading