Skip to content

Enforce strict-raw-types #2791

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 4 commits into from
Sep 27, 2021
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
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ analyzer:
todo: ignore
unused_import: warning
unused_shown_name: warning
language:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably should be added to analysis_options_presubmit.yaml?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

strict-raw-types: true
exclude:
- 'doc/**'
- 'lib/src/third_party/pkg/**'
Expand Down
2 changes: 2 additions & 0 deletions analysis_options_presubmit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ analyzer:
### Extra ignores for presubmit
deprecated_member_use: ignore
deprecated_member_use_from_same_package: ignore
language:
strict-raw-types: true
exclude:
- 'doc/**'
- 'lib/src/third_party/pkg/**'
Expand Down
2 changes: 1 addition & 1 deletion lib/src/dartdoc_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ class _OptionValueWithContext<T> {
///
/// Use via implementations [DartdocOptionSet], [DartdocOptionArgFile],
/// [DartdocOptionArgOnly], and [DartdocOptionFileOnly].
abstract class DartdocOption<T> {
abstract class DartdocOption<T extends Object> {
/// This is the value returned if we couldn't find one otherwise.
final T defaultsTo;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/io_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class _TaskQueueItem<T> {
/// the number of simultaneous tasks.
///
/// The tasks return results of type T.
class TaskQueue<T> {
class TaskQueue<T extends Object> {
/// Creates a task queue with a maximum number of simultaneous jobs.
/// The [maxJobs] parameter defaults to the number of CPU cores on the
/// system.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/mustachio/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Renderer {
final Symbol name;

/// The type of the context type, specified as the [Context] type argument.
final Context context;
final Context<Object> context;

/// The unparsed, string form of the URI of the _standard_ HTML template.
///
Expand Down
6 changes: 3 additions & 3 deletions lib/src/mustachio/renderer_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ class Template {
}

/// The base class for a generated Mustache renderer.
abstract class RendererBase<T> {
abstract class RendererBase<T extends Object> {
/// The context object which this renderer can render.
final T context;

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

/// The current template being rendered.
///
Expand Down Expand Up @@ -288,7 +288,7 @@ abstract class RendererBase<T> {

String renderSimple(
Object context, List<MustachioNode> ast, Template template, StringSink sink,
{@required RendererBase parent, Set<String> getters}) {
{@required RendererBase<Object> parent, Set<String> getters}) {
var renderer = SimpleRenderer(context, parent, template, sink, getters);
renderer.renderBlock(ast);
return renderer.sink.toString();
Expand Down
5 changes: 3 additions & 2 deletions test/html_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,13 @@ const Matcher doesExist = _DoesExist();
class _DoesExist extends Matcher {
const _DoesExist();
@override
bool matches(Object item, Map matchState) => (item as Resource).exists;
bool matches(Object item, Map<Object, Object> matchState) =>
(item as Resource).exists;
@override
Description describe(Description description) => description.add('exists');
@override
Description describeMismatch(Object item, Description mismatchDescription,
Map matchState, bool verbose) {
Map<Object, Object> matchState, bool verbose) {
if (item is! File && item is! Folder) {
return mismatchDescription
.addDescriptionOf(item)
Expand Down
39 changes: 22 additions & 17 deletions tool/grind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void presubmit() => null;
void buildbot() => null;

@Task('Generate docs for the Dart SDK')
Future buildSdkDocs() async {
Future<void> buildSdkDocs() async {
log('building SDK docs');
await _buildSdkDocs(sdkDocsDir.path, Future.value(Directory.current.path));
}
Expand Down Expand Up @@ -426,8 +426,11 @@ class WarningsCollection {
}

/// Returns a map of warning texts to the number of times each has been seen.
WarningsCollection jsonMessageIterableToWarnings(Iterable<Map> messageIterable,
String tempPath, String pubDir, String branch) {
WarningsCollection jsonMessageIterableToWarnings(
Iterable<Map<Object, Object>> messageIterable,
String tempPath,
String pubDir,
String branch) {
var warningTexts = WarningsCollection(tempPath, pubDir, branch);
if (messageIterable == null) return warningTexts;
for (Map<String, dynamic> message in messageIterable) {
Expand All @@ -442,13 +445,13 @@ WarningsCollection jsonMessageIterableToWarnings(Iterable<Map> messageIterable,
}

@Task('Display delta in SDK warnings')
Future compareSdkWarnings() async {
Future<void> compareSdkWarnings() async {
var originalDartdocSdkDocs =
Directory.systemTemp.createTempSync('dartdoc-comparison-sdkdocs');
Future originalDartdoc = createComparisonDartdoc();
Future currentDartdocSdkBuild = _buildSdkDocs(
var originalDartdoc = createComparisonDartdoc();
var currentDartdocSdkBuild = _buildSdkDocs(
sdkDocsDir.path, Future.value(Directory.current.path), 'current');
Future originalDartdocSdkBuild =
var originalDartdocSdkBuild =
_buildSdkDocs(originalDartdocSdkDocs.path, originalDartdoc, 'original');
var currentDartdocWarnings = jsonMessageIterableToWarnings(
await currentDartdocSdkBuild, sdkDocsDir.absolute.path, null, 'HEAD');
Expand Down Expand Up @@ -540,7 +543,8 @@ Future<void> testWithAnalyzerSdk() async {
workingDirectory: sdkDartdoc);
}

Future<List<Map>> _buildSdkDocs(String sdkDocsPath, Future<String> futureCwd,
Future<List<Map<Object, Object>>> _buildSdkDocs(
String sdkDocsPath, Future<String> futureCwd,
[String label]) async {
label ??= '';
if (label != '') label = '-$label';
Expand All @@ -562,15 +566,16 @@ Future<List<Map>> _buildSdkDocs(String sdkDocsPath, Future<String> futureCwd,
workingDirectory: cwd);
}

Future<List<Map>> _buildTestPackageDocs(String outputDir, String cwd,
Future<List<Map<Object, Object>>> _buildTestPackageDocs(
String outputDir, String cwd,
{List<String> params, String label = '', String testPackagePath}) async {
if (label != '') label = '-$label';
testPackagePath ??= testPackage.absolute.path;
params ??= [];
var launcher = SubprocessLauncher('build-test-package-docs$label');
Future testPackagePubGet = launcher.runStreamed(sdkBin('pub'), ['get'],
var testPackagePubGet = launcher.runStreamed(sdkBin('pub'), ['get'],
workingDirectory: testPackagePath);
Future dartdocPubGet =
var dartdocPubGet =
launcher.runStreamed(sdkBin('pub'), ['get'], workingDirectory: cwd);
await Future.wait([testPackagePubGet, dartdocPubGet]);
return await launcher.runStreamed(
Expand Down Expand Up @@ -687,12 +692,12 @@ Future<void> serveSdkDocs() async {
Future<void> compareFlutterWarnings() async {
var originalDartdocFlutter =
Directory.systemTemp.createTempSync('dartdoc-comparison-flutter');
Future originalDartdoc = createComparisonDartdoc();
var originalDartdoc = createComparisonDartdoc();
var envCurrent = _createThrowawayPubCache();
var envOriginal = _createThrowawayPubCache();
Future currentDartdocFlutterBuild = _buildFlutterDocs(flutterDir.path,
var currentDartdocFlutterBuild = _buildFlutterDocs(flutterDir.path,
Future.value(Directory.current.path), envCurrent, 'docs-current');
Future originalDartdocFlutterBuild = _buildFlutterDocs(
var originalDartdocFlutterBuild = _buildFlutterDocs(
originalDartdocFlutter.path,
originalDartdoc,
envOriginal,
Expand All @@ -714,7 +719,7 @@ Future<void> compareFlutterWarnings() async {
if (Platform.environment['SERVE_FLUTTER'] == '1') {
var launcher = SubprocessLauncher('serve-flutter-docs');
await launcher.runStreamed(sdkBin('pub'), ['get']);
Future original = launcher.runStreamed(sdkBin('pub'), [
var original = launcher.runStreamed(sdkBin('pub'), [
'global',
'run',
'dhttpd',
Expand All @@ -723,7 +728,7 @@ Future<void> compareFlutterWarnings() async {
'--path',
path.join(originalDartdocFlutter.absolute.path, 'dev', 'docs', 'doc'),
]);
Future current = launcher.runStreamed(sdkBin('pub'), [
var current = launcher.runStreamed(sdkBin('pub'), [
'global',
'run',
'dhttpd',
Expand Down Expand Up @@ -909,7 +914,7 @@ class FlutterRepo {
SubprocessLauncher launcher;
}

Future<List<Map>> _buildFlutterDocs(
Future<List<Map<Object, Object>>> _buildFlutterDocs(
String flutterPath, Future<String> futureCwd, Map<String, String> env,
[String label]) async {
var flutterRepo = await FlutterRepo.copyFromExistingFlutterRepo(
Expand Down
16 changes: 10 additions & 6 deletions tool/subprocess_launcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ class CoverageSubprocessLauncher extends SubprocessLauncher {
Platform.environment.containsKey('COVERAGE_TOKEN');

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

static Directory _tempDir;
static Directory get tempDir {
Expand Down Expand Up @@ -71,7 +73,8 @@ class CoverageSubprocessLauncher extends SubprocessLauncher {
}

@override
Future<Iterable<Map>> runStreamed(String executable, List<String> arguments,
Future<Iterable<Map<Object, Object>>> runStreamed(
String executable, List<String> arguments,
{String workingDirectory,
Map<String, String> environment,
bool includeParentEnvironment = true,
Expand All @@ -92,7 +95,7 @@ class CoverageSubprocessLauncher extends SubprocessLauncher {
}
}

Completer<Iterable<Map>> coverageResult;
Completer<Iterable<Map<Object, Object>>> coverageResult;

if (coverageEnabled) {
coverageResult = Completer();
Expand Down Expand Up @@ -168,21 +171,22 @@ class SubprocessLauncher {
/// Windows (though some of the bashisms will no longer make sense).
/// TODO(jcollins-g): refactor to return a stream of stderr/stdout lines
/// and their associated JSON objects.
Future<Iterable<Map>> runStreamed(String executable, List<String> arguments,
Future<Iterable<Map<Object, Object>>> runStreamed(
String executable, List<String> arguments,
{String workingDirectory,
Map<String, String> environment,
bool includeParentEnvironment = true,
void Function(String) perLine}) async {
environment ??= {};
environment.addAll(environmentDefaults);
List<Map> jsonObjects;
List<Map<Object, Object>> jsonObjects;

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