Skip to content

Commit c573859

Browse files
authored
Minor cleanup to lints and some top level files (#2872)
1 parent e00f32f commit c573859

19 files changed

+67
-73
lines changed

analysis_options.yaml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,14 @@ analyzer:
1919
- 'testing/test_package_export_error/**'
2020
linter:
2121
rules:
22-
always_declare_return_types: true
23-
avoid_dynamic_calls: true
24-
avoid_single_cascade_in_expression_statements: true
25-
avoid_unused_constructor_parameters: true
26-
avoid_init_to_null: true
27-
directives_ordering: true
28-
no_adjacent_strings_in_list: true
29-
package_api_docs: true
30-
prefer_final_fields: true
31-
prefer_initializing_formals: true
32-
prefer_void_to_null: true
33-
slash_for_doc_comments: true
34-
type_annotate_public_apis: true
35-
# Work in progress canonical score lints
36-
unawaited_futures: true
22+
- always_declare_return_types
23+
- always_put_required_named_parameters_first
24+
- avoid_bool_literals_in_conditional_expressions
25+
- avoid_unused_constructor_parameters
26+
- directives_ordering
27+
- no_adjacent_strings_in_list
28+
- package_api_docs
29+
- prefer_single_quotes
30+
- sort_child_properties_last
31+
- unawaited_futures
32+
- unnecessary_null_aware_assignments

analysis_options_presubmit.yaml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,14 @@ analyzer:
2424
- 'testing/test_package_export_error/**'
2525
linter:
2626
rules:
27-
always_declare_return_types: true
28-
avoid_dynamic_calls: true
29-
avoid_single_cascade_in_expression_statements: true
30-
avoid_unused_constructor_parameters: true
31-
avoid_init_to_null: true
32-
directives_ordering: true
33-
no_adjacent_strings_in_list: true
34-
package_api_docs: true
35-
prefer_final_fields: true
36-
prefer_initializing_formals: true
37-
prefer_void_to_null: true
38-
slash_for_doc_comments: true
39-
type_annotate_public_apis: true
40-
# Work in progress canonical score lints
41-
unawaited_futures: true
27+
- always_declare_return_types
28+
- always_put_required_named_parameters_first
29+
- avoid_bool_literals_in_conditional_expressions
30+
- avoid_unused_constructor_parameters
31+
- directives_ordering
32+
- no_adjacent_strings_in_list
33+
- package_api_docs
34+
- prefer_single_quotes
35+
- sort_child_properties_last
36+
- unawaited_futures
37+
- unnecessary_null_aware_assignments

lib/src/comment_references/parser.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ class StringTrie {
4848
return valid ? index : lastValid;
4949
}
5050
var matchChar = toMatch.codeUnitAt(index);
51-
if (children.containsKey(matchChar)) {
51+
var matchedChild = children[matchChar];
52+
if (matchedChild != null) {
5253
lastValid = valid ? index : lastValid;
53-
return children[matchChar]!.match(toMatch, index + 1, lastValid);
54+
return matchedChild.match(toMatch, index + 1, lastValid);
5455
}
5556
return valid ? index : lastValid;
5657
}
@@ -65,7 +66,7 @@ class StringTrie {
6566
}
6667
}
6768

