Skip to content

Commit f146d9d

Browse files
srawlinsjcollins-g
andauthored
Enforce strict-raw-types (#2791)
* Enforce strict-raw-types * presubmit Co-authored-by: Janice Collins <[email protected]>
1 parent b1b9ee8 commit f146d9d

9 files changed

+45
-31
lines changed

analysis_options.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ analyzer:
77
todo: ignore
88
unused_import: warning
99
unused_shown_name: warning
10+
language:
11+
strict-raw-types: true
1012
exclude:
1113
- 'doc/**'
1214
- 'lib/src/third_party/pkg/**'

analysis_options_presubmit.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ analyzer:
1010
### Extra ignores for presubmit
1111
deprecated_member_use: ignore
1212
deprecated_member_use_from_same_package: ignore
13+
language:
14+
strict-raw-types: true
1315
exclude:
1416
- 'doc/**'
1517
- 'lib/src/third_party/pkg/**'

lib/src/dartdoc_options.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ class _OptionValueWithContext<T> {
338338
///
339339
/// Use via implementations [DartdocOptionSet], [DartdocOptionArgFile],
340340
/// [DartdocOptionArgOnly], and [DartdocOptionFileOnly].
341-
abstract class DartdocOption<T> {
341+
abstract class DartdocOption<T extends Object> {
342342
/// This is the value returned if we couldn't find one otherwise.
343343
final T defaultsTo;
344344

lib/src/io_utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class _TaskQueueItem<T> {
144144
/// the number of simultaneous tasks.
145145
///
146146
/// The tasks return results of type T.
147-
class TaskQueue<T> {
147+
class TaskQueue<T extends Object> {
148148
/// Creates a task queue with a maximum number of simultaneous jobs.
149149
/// The [maxJobs] parameter defaults to the number of CPU cores on the
150150
/// system.

lib/src/mustachio/annotations.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Renderer {
2020
final Symbol name;
2121

2222
/// The type of the context type, specified as the [Context] type argument.
23-
final Context context;
23+
final Context<Object> context;
2424

2525
/// The unparsed, string form of the URI of the _standard_ HTML template.
2626
///

lib/src/mustachio/renderer_base.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ class Template {
132132
}
133133

134134
/// The base class for a generated Mustache renderer.
135-
abstract class RendererBase<T> {
135+
abstract class RendererBase<T extends Object> {
136136
/// The context object which this renderer can render.
137137
final T context;
138138

139139
/// The renderer of the parent context, if any, otherwise `null`.
140-
final RendererBase parent;
140+
final RendererBase<Object> parent;
141141

142142
/// The current template being rendered.
143143
///
@@ -288,7 +288,7 @@ abstract class RendererBase<T> {
288288

289289
String renderSimple(
290290
Object context, List<MustachioNode> ast, Template template, StringSink sink,
291-
{@required RendererBase parent, Set<String> getters}) {
291+
{@required RendererBase<Object> parent, Set<String> getters}) {
292292
var renderer = SimpleRenderer(context, parent, template, sink, getters);
293293
renderer.renderBlock(ast);
294294
return renderer.sink.toString();

test/html_generator_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,13 @@ const Matcher doesExist = _DoesExist();
162162
class _DoesExist extends Matcher {
163163
const _DoesExist();
164164
@override
165-
bool matches(Object item, Map matchState) => (item as Resource).exists;
165+
bool matches(Object item, Map<Object, Object> matchState) =>
166+
(item as Resource).exists;
166167
@override
167168
Description describe(Description description) => description.add('exists');
168169
@override
169170
Description describeMismatch(Object item, Description mismatchDescription,
170-
Map matchState, bool verbose) {
171+
Map<Object, Object> matchState, bool verbose) {
171172
if (item is! File && item is! Folder) {
172173
return mismatchDescription
173174
.addDescriptionOf(item)

tool/grind.dart

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ void presubmit() => null;
327327
void buildbot() => null;
328328

329329
@Task('Generate docs for the Dart SDK')
330-
Future buildSdkDocs() async {
330+
Future<void> buildSdkDocs() async {
331331
log('building SDK docs');
332332
await _buildSdkDocs(sdkDocsDir.path, Future.value(Directory.current.path));
333333
}
@@ -426,8 +426,11 @@ class WarningsCollection {
426426
}
427427

428428
/// Returns a map of warning texts to the number of times each has been seen.
429-
WarningsCollection jsonMessageIterableToWarnings(Iterable<Map> messageIterable,
430-
String tempPath, String pubDir, String branch) {
429+
WarningsCollection jsonMessageIterableToWarnings(
430+
Iterable<Map<Object, Object>> messageIterable,
431+
String tempPath,
432+
String pubDir,
433+
String branch) {
431434
var warningTexts = WarningsCollection(tempPath, pubDir, branch);
432435
if (messageIterable == null) return warningTexts;
433436
for (Map<String, dynamic> message in messageIterable) {
@@ -442,13 +445,13 @@ WarningsCollection jsonMessageIterableToWarnings(Iterable<Map> messageIterable,
442445
}
443446

444447
@Task('Display delta in SDK warnings')
445-
Future compareSdkWarnings() async {
448+
Future<void> compareSdkWarnings() async {
446449
var originalDartdocSdkDocs =
447450
Directory.systemTemp.createTempSync('dartdoc-comparison-sdkdocs');
448-
Future originalDartdoc = createComparisonDartdoc();
449-
Future currentDartdocSdkBuild = _buildSdkDocs(
451+
var originalDartdoc = createComparisonDartdoc();
452+
var currentDartdocSdkBuild = _buildSdkDocs(
450453
sdkDocsDir.path, Future.value(Directory.current.path), 'current');
451-
Future originalDartdocSdkBuild =
454+
var originalDartdocSdkBuild =
452455
_buildSdkDocs(originalDartdocSdkDocs.path, originalDartdoc, 'original');
453456
var currentDartdocWarnings = jsonMessageIterableToWarnings(
454457
await currentDartdocSdkBuild, sdkDocsDir.absolute.path, null, 'HEAD');
@@ -540,7 +543,8 @@ Future<void> testWithAnalyzerSdk() async {
540543
workingDirectory: sdkDartdoc);
541544
}
542545

543-
Future<List<Map>> _buildSdkDocs(String sdkDocsPath, Future<String> futureCwd,
546+
Future<List<Map<Object, Object>>> _buildSdkDocs(
547+
String sdkDocsPath, Future<String> futureCwd,
544548
[String label]) async {
545549
label ??= '';
546550
if (label != '') label = '-$label';
@@ -562,15 +566,16 @@ Future<List<Map>> _buildSdkDocs(String sdkDocsPath, Future<String> futureCwd,
562566
workingDirectory: cwd);
563567
}
564568

565-
Future<List<Map>> _buildTestPackageDocs(String outputDir, String cwd,
569+
Future<List<Map<Object, Object>>> _buildTestPackageDocs(
570+
String outputDir, String cwd,
566571
{List<String> params, String label = '', String testPackagePath}) async {
567572
if (label != '') label = '-$label';
568573
testPackagePath ??= testPackage.absolute.path;
569574
params ??= [];
570575
var launcher = SubprocessLauncher('build-test-package-docs$label');
571-
Future testPackagePubGet = launcher.runStreamed(sdkBin('pub'), ['get'],
576+
var testPackagePubGet = launcher.runStreamed(sdkBin('pub'), ['get'],
572577
workingDirectory: testPackagePath);
573-
Future dartdocPubGet =
578+
var dartdocPubGet =
574579
launcher.runStreamed(sdkBin('pub'), ['get'], workingDirectory: cwd);
575580
await Future.wait([testPackagePubGet, dartdocPubGet]);
576581
return await launcher.runStreamed(
@@ -687,12 +692,12 @@ Future<void> serveSdkDocs() async {
687692
Future<void> compareFlutterWarnings() async {
688693
var originalDartdocFlutter =
689694
Directory.systemTemp.createTempSync('dartdoc-comparison-flutter');
690-
Future originalDartdoc = createComparisonDartdoc();
695+
var originalDartdoc = createComparisonDartdoc();
691696
var envCurrent = _createThrowawayPubCache();
692697
var envOriginal = _createThrowawayPubCache();
693-
Future currentDartdocFlutterBuild = _buildFlutterDocs(flutterDir.path,
698+
var currentDartdocFlutterBuild = _buildFlutterDocs(flutterDir.path,
694699
Future.value(Directory.current.path), envCurrent, 'docs-current');
695-
Future originalDartdocFlutterBuild = _buildFlutterDocs(
700+
var originalDartdocFlutterBuild = _buildFlutterDocs(
696701
originalDartdocFlutter.path,
697702
originalDartdoc,
698703
envOriginal,
@@ -714,7 +719,7 @@ Future<void> compareFlutterWarnings() async {
714719
if (Platform.environment['SERVE_FLUTTER'] == '1') {
715720
var launcher = SubprocessLauncher('serve-flutter-docs');
716721
await launcher.runStreamed(sdkBin('pub'), ['get']);
717-
Future original = launcher.runStreamed(sdkBin('pub'), [
722+
var original = launcher.runStreamed(sdkBin('pub'), [
718723
'global',
719724
'run',
720725
'dhttpd',
@@ -723,7 +728,7 @@ Future<void> compareFlutterWarnings() async {
723728
'--path',
724729
path.join(originalDartdocFlutter.absolute.path, 'dev', 'docs', 'doc'),
725730
]);
726-
Future current = launcher.runStreamed(sdkBin('pub'), [
731+
var current = launcher.runStreamed(sdkBin('pub'), [
727732
'global',
728733
'run',
729734
'dhttpd',
@@ -909,7 +914,7 @@ class FlutterRepo {
909914
SubprocessLauncher launcher;
910915
}
911916

912-
Future<List<Map>> _buildFlutterDocs(
917+
Future<List<Map<Object, Object>>> _buildFlutterDocs(
913918
String flutterPath, Future<String> futureCwd, Map<String, String> env,
914919
[String label]) async {
915920
var flutterRepo = await FlutterRepo.copyFromExistingFlutterRepo(

tool/subprocess_launcher.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ class CoverageSubprocessLauncher extends SubprocessLauncher {
2525
Platform.environment.containsKey('COVERAGE_TOKEN');
2626

2727
/// A list of all coverage results picked up by all launchers.
28-
static List<Future<Iterable<Map>>> coverageResults = [];
28+
// TODO(srawlins): Refactor this to one or more type aliases once the feature
29+
// is enabled.
30+
static List<Future<Iterable<Map<Object, Object>>>> coverageResults = [];
2931

3032
static Directory _tempDir;
3133
static Directory get tempDir {
@@ -71,7 +73,8 @@ class CoverageSubprocessLauncher extends SubprocessLauncher {
7173
}
7274

7375
@override
74-
Future<Iterable<Map>> runStreamed(String executable, List<String> arguments,
76+
Future<Iterable<Map<Object, Object>>> runStreamed(
77+
String executable, List<String> arguments,
7578
{String workingDirectory,
7679
Map<String, String> environment,
7780
bool includeParentEnvironment = true,
@@ -92,7 +95,7 @@ class CoverageSubprocessLauncher extends SubprocessLauncher {
9295
}
9396
}
9497

95-
Completer<Iterable<Map>> coverageResult;
98+
Completer<Iterable<Map<Object, Object>>> coverageResult;
9699

97100
if (coverageEnabled) {
98101
coverageResult = Completer();
@@ -168,21 +171,22 @@ class SubprocessLauncher {
168171
/// Windows (though some of the bashisms will no longer make sense).
169172
/// TODO(jcollins-g): refactor to return a stream of stderr/stdout lines
170173
/// and their associated JSON objects.
171-
Future<Iterable<Map>> runStreamed(String executable, List<String> arguments,
174+
Future<Iterable<Map<Object, Object>>> runStreamed(
175+
String executable, List<String> arguments,
172176
{String workingDirectory,
173177
Map<String, String> environment,
174178
bool includeParentEnvironment = true,
175179
void Function(String) perLine}) async {
176180
environment ??= {};
177181
environment.addAll(environmentDefaults);
178-
List<Map> jsonObjects;
182+
List<Map<Object, Object>> jsonObjects;
179183

180184
/// Allow us to pretend we didn't pass the JSON flag in to dartdoc by
181185
/// printing what dartdoc would have printed without it, yet storing
182186
/// json objects into [jsonObjects].
183187
Iterable<String> jsonCallback(String line) {
184188
if (perLine != null) perLine(line);
185-
Map result;
189+
Map<Object, Object> result;
186190
try {
187191
result = json.decoder.convert(line);
188192
} on FormatException {

0 commit comments

Comments
 (0)