Skip to content

Commit ceaa86f

Browse files
authored
Enforce and fix lints from package:pedantic (#2291)
- always_declare_return_types - annotate_overrides - curly_braces_in_flow_control_structures - prefer_for_elements_to_map_fromiterable - prefer_if_null_operators - prefer_single_quotes - prefer_spread_collections - unawaited_futures - use_function_type_syntax_for_parameters Rename a method starting with `get` to use a more accurately descriptive verb. Tighten the types on some methods highlighted by the `always_declare_return_types` lint by making them generic instead of returning `dynamic`.
1 parent 6ce1606 commit ceaa86f

373 files changed

Lines changed: 4522 additions & 4200 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

analysis_options.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include: package:pedantic/analysis_options.yaml
2+
13
analyzer:
24
errors:
35
unused_import: error

lib/src/ascii_tree.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ String fromFiles(List<String> files, {String baseDir, bool showAllChildren}) {
100100
/// will have their contents truncated. Defaults to `false`.
101101
String fromMap(Map<String, Map> map, {bool showAllChildren}) {
102102
var buffer = StringBuffer();
103-
_draw(buffer, "", null, map, showAllChildren: showAllChildren);
103+
_draw(buffer, '', null, map, showAllChildren: showAllChildren);
104104
return buffer.toString();
105105
}
106106

@@ -112,7 +112,7 @@ void _drawLine(
112112
if (isLastChild) {
113113
buffer.write(log.gray("'-- "));
114114
} else {
115-
buffer.write(log.gray("|-- "));
115+
buffer.write(log.gray('|-- '));
116116
}
117117
}
118118

@@ -121,9 +121,9 @@ void _drawLine(
121121
}
122122

123123
String _getPrefix(bool isRoot, bool isLast) {
124-
if (isRoot) return "";
125-
if (isLast) return " ";
126-
return log.gray("| ");
124+
if (isRoot) return '';
125+
if (isLast) return ' ';
126+
return log.gray('| ');
127127
}
128128

129129
void _draw(
@@ -137,7 +137,7 @@ void _draw(
137137
// Recurse to the children.
138138
var childNames = ordered(children.keys);
139139

140-
drawChild(bool isLastChild, String child) {
140+
void drawChild(bool isLastChild, String child) {
141141
var childPrefix = _getPrefix(name == null, isLast);
142142
_draw(buffer, '$prefix$childPrefix', child,
143143
children[child] as Map<String, Map>,

lib/src/command.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ abstract class PubCommand extends Command {
4141

4242
// Lazily initialize the parser because the superclass constructor requires
4343
// it but we want to initialize it based on [allowTrailingOptions].
44+
@override
4445
ArgParser get argParser =>
4546
_argParser ??= ArgParser(allowTrailingOptions: allowTrailingOptions);
4647

@@ -52,11 +53,13 @@ abstract class PubCommand extends Command {
5253
/// it has no effect. This only needs to be set in leaf commands.
5354
bool get isOffline => false;
5455

56+
@override
5557
String get usageFooter {
5658
if (docUrl == null) return null;
57-
return "See $docUrl for detailed documentation.";
59+
return 'See $docUrl for detailed documentation.';
5860
}
5961

62+
@override
6063
void printUsage() {
6164
log.message(usage);
6265
}

lib/src/command/barback.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@ import '../utils.dart';
99
/// Shared base class for [BuildCommand] and [ServeCommand].
1010
abstract class BarbackCommand extends PubCommand {
1111
BarbackCommand() {
12-
argParser.addOption("mode", hide: true);
13-
argParser.addFlag("all", hide: true);
14-
argParser.addOption("web-compiler", hide: true);
12+
argParser.addOption('mode', hide: true);
13+
argParser.addFlag('all', hide: true);
14+
argParser.addOption('web-compiler', hide: true);
1515
}
1616

17-
run() {
17+
@override
18+
void run() {
1819
// Switch to JSON output if specified. We need to do this before parsing
1920
// the source directories so an error will be correctly reported in JSON
2021
// format.
2122
log.json.enabled =
22-
argResults.options.contains("format") && argResults["format"] == "json";
23+
argResults.options.contains('format') && argResults['format'] == 'json';
2324

24-
fail(log.red("Dart 2 has a new build system. Learn how to migrate "
25+
fail(log.red('Dart 2 has a new build system. Learn how to migrate '
2526
"from ${log.bold('pub build')} and\n"
2627
"${log.bold('pub serve')}: https://webdev.dartlang.org/dart-2\n"));
2728
}

lib/src/command/build.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import 'barback.dart';
66

77
/// Handles the `build` pub command.
88
class BuildCommand extends BarbackCommand {
9-
String get name => "build";
10-
String get description => "Deprecated command";
9+
@override
10+
String get name => 'build';
11+
@override
12+
String get description => 'Deprecated command';
13+
@override
1114
bool get hidden => true;
1215

1316
BuildCommand() {
14-
argParser.addOption("define", hide: true);
15-
argParser.addOption("format", hide: true);
16-
argParser.addOption("output", hide: true);
17+
argParser.addOption('define', hide: true);
18+
argParser.addOption('format', hide: true);
19+
argParser.addOption('output', hide: true);
1720
}
1821
}

lib/src/command/cache.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ import 'cache_repair.dart';
99

1010
/// Handles the `cache` pub command.
1111
class CacheCommand extends PubCommand {
12-
String get name => "cache";
13-
String get description => "Work with the system cache.";
14-
String get invocation => "pub cache <subcommand>";
15-
String get docUrl => "https://dart.dev/tools/pub/cmd/pub-cache";
12+
@override
13+
String get name => 'cache';
14+
@override
15+
String get description => 'Work with the system cache.';
16+
@override
17+
String get invocation => 'pub cache <subcommand>';
18+
@override
19+
String get docUrl => 'https://dart.dev/tools/pub/cmd/pub-cache';
1620

1721
CacheCommand() {
1822
addSubcommand(CacheAddCommand());

lib/src/command/cache_add.dart

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,44 @@ import '../utils.dart';
1212

1313
/// Handles the `cache add` pub command.
1414
class CacheAddCommand extends PubCommand {
15-
String get name => "add";
16-
String get description => "Install a package.";
15+
@override
16+
String get name => 'add';
17+
@override
18+
String get description => 'Install a package.';
19+
@override
1720
String get invocation =>
18-
"pub cache add <package> [--version <constraint>] [--all]";
19-
String get docUrl => "https://dart.dev/tools/pub/cmd/pub-cache";
21+
'pub cache add <package> [--version <constraint>] [--all]';
22+
@override
23+
String get docUrl => 'https://dart.dev/tools/pub/cmd/pub-cache';
2024

2125
CacheAddCommand() {
22-
argParser.addFlag("all",
23-
help: "Install all matching versions.", negatable: false);
26+
argParser.addFlag('all',
27+
help: 'Install all matching versions.', negatable: false);
2428

25-
argParser.addOption("version", abbr: "v", help: "Version constraint.");
29+
argParser.addOption('version', abbr: 'v', help: 'Version constraint.');
2630
}
2731

32+
@override
2833
Future run() async {
2934
// Make sure there is a package.
3035
if (argResults.rest.isEmpty) {
31-
usageException("No package to add given.");
36+
usageException('No package to add given.');
3237
}
3338

3439
// Don't allow extra arguments.
3540
if (argResults.rest.length > 1) {
3641
var unexpected = argResults.rest.skip(1).map((arg) => '"$arg"');
37-
var arguments = pluralize("argument", unexpected.length);
38-
usageException("Unexpected $arguments ${toSentence(unexpected)}.");
42+
var arguments = pluralize('argument', unexpected.length);
43+
usageException('Unexpected $arguments ${toSentence(unexpected)}.');
3944
}
4045

4146
var package = argResults.rest.single;
4247

4348
// Parse the version constraint, if there is one.
4449
var constraint = VersionConstraint.any;
45-
if (argResults["version"] != null) {
50+
if (argResults['version'] != null) {
4651
try {
47-
constraint = VersionConstraint.parse(argResults["version"]);
52+
constraint = VersionConstraint.parse(argResults['version']);
4853
} on FormatException catch (error) {
4954
usageException(error.message);
5055
}
@@ -60,22 +65,22 @@ class CacheAddCommand extends PubCommand {
6065

6166
if (ids.isEmpty) {
6267
// TODO(rnystrom): Show most recent unmatching version?
63-
fail("Package $package has no versions that match $constraint.");
68+
fail('Package $package has no versions that match $constraint.');
6469
}
6570

66-
downloadVersion(id) async {
71+
Future<void> downloadVersion(id) async {
6772
if (cache.contains(id)) {
6873
// TODO(rnystrom): Include source and description if not hosted.
6974
// See solve_report.dart for code to harvest.
70-
log.message("Already cached ${id.name} ${id.version}.");
75+
log.message('Already cached ${id.name} ${id.version}.');
7176
return null;
7277
}
7378

7479
// Download it.
7580
await source.downloadToSystemCache(id);
7681
}
7782

78-
if (argResults["all"]) {
83+
if (argResults['all']) {
7984
// Install them in ascending order.
8085
ids.sort((id1, id2) => id1.version.compareTo(id2.version));
8186
await Future.forEach(ids, downloadVersion);

lib/src/command/cache_list.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ import '../source/cached.dart';
1010

1111
/// Handles the `cache list` pub command.
1212
class CacheListCommand extends PubCommand {
13-
String get name => "list";
14-
String get description => "List packages in the system cache.";
15-
String get invocation => "pub cache list";
13+
@override
14+
String get name => 'list';
15+
@override
16+
String get description => 'List packages in the system cache.';
17+
@override
18+
String get invocation => 'pub cache list';
19+
@override
1620
bool get hidden => true;
21+
@override
1722
bool get takesArguments => false;
1823

24+
@override
1925
void run() {
2026
// TODO(keertip): Add flag to list packages from non default sources.
2127
var packagesObj = <String, Map>{};

lib/src/command/cache_repair.dart

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ import '../utils.dart';
1313

1414
/// Handles the `cache repair` pub command.
1515
class CacheRepairCommand extends PubCommand {
16-
String get name => "repair";
17-
String get description => "Reinstall cached packages.";
18-
String get invocation => "pub cache repair";
19-
String get docUrl => "https://dart.dev/tools/pub/cmd/pub-cache";
16+
@override
17+
String get name => 'repair';
18+
@override
19+
String get description => 'Reinstall cached packages.';
20+
@override
21+
String get invocation => 'pub cache repair';
22+
@override
23+
String get docUrl => 'https://dart.dev/tools/pub/cmd/pub-cache';
24+
@override
2025
bool get takesArguments => false;
2126

27+
@override
2228
Future run() async {
2329
var successes = [];
2430
var failures = [];
@@ -33,19 +39,19 @@ class CacheRepairCommand extends PubCommand {
3339
}
3440

3541
if (successes.isNotEmpty) {
36-
var packages = pluralize("package", successes.length);
37-
log.message("Reinstalled ${log.green(successes.length)} $packages.");
42+
var packages = pluralize('package', successes.length);
43+
log.message('Reinstalled ${log.green(successes.length)} $packages.');
3844
}
3945

4046
if (failures.isNotEmpty) {
41-
var packages = pluralize("package", failures.length);
47+
var packages = pluralize('package', failures.length);
4248
var buffer = StringBuffer(
43-
"Failed to reinstall ${log.red(failures.length)} $packages:\n");
49+
'Failed to reinstall ${log.red(failures.length)} $packages:\n');
4450

4551
for (var id in failures) {
46-
buffer.write("- ${log.bold(id.name)} ${id.version}");
52+
buffer.write('- ${log.bold(id.name)} ${id.version}');
4753
if (id.source != cache.sources.defaultSource) {
48-
buffer.write(" from ${id.source}");
54+
buffer.write(' from ${id.source}');
4955
}
5056
buffer.writeln();
5157
}
@@ -55,19 +61,19 @@ class CacheRepairCommand extends PubCommand {
5561

5662
var results = await globals.repairActivatedPackages();
5763
if (results.first.isNotEmpty) {
58-
var packages = pluralize("package", results.first.length);
59-
log.message("Reactivated ${log.green(results.first.length)} $packages.");
64+
var packages = pluralize('package', results.first.length);
65+
log.message('Reactivated ${log.green(results.first.length)} $packages.');
6066
}
6167

6268
if (results.last.isNotEmpty) {
63-
var packages = pluralize("package", results.last.length);
69+
var packages = pluralize('package', results.last.length);
6470
log.message(
65-
"Failed to reactivate ${log.red(results.last.length)} $packages:\n" +
66-
results.last.map((name) => "- ${log.bold(name)}").join("\n"));
71+
'Failed to reactivate ${log.red(results.last.length)} $packages:\n' +
72+
results.last.map((name) => '- ${log.bold(name)}').join('\n'));
6773
}
6874

6975
if (successes.isEmpty && failures.isEmpty) {
70-
log.message("No packages in cache, so nothing to repair.");
76+
log.message('No packages in cache, so nothing to repair.');
7177
}
7278

7379
if (failures.isNotEmpty || results.last.isNotEmpty) {

0 commit comments

Comments
 (0)