68-
late final StringTrie operatorParseTrie = () {
69+
final StringTrie operatorParseTrie = () {
6970
var _operatorParseTrie = StringTrie();
7071
for (var name in operatorNames.keys) {
7172
_operatorParseTrie.addWord(name);

lib/src/dartdoc.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ class Dartdoc {
352352
var stringLinks = links
353353
.map((link) => link.attributes['href'])
354354
.whereType<String>()
355-
.where((href) => href != '')
355+
.where((href) => href.isNotEmpty)
356356
.toList();
357357

358358
return Tuple2(stringLinks, baseHref);

lib/src/dartdoc_options.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,13 +1467,15 @@ Future<List<DartdocOption>> createDartdocOptions(
14671467
// ignore: unnecessary_null_comparison
14681468
if (inSdk != null) {
14691469
Map<String, String> sdks = option.parent['sdks'].valueAt(dir);
1470-
if (sdks.containsKey(inSdk)) return sdks[inSdk]!;
1470+
var inSdkVal = sdks[inSdk];
1471+
if (inSdkVal != null) return inSdkVal;
14711472
}
14721473
var hostedAt = packageMeta.hostedAt;
14731474
// ignore: unnecessary_null_comparison
14741475
if (hostedAt != null) {
14751476
Map<String, String> hostMap = option.parent['hosted'].valueAt(dir);
1476-
if (hostMap.containsKey(hostedAt)) return hostMap[hostedAt]!;
1477+
var hostedAtVal = hostMap[hostedAt];
1478+
if (hostedAtVal != null) return hostedAtVal;
14771479
}
14781480
return '';
14791481
}, resourceProvider, help: 'Url to use for this particular package.'),

lib/src/element_type.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class ParameterizedElementType extends DefinedElementType with Rendered {
227227
.toList(growable: false);
228228
}
229229

230-
/// A [ElementType] whose underlying type was referrred to by a type alias.
230+
/// A [ElementType] whose underlying type was referred to by a type alias.
231231
mixin Aliased implements ElementType, ModelBuilderInterface {
232232
late final Element typeAliasElement = type.alias!.element;
233233

lib/src/model/comment_referable.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extension on Scope {
3939

4040
/// A set of utility methods for helping build
4141
/// [CommentReferable.referenceChildren] out of collections of other
42-
/// [CommmentReferable]s.
42+
/// [CommentReferable]s.
4343
extension CommentReferableEntryGenerators on Iterable<CommentReferable> {
4444
/// Creates ordinary references except if there is a conflict with
4545
/// [referable], it will generate a [MapEntry] using [referable]'s

lib/src/model/getter_setter_combo.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ mixin GetterSetterCombo on ModelElement {
154154
buffer.write(getter!.oneLineDoc);
155155
}
156156
if (hasPublicSetter && setter!.oneLineDoc!.isNotEmpty) {
157-
buffer.write(getterSetterBothAvailable ? "" : setter!.oneLineDoc);
157+
buffer.write(getterSetterBothAvailable ? '' : setter!.oneLineDoc);
158158
}
159159
_oneLineDoc = buffer.toString();
160160
}

lib/src/model/model_element.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ abstract class ModelElement extends Canonicalization
157157
/// if and only if this is to be an inherited or extended object.
158158
factory ModelElement._fromPropertyInducingElement(
159159
PropertyInducingElement e, Library library, PackageGraph packageGraph,
160-
{Container? enclosingContainer,
161-
required Accessor? getter,
162-
required Accessor? setter}) {
160+
{required Accessor? getter,
161+
required Accessor? setter,
162+
Container? enclosingContainer}) {
163163
// TODO(jcollins-g): Refactor object model to instantiate 'ModelMembers'
164164
// for members?
165165
if (e is Member) {

lib/src/model/model_object_builder.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ abstract class ModelElementBuilder {
2020
ModelElement fromElement(Element e);
2121

2222
ModelElement fromPropertyInducingElement(Element e, Library l,
23-
{Container enclosingContainer,
24-
required Accessor? getter,
25-
required Accessor? setter});
23+
{required Accessor? getter,
24+
required Accessor? setter,
25+
Container enclosingContainer});
2626
}
2727

2828
abstract class ElementTypeBuilder {

lib/src/model/package_graph.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:analyzer/file_system/file_system.dart';
1010
// ignore: implementation_imports
1111
import 'package:analyzer/src/generated/sdk.dart' show DartSdk, SdkLibrary;
1212
// ignore: implementation_imports
13-
import 'package:analyzer/src/generated/source_io.dart' show Source;
13+
import 'package:analyzer/src/generated/source.dart' show Source;
1414
import 'package:dartdoc/src/dartdoc_options.dart';
1515
import 'package:dartdoc/src/failure.dart';
1616
import 'package:dartdoc/src/logging.dart';

lib/src/mustachio/parser.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ class _KeyParseResult {
562562
final List<String> names;
563563

564564
/// The source span from where this key was parsed, if this represents a
565-
/// parsed key, othwerwise `null`.
565+
/// parsed key, otherwise `null`.
566566
final SourceSpan? span;
567567

568568
const _KeyParseResult._(this.type, this.names, {this.span});

lib/src/package_meta.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
library dartdoc.package_meta;
66

7-
import 'dart:convert';
87
import 'dart:io' show Platform, Process;
98

109
import 'package:analyzer/dart/element/element.dart';
@@ -20,9 +19,7 @@ import 'package:yaml/yaml.dart';
2019

2120
import 'logging.dart';
2221

23-
Map<String, PackageMeta?> _packageMetaCache = {};
24-
25-
Encoding utf8AllowMalformed = Utf8Codec(allowMalformed: true);
22+
final Map<String, PackageMeta?> _packageMetaCache = {};
2623

2724
class PackageMetaFailure extends DartdocFailure {
2825
PackageMetaFailure(String message) : super(message);
@@ -174,7 +171,7 @@ abstract class PubPackageMeta extends PackageMeta {
174171
PubPackageMeta(Folder dir, ResourceProvider resourceProvider)
175172
: super(dir, resourceProvider);
176173

177-
static late final List<List<String>> _sdkDirFilePaths = () {
174+
static final List<List<String>> _sdkDirFilePaths = () {
178175
var pathsToReturn = <List<String>>[];
179176
if (Platform.isWindows) {
180177
for (var paths in _sdkDirFilePathsPosix) {

lib/src/special_elements.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ class SpecialClasses {
9999

100100
/// Add a class object that could be special.
101101
void addSpecial(Class aClass) {
102-
if (_specialClassDefinitions.containsKey(aClass.name)) {
103-
var d = _specialClassDefinitions[aClass.name]!;
104-
if (d.matchesClass(aClass)) {
105-
assert(!_specialClass.containsKey(d.specialClass) ||
106-
_specialClass[d.specialClass] == aClass);
107-
_specialClass[d.specialClass] = aClass;
102+
var definition = _specialClassDefinitions[aClass.name];
103+
if (definition != null) {
104+
if (definition.matchesClass(aClass)) {
105+
assert(!_specialClass.containsKey(definition.specialClass) ||
106+
_specialClass[definition.specialClass] == aClass);
107+
_specialClass[definition.specialClass] = aClass;
108108
}
109109
}
110110
}

lib/src/tool_definition.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class ToolDefinition {
8181
Future<ToolStateForArgs> toolStateForArgs(String toolName, List<String> args,
8282
{required ToolErrorCallback toolErrorCallback}) async {
8383
var commandPath = args.removeAt(0);
84-
return ToolStateForArgs(commandPath, args, null);
84+
return ToolStateForArgs(commandPath, args);
8585
}
8686
}
8787

@@ -124,7 +124,7 @@ class DartToolDefinition extends ToolDefinition {
124124
...compileArgs,
125125
...args,
126126
],
127-
snapshot._snapshotCompleted);
127+
onProcessComplete: snapshot._snapshotCompleted);
128128
} else {
129129
await snapshot._snapshotValid();
130130
if (!snapshotFile.exists) {
@@ -135,7 +135,7 @@ class DartToolDefinition extends ToolDefinition {
135135
// replace the first argument with the path to the snapshot.
136136
args[0] = snapshotPath;
137137
}
138-
return ToolStateForArgs(_resourceProvider.resolvedExecutable, args, null);
138+
return ToolStateForArgs(_resourceProvider.resolvedExecutable, args);
139139
}
140140
}
141141

@@ -227,13 +227,15 @@ class SnapshotCache {
227227
}
228228

229229
_Snapshot getSnapshot(String toolPath) {
230-
if (snapshots.containsKey(toolPath)) {
231-
return snapshots[toolPath]!;
230+
var toolSnapshot = snapshots[toolPath];
231+
if (toolSnapshot != null) {
232+
return toolSnapshot;
232233
}
233-
snapshots[toolPath] =
234+
toolSnapshot =
234235
_Snapshot(snapshotCache, toolPath, _serial, _resourceProvider);
236+
snapshots[toolPath] = toolSnapshot;
235237
_serial++;
236-
return snapshots[toolPath]!;
238+
return toolSnapshot;
237239
}
238240

239241
void dispose() {
@@ -249,5 +251,5 @@ class ToolStateForArgs {
249251
final List<String> args;
250252
final void Function()? onProcessComplete;
251253

252-
ToolStateForArgs(this.commandPath, this.args, this.onProcessComplete);
254+
ToolStateForArgs(this.commandPath, this.args, {this.onProcessComplete});
253255
}

lib/src/tool_runner.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ class ToolRunner {
139139

140140
Future<String> _run(List<String> args,
141141
{required ToolErrorCallback toolErrorCallback,
142-
String content = '',
143-
required Map<String, String> environment}) async {
142+
required Map<String, String> environment,
143+
String content = ''}) async {
144144
assert(args.isNotEmpty);
145145
var toolName = args.removeAt(0);
146146
if (!toolConfiguration.tools.containsKey(toolName)) {

test/mustachio/parser_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,9 @@ void _expectText(MustachioNode node, Object matcher,
426426
void _expectVariable(
427427
MustachioNode node,
428428
Object matcher, {
429-
bool escape = true,
430429
required int spanStart,
431430
required int spanEnd,
431+
bool escape = true,
432432
int? keySpanStart,
433433
int? keySpanEnd,
434434
}) {
@@ -459,9 +459,9 @@ void _expectVariable(
459459
void _expectSection(
460460
MustachioNode node,
461461
Object matcher, {
462-
bool invert = false,
463462
required int spanStart,
464463
required int spanEnd,
464+
bool invert = false,
465465
int? keySpanStart,
466466
int? keySpanEnd,
467467
}) {

tool/grind.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ $analyzerOptions
849849
'--link-to-remote',
850850
'--show-progress',
851851
'--enable-experiment',
852-
languageExperiments.join(","),
852+
languageExperiments.join(','),
853853
...extraDartdocParameters,
854854
],
855855
workingDirectory: languageTestPackageDir.absolute.path);

tool/subprocess_launcher.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ class SubprocessLauncher {
138138

139139
// from flutter:dev/tools/dartdoc.dart, modified
140140
static Future<void> _printStream(Stream<List<int>> stream, Stdout output,
141-
{String prefix = '',
142-
required Iterable<String> Function(String line) filter}) {
141+
{required Iterable<String> Function(String line) filter,
142+
String prefix = ''}) {
143143
return stream
144144
.transform(utf8.decoder)
145145
.transform(const LineSplitter())

0 commit comments

Comments
 (0)