Skip to content

Commit

Permalink
Fix some type related lints (#3986)
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough authored Aug 14, 2023
1 parent f41c6c8 commit 78a39b0
Show file tree
Hide file tree
Showing 36 changed files with 95 additions and 106 deletions.
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ analyzer:

linter:
rules:
- always_declare_return_types
- avoid_catching_errors
- avoid_print
- avoid_private_typedef_functions
Expand All @@ -26,6 +27,7 @@ linter:
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
- no_runtimeType_toString
- omit_local_variable_types
- only_throw_errors
- package_api_docs
- prefer_asserts_in_initializer_lists
Expand All @@ -36,6 +38,7 @@ linter:
- sort_pub_dependencies
- test_types_in_equals
- throw_in_finally
- type_annotate_public_apis
- unawaited_futures
- unnecessary_lambdas
- unnecessary_null_aware_assignments
Expand Down
2 changes: 1 addition & 1 deletion lib/src/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ abstract class PubTopLevel {
log.Verbosity get verbosity;
bool get trace;

static addColorFlag(ArgParser argParser) {
static void addColorFlag(ArgParser argParser) {
argParser.addFlag(
'color',
help: 'Use colors in terminal output.\n'
Expand Down
2 changes: 1 addition & 1 deletion lib/src/command/add.dart
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ Specify multiple sdk packages with descriptors.''');
final name = ref.name;
final resultId = resultPackages.firstWhere((id) => id.name == name);

Object? description = pubspecDescription(
final description = pubspecDescription(
ref.withConstraint(
constraint ??
(ref.source is HostedSource
Expand Down
4 changes: 2 additions & 2 deletions lib/src/command/cache_preload.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ class CachePreloadCommand extends PubCommand {
usageException('No package to preload given.');
}

for (String packagePath in argResults.rest) {
for (final packagePath in argResults.rest) {
if (!fileExists(packagePath)) {
fail('Could not find file $packagePath.');
}
}
for (String archivePath in argResults.rest) {
for (final archivePath in argResults.rest) {
final id = await cache.hosted.preloadPackage(archivePath, cache);
final url = (id.description.description as HostedDescription).url;

Expand Down
4 changes: 3 additions & 1 deletion lib/src/command/deps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ class DepsCommand extends PubCommand {
buffer.writeln('- ${_labelPackage(package)}');

for (var dep in package.dependencies.values) {
buffer.writeln(' - ${log.bold(dep.name)} ${log.gray(dep.constraint)}');
buffer.writeln(
' - ${log.bold(dep.name)} ${log.gray(dep.constraint.toString())}',
);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/command/uploader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class UploaderCommand extends PubCommand {

@override
Future<void> runProtected() async {
String packageName = '<packageName>';
var packageName = '<packageName>';
try {
packageName = entrypoint.root.name;
} on Exception catch (_) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/command_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class PubCommandRunner extends CommandRunner<int> implements PubTopLevel {

if (depsRev == actualRev) return;
log.warning("${log.yellow('Warning:')} the revision of pub in DEPS is "
'${log.bold(depsRev)},\n'
'${log.bold(depsRev.toString())},\n'
'but ${log.bold(actualRev)} is checked out in '
'${p.relative(pubRoot)}.\n\n');
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class PackageIntegrityException extends PubHttpException {
/// Returns whether [error] is a user-facing error object.
///
/// This includes both [ApplicationException] and any dart:io errors.
bool isUserFacingException(error) {
bool isUserFacingException(Object error) {
return error is ApplicationException ||
error is AnalyzerErrorGroup ||
error is IsolateSpawnException ||
Expand Down Expand Up @@ -148,7 +148,7 @@ class SourceSpanApplicationException extends SourceSpanFormatException
}) : super(message, span);

@override
String toString({color}) {
String toString({Object? color}) {
return [
if (explanation != null) explanation,
span == null
Expand Down
2 changes: 1 addition & 1 deletion lib/src/flutter_releases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ class FlutterRelease {
required this.channel,
});
@override
toString() =>
String toString() =>
'FlutterRelease(flutter=$flutterVersion, dart=$dartVersion, channel=$channel)';
}
10 changes: 5 additions & 5 deletions lib/src/global_packages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class GlobalPackages {
bool silent = false,
}) async {
final name = dep.name;
LockFile? originalLockFile = _describeActive(name, cache);
final originalLockFile = _describeActive(name, cache);

// Create a dummy package with just [dep] so we can do resolution on it.
var root = Package.inMemory(
Expand Down Expand Up @@ -251,7 +251,7 @@ class GlobalPackages {
final sameVersions =
originalLockFile != null && originalLockFile.samePackageIds(lockFile);

final PackageId id = lockFile.packages[name]!;
final id = lockFile.packages[name]!;
if (sameVersions) {
log.message('''
The package $name is already activated at newest available version.
Expand Down Expand Up @@ -331,7 +331,7 @@ To recompile executables, first run `$topLevelProgram pub global deactivate $nam
'"${description.path}".');
} else {
log.message('Package ${log.bold(name)} is currently active at version '
'${log.bold(id.version)}.');
'${log.bold(id.version.toString())}.');
}
return lockFile;
}
Expand Down Expand Up @@ -724,10 +724,10 @@ try:
for (var command in ordered(collided.keys)) {
if (overwriteBinStubs) {
log.warning('Replaced ${log.bold(command)} previously installed from '
'${log.bold(collided[command])}.');
'${log.bold(collided[command].toString())}.');
} else {
log.warning('Executable ${log.bold(command)} was already installed '
'from ${log.bold(collided[command])}.');
'from ${log.bold(collided[command].toString())}.');
}
}

Expand Down
10 changes: 4 additions & 6 deletions lib/src/log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class _Entry {
///
/// If [error] is passed, it's appended to [message]. If [trace] is passed, it's
/// printed at log level fine.
void error(String message, [error, StackTrace? trace]) {
void error(String message, [Object? error, StackTrace? trace]) {
if (error != null) {
message = message.isEmpty ? '$error' : '$message: $error';
if (error is Error && trace == null) trace = error.stackTrace;
Expand Down Expand Up @@ -490,15 +490,13 @@ void unmuteProgress() {
/// that supports that.
///
/// Use this to highlight the most important piece of a long chunk of text.
String bold(text) => '$_bold$text$_none';
String bold(String text) => '$_bold$text$_none';

/// Wraps [text] in the ANSI escape codes to make it gray when on a platform
/// that supports that.
///
/// Use this for text that's less important than the text around it.
String gray(text) {
return '$_gray$text$_none';
}
String gray(String text) => '$_gray$text$_none';

/// Wraps [text] in the ANSI escape codes to color it cyan when on a platform
/// that supports that.
Expand Down Expand Up @@ -626,7 +624,7 @@ class _JsonLogger {
}

/// Encodes [message] to JSON and prints it if JSON output is enabled.
void message(message) {
void message(Map<String, String> message) {
if (!enabled) return;

stdout.writeln(jsonEncode(message));
Expand Down
6 changes: 3 additions & 3 deletions lib/src/package_name.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PackageRef {
PackageRange(this, constraint);

@override
bool operator ==(other) =>
bool operator ==(Object other) =>
other is PackageRef &&
name == other.name &&
description == other.description;
Expand Down Expand Up @@ -95,7 +95,7 @@ class PackageId {
int get hashCode => Object.hash(name, version, description);

@override
bool operator ==(other) =>
bool operator ==(Object other) =>
other is PackageId &&
name == other.name &&
version == other.version &&
Expand Down Expand Up @@ -208,7 +208,7 @@ class PackageRange {
int get hashCode => Object.hash(_ref, constraint);

@override
bool operator ==(other) =>
bool operator ==(Object other) =>
other is PackageRange &&
_ref == other._ref &&
other.constraint == constraint;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/pub_embeddable_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PubEmbeddableCommand extends PubCommand implements PubTopLevel {
String get name => 'pub';

@override
get suggestionAliases => const ['packages', 'pkg'];
List<String> get suggestionAliases => const ['packages', 'pkg'];

@override
String get description => 'Work with packages.';
Expand Down
6 changes: 3 additions & 3 deletions lib/src/pubspec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class Pubspec extends PubspecBase {
pubspecPath,
);
}
String? overridesFileContents =
final overridesFileContents =
allowOverridesFile && fileExists(overridesPath)
? readTextFile(overridesPath)
: null;
Expand Down Expand Up @@ -613,7 +613,7 @@ class SdkConstraint {
VersionConstraint originalConstraint, {
required VersionConstraint? defaultUpperBoundConstraint,
}) {
VersionConstraint constraint = originalConstraint;
var constraint = originalConstraint;
if (defaultUpperBoundConstraint != null &&
constraint is VersionRange &&
constraint.max == null &&
Expand Down Expand Up @@ -676,7 +676,7 @@ class SdkConstraint {
}

@override
operator ==(other) =>
bool operator ==(Object other) =>
other is SdkConstraint &&
other.effectiveConstraint == effectiveConstraint &&
other.originalConstraint == originalConstraint;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/pubspec_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ VersionConstraint stripUpperBound(VersionConstraint constraint) {
///
/// The syntax used for hosted will depend on the language version of
/// [relativeEntrypoint]
Object? pubspecDescription(
Object pubspecDescription(
PackageRange range,
SystemCache cache,
Entrypoint relativeEntrypoint,
Expand Down
13 changes: 9 additions & 4 deletions lib/src/source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'dart:async';

import 'package:meta/meta.dart';
import 'package:pub_semver/pub_semver.dart';

import 'exceptions.dart';
Expand Down Expand Up @@ -78,7 +79,7 @@ abstract class Source {
/// Throws a [FormatException] if the description is not valid.
PackageRef parseRef(
String name,
description, {
Object? description, {
String? containingDir,
required LanguageVersion languageVersion,
});
Expand All @@ -96,7 +97,7 @@ abstract class Source {
PackageId parseId(
String name,
Version version,
description, {
Object? description, {
String? containingDir,
});

Expand Down Expand Up @@ -183,10 +184,12 @@ abstract class Description {
String format();

@override
bool operator ==(other) =>
@mustBeOverridden
bool operator ==(Object other) =>
throw UnimplementedError('Subclasses must override');

@override
@mustBeOverridden
int get hashCode => throw UnimplementedError('Subclasses must override');
}

Expand Down Expand Up @@ -214,10 +217,12 @@ abstract class ResolvedDescription {
String format() => description.format();

@override
bool operator ==(other) =>
@mustBeOverridden
bool operator ==(Object other) =>
throw UnimplementedError('Subclasses must override');

@override
@mustBeOverridden
int get hashCode => throw UnimplementedError('Subclasses must override');
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/source/git.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class GitSource extends CachedSource {
PackageId parseId(
String name,
Version version,
description, {
Object? description, {
String? containingDir,
}) {
if (description is! Map) {
Expand Down Expand Up @@ -357,7 +357,7 @@ class GitSource extends CachedSource {
SystemCache cache,
) async {
return await _pool.withResource(() async {
bool didUpdate = false;
var didUpdate = false;
final ref = id.toRef();
final description = ref.description;
if (description is! GitDescription) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/source/hosted.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class HostedSource extends CachedSource {
@override
PackageRef parseRef(
String name,
description, {
Object? description, {
String? containingDir,
required LanguageVersion languageVersion,
}) {
Expand All @@ -239,7 +239,7 @@ class HostedSource extends CachedSource {
PackageId parseId(
String name,
Version version,
description, {
Object? description, {
String? containingDir,
}) {
// Old pub versions only wrote `description: <pkg>` into the lock file.
Expand Down
4 changes: 2 additions & 2 deletions lib/src/source/path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class PathSource extends Source {
@override
PackageRef parseRef(
String name,
description, {
Object? description, {
String? containingDir,
LanguageVersion? languageVersion,
}) {
Expand Down Expand Up @@ -90,7 +90,7 @@ class PathSource extends Source {
PackageId parseId(
String name,
Version version,
description, {
Object? description, {
String? containingDir,
}) {
if (description is! Map) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/source/root.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class RootSource extends Source {
PackageId parseId(
String name,
Version version,
description, {
Object? description, {
String? containingDir,
}) {
throw UnsupportedError('Trying to parse a root package description.');
Expand All @@ -67,7 +67,7 @@ class RootSource extends Source {
@override
PackageRef parseRef(
String name,
description, {
Object? description, {
String? containingDir,
required LanguageVersion languageVersion,
}) {
Expand Down
Loading

0 comments on commit 78a39b0

Please sign in to comment.