Skip to content

Minor cleanup to lints and some top level files #2872

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
Dec 31, 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
26 changes: 11 additions & 15 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 11 additions & 15 deletions analysis_options_presubmit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions lib/src/comment_references/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class Dartdoc {
var stringLinks = links
.map((link) => link.attributes['href'])
.whereType<String>()
.where((href) => href != '')
.where((href) => href.isNotEmpty)
.toList();

return Tuple2(stringLinks, baseHref);
Expand Down
6 changes: 4 additions & 2 deletions lib/src/dartdoc_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1467,13 +1467,15 @@ Future<List<DartdocOption>> createDartdocOptions(
// ignore: unnecessary_null_comparison
if (inSdk != null) {
Map<String, String> 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<String, String> 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.'),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/element_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/comment_referable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommentReferable> {
/// Creates ordinary references except if there is a conflict with
/// [referable], it will generate a [MapEntry] using [referable]'s
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/getter_setter_combo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/model/model_object_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/package_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/mustachio/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ class _KeyParseResult {
final List<String> 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});
Expand Down
7 changes: 2 additions & 5 deletions lib/src/package_meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

library dartdoc.package_meta;

import 'dart:convert';
import 'dart:io' show Platform, Process;

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

import 'logging.dart';

Map<String, PackageMeta?> _packageMetaCache = {};

Encoding utf8AllowMalformed = Utf8Codec(allowMalformed: true);
final Map<String, PackageMeta?> _packageMetaCache = {};

class PackageMetaFailure extends DartdocFailure {
PackageMetaFailure(String message) : super(message);
Expand Down Expand Up @@ -174,7 +171,7 @@ abstract class PubPackageMeta extends PackageMeta {
PubPackageMeta(Folder dir, ResourceProvider resourceProvider)
: super(dir, resourceProvider);

static late final List<List<String>> _sdkDirFilePaths = () {
static final List<List<String>> _sdkDirFilePaths = () {
var pathsToReturn = <List<String>>[];
if (Platform.isWindows) {
for (var paths in _sdkDirFilePathsPosix) {
Expand Down
12 changes: 6 additions & 6 deletions lib/src/special_elements.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 definition = _specialClassDefinitions[aClass.name];
if (definition != null) {
if (definition.matchesClass(aClass)) {
assert(!_specialClass.containsKey(definition.specialClass) ||
_specialClass[definition.specialClass] == aClass);
_specialClass[definition.specialClass] = aClass;
}
}
}
Expand Down
18 changes: 10 additions & 8 deletions lib/src/tool_definition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ToolDefinition {
Future<ToolStateForArgs> toolStateForArgs(String toolName, List<String> args,
{required ToolErrorCallback toolErrorCallback}) async {
var commandPath = args.removeAt(0);
return ToolStateForArgs(commandPath, args, null);
return ToolStateForArgs(commandPath, args);
}
}

Expand Down Expand Up @@ -124,7 +124,7 @@ class DartToolDefinition extends ToolDefinition {
...compileArgs,
...args,
],
snapshot._snapshotCompleted);
onProcessComplete: snapshot._snapshotCompleted);
} else {
await snapshot._snapshotValid();
if (!snapshotFile.exists) {
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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() {
Expand All @@ -249,5 +251,5 @@ class ToolStateForArgs {
final List<String> args;
final void Function()? onProcessComplete;

ToolStateForArgs(this.commandPath, this.args, this.onProcessComplete);
ToolStateForArgs(this.commandPath, this.args, {this.onProcessComplete});
}
4 changes: 2 additions & 2 deletions lib/src/tool_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ class ToolRunner {

Future<String> _run(List<String> args,
{required ToolErrorCallback toolErrorCallback,
String content = '',
required Map<String, String> environment}) async {
required Map<String, String> environment,
String content = ''}) async {
assert(args.isNotEmpty);
var toolName = args.removeAt(0);
if (!toolConfiguration.tools.containsKey(toolName)) {
Expand Down
4 changes: 2 additions & 2 deletions test/mustachio/parser_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}) {
Expand Down Expand Up @@ -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,
}) {
Expand Down
2 changes: 1 addition & 1 deletion tool/grind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ $analyzerOptions
'--link-to-remote',
'--show-progress',
'--enable-experiment',
languageExperiments.join(","),
languageExperiments.join(','),
...extraDartdocParameters,
],
workingDirectory: languageTestPackageDir.absolute.path);
Expand Down
4 changes: 2 additions & 2 deletions tool/subprocess_launcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ class SubprocessLauncher {

// from flutter:dev/tools/dartdoc.dart, modified
static Future<void> _printStream(Stream<List<int>> stream, Stdout output,
{String prefix = '',
required Iterable<String> Function(String line) filter}) {
{required Iterable<String> Function(String line) filter,
String prefix = ''}) {
return stream
.transform(utf8.decoder)
.transform(const LineSplitter())
Expand Down