From a2449d8b2d036ab07f549c9d0bd24e6562e7e30c Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Thu, 16 Sep 2021 12:41:50 -0700 Subject: [PATCH 1/2] Enforce strict-raw-types --- analysis_options.yaml | 2 ++ lib/src/dartdoc_options.dart | 2 +- lib/src/io_utils.dart | 2 +- lib/src/mustachio/annotations.dart | 2 +- lib/src/mustachio/renderer_base.dart | 6 ++--- test/html_generator_test.dart | 5 ++-- tool/grind.dart | 39 ++++++++++++++++------------ tool/subprocess_launcher.dart | 16 +++++++----- 8 files changed, 43 insertions(+), 31 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 73752b0ec1..261318542d 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -7,6 +7,8 @@ analyzer: todo: ignore unused_import: warning unused_shown_name: warning + language: + strict-raw-types: true exclude: - 'doc/**' - 'lib/src/third_party/pkg/**' diff --git a/lib/src/dartdoc_options.dart b/lib/src/dartdoc_options.dart index 9c83b85068..624710598c 100644 --- a/lib/src/dartdoc_options.dart +++ b/lib/src/dartdoc_options.dart @@ -337,7 +337,7 @@ class _OptionValueWithContext { /// /// Use via implementations [DartdocOptionSet], [DartdocOptionArgFile], /// [DartdocOptionArgOnly], and [DartdocOptionFileOnly]. -abstract class DartdocOption { +abstract class DartdocOption { /// This is the value returned if we couldn't find one otherwise. final T defaultsTo; diff --git a/lib/src/io_utils.dart b/lib/src/io_utils.dart index 2be1ffa625..0cf7693ad4 100644 --- a/lib/src/io_utils.dart +++ b/lib/src/io_utils.dart @@ -144,7 +144,7 @@ class _TaskQueueItem { /// the number of simultaneous tasks. /// /// The tasks return results of type T. -class TaskQueue { +class TaskQueue { /// Creates a task queue with a maximum number of simultaneous jobs. /// The [maxJobs] parameter defaults to the number of CPU cores on the /// system. diff --git a/lib/src/mustachio/annotations.dart b/lib/src/mustachio/annotations.dart index 17e837983e..671ce0c9cd 100644 --- a/lib/src/mustachio/annotations.dart +++ b/lib/src/mustachio/annotations.dart @@ -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 context; /// The unparsed, string form of the URI of the _standard_ HTML template. /// diff --git a/lib/src/mustachio/renderer_base.dart b/lib/src/mustachio/renderer_base.dart index 85fcfa8f9d..e85f341cbf 100644 --- a/lib/src/mustachio/renderer_base.dart +++ b/lib/src/mustachio/renderer_base.dart @@ -132,12 +132,12 @@ class Template { } /// The base class for a generated Mustache renderer. -abstract class RendererBase { +abstract class RendererBase { /// 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 parent; /// The current template being rendered. /// @@ -288,7 +288,7 @@ abstract class RendererBase { String renderSimple( Object context, List ast, Template template, StringSink sink, - {@required RendererBase parent, Set getters}) { + {@required RendererBase parent, Set getters}) { var renderer = SimpleRenderer(context, parent, template, sink, getters); renderer.renderBlock(ast); return renderer.sink.toString(); diff --git a/test/html_generator_test.dart b/test/html_generator_test.dart index 899fb1b49d..7512184e43 100644 --- a/test/html_generator_test.dart +++ b/test/html_generator_test.dart @@ -160,12 +160,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 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 matchState, bool verbose) { if (item is! File && item is! Folder) { return mismatchDescription .addDescriptionOf(item) diff --git a/tool/grind.dart b/tool/grind.dart index 8fce2ae6c8..86f182dc55 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -322,7 +322,7 @@ void presubmit() => null; void buildbot() => null; @Task('Generate docs for the Dart SDK') -Future buildSdkDocs() async { +Future buildSdkDocs() async { log('building SDK docs'); await _buildSdkDocs(sdkDocsDir.path, Future.value(Directory.current.path)); } @@ -421,8 +421,11 @@ class WarningsCollection { } /// Returns a map of warning texts to the number of times each has been seen. -WarningsCollection jsonMessageIterableToWarnings(Iterable messageIterable, - String tempPath, String pubDir, String branch) { +WarningsCollection jsonMessageIterableToWarnings( + Iterable> messageIterable, + String tempPath, + String pubDir, + String branch) { var warningTexts = WarningsCollection(tempPath, pubDir, branch); if (messageIterable == null) return warningTexts; for (Map message in messageIterable) { @@ -437,13 +440,13 @@ WarningsCollection jsonMessageIterableToWarnings(Iterable messageIterable, } @Task('Display delta in SDK warnings') -Future compareSdkWarnings() async { +Future 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'); @@ -535,7 +538,8 @@ Future testWithAnalyzerSdk() async { workingDirectory: sdkDartdoc); } -Future> _buildSdkDocs(String sdkDocsPath, Future futureCwd, +Future>> _buildSdkDocs( + String sdkDocsPath, Future futureCwd, [String label]) async { label ??= ''; if (label != '') label = '-$label'; @@ -557,15 +561,16 @@ Future> _buildSdkDocs(String sdkDocsPath, Future futureCwd, workingDirectory: cwd); } -Future> _buildTestPackageDocs(String outputDir, String cwd, +Future>> _buildTestPackageDocs( + String outputDir, String cwd, {List 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( @@ -682,12 +687,12 @@ Future serveSdkDocs() async { Future 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, @@ -709,7 +714,7 @@ Future 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', @@ -718,7 +723,7 @@ Future 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', @@ -909,7 +914,7 @@ class FlutterRepo { SubprocessLauncher launcher; } -Future> _buildFlutterDocs( +Future>> _buildFlutterDocs( String flutterPath, Future futureCwd, Map env, [String label]) async { var flutterRepo = await FlutterRepo.copyFromExistingFlutterRepo( diff --git a/tool/subprocess_launcher.dart b/tool/subprocess_launcher.dart index e25646e753..3385f9d1d8 100644 --- a/tool/subprocess_launcher.dart +++ b/tool/subprocess_launcher.dart @@ -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>> coverageResults = []; + // TODO(srawlins): Refactor this to one or more type aliases once the feature + // is enabled. + static List>>> coverageResults = []; static Directory _tempDir; static Directory get tempDir { @@ -71,7 +73,8 @@ class CoverageSubprocessLauncher extends SubprocessLauncher { } @override - Future> runStreamed(String executable, List arguments, + Future>> runStreamed( + String executable, List arguments, {String workingDirectory, Map environment, bool includeParentEnvironment = true, @@ -92,7 +95,7 @@ class CoverageSubprocessLauncher extends SubprocessLauncher { } } - Completer> coverageResult; + Completer>> coverageResult; if (coverageEnabled) { coverageResult = Completer(); @@ -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> runStreamed(String executable, List arguments, + Future>> runStreamed( + String executable, List arguments, {String workingDirectory, Map environment, bool includeParentEnvironment = true, void Function(String) perLine}) async { environment ??= {}; environment.addAll(environmentDefaults); - List jsonObjects; + List> 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 jsonCallback(String line) { if (perLine != null) perLine(line); - Map result; + Map result; try { result = json.decoder.convert(line); } on FormatException { From d6e10fa1a82e68864ca2f39d556fbe4db9175d1e Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Fri, 17 Sep 2021 15:27:31 -0700 Subject: [PATCH 2/2] presubmit --- analysis_options_presubmit.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/analysis_options_presubmit.yaml b/analysis_options_presubmit.yaml index 26dffd27ac..6802b0962b 100644 --- a/analysis_options_presubmit.yaml +++ b/analysis_options_presubmit.yaml @@ -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/**'