From 93f2c59631fa9b6250bb05507576851d94e10977 Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Thu, 30 Dec 2021 20:33:20 -0600 Subject: [PATCH 1/4] Minor cleanup to lints and top level files --- analysis_options.yaml | 26 +++++++++++-------------- analysis_options_presubmit.yaml | 26 +++++++++++-------------- lib/src/comment_references/parser.dart | 7 ++++--- lib/src/dartdoc.dart | 2 +- lib/src/dartdoc_options.dart | 6 ++++-- lib/src/model/getter_setter_combo.dart | 2 +- lib/src/model/model_element.dart | 6 +++--- lib/src/model/model_object_builder.dart | 6 +++--- lib/src/model/package_graph.dart | 2 +- lib/src/mustachio/parser.dart | 2 +- lib/src/package_meta.dart | 7 ++----- lib/src/special_elements.dart | 12 ++++++------ lib/src/tool_definition.dart | 18 +++++++++-------- lib/src/tool_runner.dart | 3 +-- test/mustachio/parser_test.dart | 4 ++-- tool/grind.dart | 2 +- tool/subprocess_launcher.dart | 4 ++-- 17 files changed, 64 insertions(+), 71 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 3096bb152d..51ab358a96 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -19,18 +19,14 @@ analyzer: - 'testing/test_package_export_error/**' linter: rules: - always_declare_return_types: true - avoid_dynamic_calls: true - avoid_single_cascade_in_expression_statements: true - avoid_unused_constructor_parameters: true - avoid_init_to_null: true - directives_ordering: true - no_adjacent_strings_in_list: true - package_api_docs: true - prefer_final_fields: true - prefer_initializing_formals: true - prefer_void_to_null: true - slash_for_doc_comments: true - type_annotate_public_apis: true - # Work in progress canonical score lints - unawaited_futures: true + - always_declare_return_types + - always_put_required_named_parameters_first + - avoid_bool_literals_in_conditional_expressions + - avoid_unused_constructor_parameters + - directives_ordering + - no_adjacent_strings_in_list + - package_api_docs + - prefer_single_quotes + - sort_child_properties_last + - unawaited_futures + - unnecessary_null_aware_assignments diff --git a/analysis_options_presubmit.yaml b/analysis_options_presubmit.yaml index ea08217fac..8b33a961ff 100644 --- a/analysis_options_presubmit.yaml +++ b/analysis_options_presubmit.yaml @@ -24,18 +24,14 @@ analyzer: - 'testing/test_package_export_error/**' linter: rules: - always_declare_return_types: true - avoid_dynamic_calls: true - avoid_single_cascade_in_expression_statements: true - avoid_unused_constructor_parameters: true - avoid_init_to_null: true - directives_ordering: true - no_adjacent_strings_in_list: true - package_api_docs: true - prefer_final_fields: true - prefer_initializing_formals: true - prefer_void_to_null: true - slash_for_doc_comments: true - type_annotate_public_apis: true - # Work in progress canonical score lints - unawaited_futures: true + - always_declare_return_types + - always_put_required_named_parameters_first + - avoid_bool_literals_in_conditional_expressions + - avoid_unused_constructor_parameters + - directives_ordering + - no_adjacent_strings_in_list + - package_api_docs + - prefer_single_quotes + - sort_child_properties_last + - unawaited_futures + - unnecessary_null_aware_assignments diff --git a/lib/src/comment_references/parser.dart b/lib/src/comment_references/parser.dart index f04b677109..5ed2aea08f 100644 --- a/lib/src/comment_references/parser.dart +++ b/lib/src/comment_references/parser.dart @@ -48,9 +48,10 @@ class StringTrie { return valid ? index : lastValid; } var matchChar = toMatch.codeUnitAt(index); - if (children.containsKey(matchChar)) { + var matchedChild = children[matchChar]; + if (matchedChild != null) { lastValid = valid ? index : lastValid; - return children[matchChar]!.match(toMatch, index + 1, lastValid); + return matchedChild.match(toMatch, index + 1, lastValid); } return valid ? index : lastValid; } @@ -65,7 +66,7 @@ class StringTrie { } } -late final StringTrie operatorParseTrie = () { +final StringTrie operatorParseTrie = () { var _operatorParseTrie = StringTrie(); for (var name in operatorNames.keys) { _operatorParseTrie.addWord(name); diff --git a/lib/src/dartdoc.dart b/lib/src/dartdoc.dart index d15bc05b09..9c38593eae 100644 --- a/lib/src/dartdoc.dart +++ b/lib/src/dartdoc.dart @@ -352,7 +352,7 @@ class Dartdoc { var stringLinks = links .map((link) => link.attributes['href']) .whereType() - .where((href) => href != '') + .where((href) => href.isNotEmpty) .toList(); return Tuple2(stringLinks, baseHref); diff --git a/lib/src/dartdoc_options.dart b/lib/src/dartdoc_options.dart index 24d1c9f2df..eac2d5770d 100644 --- a/lib/src/dartdoc_options.dart +++ b/lib/src/dartdoc_options.dart @@ -1467,13 +1467,15 @@ Future> createDartdocOptions( // ignore: unnecessary_null_comparison if (inSdk != null) { Map sdks = option.parent['sdks'].valueAt(dir); - if (sdks.containsKey(inSdk)) return sdks[inSdk]!; + var inSdkVal = sdks[inSdk]; + if (inSdkVal != null) return inSdkVal; } var hostedAt = packageMeta.hostedAt; // ignore: unnecessary_null_comparison if (hostedAt != null) { Map hostMap = option.parent['hosted'].valueAt(dir); - if (hostMap.containsKey(hostedAt)) return hostMap[hostedAt]!; + var hostedAtVal = hostMap[hostedAt]; + if (hostedAtVal != null) return hostedAtVal; } return ''; }, resourceProvider, help: 'Url to use for this particular package.'), diff --git a/lib/src/model/getter_setter_combo.dart b/lib/src/model/getter_setter_combo.dart index 1ac12f0d03..6f19cd3ca1 100644 --- a/lib/src/model/getter_setter_combo.dart +++ b/lib/src/model/getter_setter_combo.dart @@ -154,7 +154,7 @@ mixin GetterSetterCombo on ModelElement { buffer.write(getter!.oneLineDoc); } if (hasPublicSetter && setter!.oneLineDoc!.isNotEmpty) { - buffer.write(getterSetterBothAvailable ? "" : setter!.oneLineDoc); + buffer.write(getterSetterBothAvailable ? '' : setter!.oneLineDoc); } _oneLineDoc = buffer.toString(); } diff --git a/lib/src/model/model_element.dart b/lib/src/model/model_element.dart index 268b814daa..a1121d73dc 100644 --- a/lib/src/model/model_element.dart +++ b/lib/src/model/model_element.dart @@ -157,9 +157,9 @@ abstract class ModelElement extends Canonicalization /// if and only if this is to be an inherited or extended object. factory ModelElement._fromPropertyInducingElement( PropertyInducingElement e, Library library, PackageGraph packageGraph, - {Container? enclosingContainer, - required Accessor? getter, - required Accessor? setter}) { + {required Accessor? getter, + required Accessor? setter, + Container? enclosingContainer}) { // TODO(jcollins-g): Refactor object model to instantiate 'ModelMembers' // for members? if (e is Member) { diff --git a/lib/src/model/model_object_builder.dart b/lib/src/model/model_object_builder.dart index c9dafd9d4e..71a4b3faa9 100644 --- a/lib/src/model/model_object_builder.dart +++ b/lib/src/model/model_object_builder.dart @@ -20,9 +20,9 @@ abstract class ModelElementBuilder { ModelElement fromElement(Element e); ModelElement fromPropertyInducingElement(Element e, Library l, - {Container enclosingContainer, - required Accessor? getter, - required Accessor? setter}); + {required Accessor? getter, + required Accessor? setter, + Container enclosingContainer}); } abstract class ElementTypeBuilder { diff --git a/lib/src/model/package_graph.dart b/lib/src/model/package_graph.dart index f289a89fe5..bbce8b22e5 100644 --- a/lib/src/model/package_graph.dart +++ b/lib/src/model/package_graph.dart @@ -10,7 +10,7 @@ import 'package:analyzer/file_system/file_system.dart'; // ignore: implementation_imports import 'package:analyzer/src/generated/sdk.dart' show DartSdk, SdkLibrary; // ignore: implementation_imports -import 'package:analyzer/src/generated/source_io.dart' show Source; +import 'package:analyzer/src/generated/source.dart' show Source; import 'package:dartdoc/src/dartdoc_options.dart'; import 'package:dartdoc/src/failure.dart'; import 'package:dartdoc/src/logging.dart'; diff --git a/lib/src/mustachio/parser.dart b/lib/src/mustachio/parser.dart index fbd4136ef5..1bfac2fda1 100644 --- a/lib/src/mustachio/parser.dart +++ b/lib/src/mustachio/parser.dart @@ -562,7 +562,7 @@ class _KeyParseResult { final List names; /// The source span from where this key was parsed, if this represents a - /// parsed key, othwerwise `null`. + /// parsed key, otherwise `null`. final SourceSpan? span; const _KeyParseResult._(this.type, this.names, {this.span}); diff --git a/lib/src/package_meta.dart b/lib/src/package_meta.dart index 9e267fe511..e7c226e321 100644 --- a/lib/src/package_meta.dart +++ b/lib/src/package_meta.dart @@ -4,7 +4,6 @@ library dartdoc.package_meta; -import 'dart:convert'; import 'dart:io' show Platform, Process; import 'package:analyzer/dart/element/element.dart'; @@ -20,9 +19,7 @@ import 'package:yaml/yaml.dart'; import 'logging.dart'; -Map _packageMetaCache = {}; - -Encoding utf8AllowMalformed = Utf8Codec(allowMalformed: true); +final Map _packageMetaCache = {}; class PackageMetaFailure extends DartdocFailure { PackageMetaFailure(String message) : super(message); @@ -174,7 +171,7 @@ abstract class PubPackageMeta extends PackageMeta { PubPackageMeta(Folder dir, ResourceProvider resourceProvider) : super(dir, resourceProvider); - static late final List> _sdkDirFilePaths = () { + static final List> _sdkDirFilePaths = () { var pathsToReturn = >[]; if (Platform.isWindows) { for (var paths in _sdkDirFilePathsPosix) { diff --git a/lib/src/special_elements.dart b/lib/src/special_elements.dart index 49907b57c2..f1f8cf8734 100644 --- a/lib/src/special_elements.dart +++ b/lib/src/special_elements.dart @@ -99,12 +99,12 @@ class SpecialClasses { /// Add a class object that could be special. void addSpecial(Class aClass) { - if (_specialClassDefinitions.containsKey(aClass.name)) { - var d = _specialClassDefinitions[aClass.name]!; - if (d.matchesClass(aClass)) { - assert(!_specialClass.containsKey(d.specialClass) || - _specialClass[d.specialClass] == aClass); - _specialClass[d.specialClass] = aClass; + var def = _specialClassDefinitions[aClass.name]; + if (def != null) { + if (def.matchesClass(aClass)) { + assert(!_specialClass.containsKey(def.specialClass) || + _specialClass[def.specialClass] == aClass); + _specialClass[def.specialClass] = aClass; } } } diff --git a/lib/src/tool_definition.dart b/lib/src/tool_definition.dart index 44ec3116e2..e18cda9193 100644 --- a/lib/src/tool_definition.dart +++ b/lib/src/tool_definition.dart @@ -81,7 +81,7 @@ class ToolDefinition { Future toolStateForArgs(String toolName, List args, {required ToolErrorCallback toolErrorCallback}) async { var commandPath = args.removeAt(0); - return ToolStateForArgs(commandPath, args, null); + return ToolStateForArgs(commandPath, args); } } @@ -124,7 +124,7 @@ class DartToolDefinition extends ToolDefinition { ...compileArgs, ...args, ], - snapshot._snapshotCompleted); + onProcessComplete: snapshot._snapshotCompleted); } else { await snapshot._snapshotValid(); if (!snapshotFile.exists) { @@ -135,7 +135,7 @@ class DartToolDefinition extends ToolDefinition { // replace the first argument with the path to the snapshot. args[0] = snapshotPath; } - return ToolStateForArgs(_resourceProvider.resolvedExecutable, args, null); + return ToolStateForArgs(_resourceProvider.resolvedExecutable, args); } } @@ -227,13 +227,15 @@ class SnapshotCache { } _Snapshot getSnapshot(String toolPath) { - if (snapshots.containsKey(toolPath)) { - return snapshots[toolPath]!; + var toolSnapshot = snapshots[toolPath]; + if (toolSnapshot != null) { + return toolSnapshot; } - snapshots[toolPath] = + toolSnapshot = _Snapshot(snapshotCache, toolPath, _serial, _resourceProvider); + snapshots[toolPath] = toolSnapshot; _serial++; - return snapshots[toolPath]!; + return toolSnapshot; } void dispose() { @@ -249,5 +251,5 @@ class ToolStateForArgs { final List args; final void Function()? onProcessComplete; - ToolStateForArgs(this.commandPath, this.args, this.onProcessComplete); + ToolStateForArgs(this.commandPath, this.args, {this.onProcessComplete}); } diff --git a/lib/src/tool_runner.dart b/lib/src/tool_runner.dart index 1b214f12be..e683a7e5a7 100644 --- a/lib/src/tool_runner.dart +++ b/lib/src/tool_runner.dart @@ -139,8 +139,7 @@ class ToolRunner { Future _run(List args, {required ToolErrorCallback toolErrorCallback, - String content = '', - required Map environment}) async { + required Map environment, String content = ''}) async { assert(args.isNotEmpty); var toolName = args.removeAt(0); if (!toolConfiguration.tools.containsKey(toolName)) { diff --git a/test/mustachio/parser_test.dart b/test/mustachio/parser_test.dart index 6fe0d53cc6..90caa87656 100644 --- a/test/mustachio/parser_test.dart +++ b/test/mustachio/parser_test.dart @@ -426,9 +426,9 @@ void _expectText(MustachioNode node, Object matcher, void _expectVariable( MustachioNode node, Object matcher, { - bool escape = true, required int spanStart, required int spanEnd, + bool escape = true, int? keySpanStart, int? keySpanEnd, }) { @@ -459,9 +459,9 @@ void _expectVariable( void _expectSection( MustachioNode node, Object matcher, { - bool invert = false, required int spanStart, required int spanEnd, + bool invert = false, int? keySpanStart, int? keySpanEnd, }) { diff --git a/tool/grind.dart b/tool/grind.dart index b5d66bee53..13d0a88e94 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -849,7 +849,7 @@ $analyzerOptions '--link-to-remote', '--show-progress', '--enable-experiment', - languageExperiments.join(","), + languageExperiments.join(','), ...extraDartdocParameters, ], workingDirectory: languageTestPackageDir.absolute.path); diff --git a/tool/subprocess_launcher.dart b/tool/subprocess_launcher.dart index c0ada7434d..92b6480266 100644 --- a/tool/subprocess_launcher.dart +++ b/tool/subprocess_launcher.dart @@ -138,8 +138,8 @@ class SubprocessLauncher { // from flutter:dev/tools/dartdoc.dart, modified static Future _printStream(Stream> stream, Stdout output, - {String prefix = '', - required Iterable Function(String line) filter}) { + {required Iterable Function(String line) filter, + String prefix = ''}) { return stream .transform(utf8.decoder) .transform(const LineSplitter()) From 36c811a403142de9eff790147632bcc30a4b659d Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Thu, 30 Dec 2021 20:51:28 -0600 Subject: [PATCH 2/4] Format tool runner --- lib/src/tool_runner.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/tool_runner.dart b/lib/src/tool_runner.dart index e683a7e5a7..cd7e941dda 100644 --- a/lib/src/tool_runner.dart +++ b/lib/src/tool_runner.dart @@ -139,7 +139,8 @@ class ToolRunner { Future _run(List args, {required ToolErrorCallback toolErrorCallback, - required Map environment, String content = ''}) async { + required Map environment, + String content = ''}) async { assert(args.isNotEmpty); var toolName = args.removeAt(0); if (!toolConfiguration.tools.containsKey(toolName)) { From 99d0f021773872e7b2838d98d03a029c0fedc552 Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Thu, 30 Dec 2021 21:04:10 -0600 Subject: [PATCH 3/4] Some minor fixes --- lib/src/element_type.dart | 2 +- lib/src/model/comment_referable.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/element_type.dart b/lib/src/element_type.dart index 4779815ab7..0483c215ee 100644 --- a/lib/src/element_type.dart +++ b/lib/src/element_type.dart @@ -227,7 +227,7 @@ class ParameterizedElementType extends DefinedElementType with Rendered { .toList(growable: false); } -/// A [ElementType] whose underlying type was referrred to by a type alias. +/// A [ElementType] whose underlying type was referred to by a type alias. mixin Aliased implements ElementType, ModelBuilderInterface { late final Element typeAliasElement = type.alias!.element; diff --git a/lib/src/model/comment_referable.dart b/lib/src/model/comment_referable.dart index 7c3f022b04..a6c4e56f82 100644 --- a/lib/src/model/comment_referable.dart +++ b/lib/src/model/comment_referable.dart @@ -39,7 +39,7 @@ extension on Scope { /// A set of utility methods for helping build /// [CommentReferable.referenceChildren] out of collections of other -/// [CommmentReferable]s. +/// [CommentReferable]s. extension CommentReferableEntryGenerators on Iterable { /// Creates ordinary references except if there is a conflict with /// [referable], it will generate a [MapEntry] using [referable]'s From 6b3dbc9a49c13f7c02bb60318927d668b7dc9157 Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Thu, 30 Dec 2021 21:50:56 -0600 Subject: [PATCH 4/4] def -> definition --- lib/src/special_elements.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/src/special_elements.dart b/lib/src/special_elements.dart index f1f8cf8734..00bff6295d 100644 --- a/lib/src/special_elements.dart +++ b/lib/src/special_elements.dart @@ -99,12 +99,12 @@ class SpecialClasses { /// Add a class object that could be special. void addSpecial(Class aClass) { - var def = _specialClassDefinitions[aClass.name]; - if (def != null) { - if (def.matchesClass(aClass)) { - assert(!_specialClass.containsKey(def.specialClass) || - _specialClass[def.specialClass] == aClass); - _specialClass[def.specialClass] = aClass; + var definition = _specialClassDefinitions[aClass.name]; + if (definition != null) { + if (definition.matchesClass(aClass)) { + assert(!_specialClass.containsKey(definition.specialClass) || + _specialClass[definition.specialClass] == aClass); + _specialClass[definition.specialClass] = aClass; } } }