Skip to content

Commit b177abc

Browse files
authored
switch the repo's analysis options to using package:lints (flutter#5534)
switch the repo analysis options to using package:lints
1 parent 05c52d8 commit b177abc

File tree

15 files changed

+131
-95
lines changed

15 files changed

+131
-95
lines changed

analysis_options.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include: package:lints/recommended.yaml
2+
13
analyzer:
24
strong-mode:
35
implicit-casts: false
@@ -7,6 +9,5 @@ analyzer:
79

810
linter:
911
rules:
10-
- prefer_single_quotes
11-
- type_annotate_public_apis
12+
- directives_ordering
1213
- unawaited_futures

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ dependencies:
1111
dev_dependencies:
1212
grinder: ^0.9.0
1313
http: ^0.13.0
14+
lints: ^1.0.0
1415
meta: any

testData/sample_tests/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ environment:
66
sdk: '>=2.0.0-dev <3.0.0'
77

88
dev_dependencies:
9+
lints: ^1.0.0
910
meta: any
1011
test: ^1.16.0

tool/grind.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void main(List<String> args) => grind(args);
1313
void checkUrls() async {
1414
log('checking URLs in FlutterBundle.properties...');
1515
var lines =
16-
await new File('src/io/flutter/FlutterBundle.properties').readAsLines();
16+
await File('src/io/flutter/FlutterBundle.properties').readAsLines();
1717
for (var line in lines) {
1818
var split = line.split('=');
1919
if (split.length == 2) {
@@ -40,7 +40,7 @@ void outlineIcons() async {
4040

4141
for (File file in previewIconsDir
4242
.listSync()
43-
.where((entity) => entity is File)
43+
.whereType<File>()
4444
.cast<File>()
4545
.where((file) => file.path.endsWith('.svg'))) {
4646
log('processing ${file.path}...');
@@ -58,7 +58,7 @@ void _createPng(
5858
File sourceSvg,
5959
String targetName, {
6060
required int? size,
61-
bool forLight: false,
61+
bool forLight = false,
6262
}) {
6363
File targetFile = joinFile(sourceSvg.parent, [targetName]);
6464

tool/plugin/analysis_options.yaml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
1-
# Lint rules and documentation, see http://dart-lang.github.io/linter/lints
1+
include: package:lints/recommended.yaml
2+
23
linter:
34
rules:
4-
- await_only_futures
5-
- cancel_subscriptions
65
- directives_ordering
7-
- hash_and_equals
8-
- iterable_contains_unrelated_type
9-
- list_remove_unrelated_type
10-
- omit_local_variable_types
11-
- prefer_final_fields
12-
- test_types_in_equals
13-
- type_annotate_public_apis
14-
- type_init_formals
156
- unawaited_futures
16-
- unrelated_type_equality_checks
17-
- valid_regexps

tool/plugin/lib/artifact.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ class Artifact {
1616
final bool bareArchive;
1717
String output;
1818

19-
Artifact(this.file, {this.bareArchive: false, this.output}) {
20-
if (output == null) {
21-
output = file.substring(0, file.lastIndexOf('-'));
22-
}
19+
Artifact(this.file, {this.bareArchive = false, this.output}) {
20+
output ??= file.substring(0, file.lastIndexOf('-'));
2321
}
2422

2523
bool get isZip => file.endsWith('.zip');

tool/plugin/lib/build_spec.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ class BuildSpec {
3636
Artifact product;
3737
Artifact dartPlugin;
3838

39-
BuildSpec.fromJson(Map json, String releaseNum)
40-
: release = releaseNum,
41-
name = json['name'],
39+
BuildSpec.fromJson(Map json, this.release)
40+
: name = json['name'],
4241
channel = json['channel'],
4342
version = json['version'],
44-
ijVersion = json['ijVersion'] ?? null,
43+
ijVersion = json['ijVersion'],
4544
ideaProduct = json['ideaProduct'],
4645
ideaVersion = json['ideaVersion'],
4746
dartPluginVersion = json['dartPluginVersion'],
@@ -103,7 +102,8 @@ class BuildSpec {
103102
// We only put Linux versions in cloud storage.
104103
artifacts.add(Artifact('$ideaProduct-$ideaVersion-linux.tar.gz',
105104
output: ideaProduct));
106-
artifacts.add(Artifact('$ideaProduct-ide-$ideaVersion-linux.tar.gz',
105+
artifacts.add(Artifact(
106+
'$ideaProduct-ide-$ideaVersion-linux.tar.gz',
107107
output: ideaProduct));
108108
}
109109
}
@@ -137,6 +137,7 @@ class BuildSpec {
137137
.replaceAll('</p>', '');
138138
}
139139

140+
@override
140141
String toString() {
141142
return 'BuildSpec($ideaProduct $ideaVersion $dartPluginVersion $sinceBuild '
142143
'$untilBuild version: "$release")';
@@ -175,13 +176,15 @@ class SyntheticBuildSpec extends BuildSpec {
175176
try {
176177
// 'isUnitTestTarget' should always be in the spec for the latest IntelliJ (not AS).
177178
alternate = specs.firstWhere((s) => s.isUnitTestTarget);
178-
} catch (StateError) {
179+
} on StateError catch (_) {
179180
log('No build spec defines "isUnitTestTarget"');
180181
exit(1);
181182
}
182183
}
183184

185+
@override
184186
String get untilBuild => alternate.untilBuild;
185187

188+
@override
186189
bool get isSynthetic => true;
187190
}

tool/plugin/lib/edit.dart

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import 'dart:async';
1010
import 'dart:io';
1111

12+
import 'package:meta/meta.dart';
13+
1214
import 'build_spec.dart';
1315
import 'util.dart';
1416

@@ -20,7 +22,9 @@ void checkAndClearAppliedEditCommands() {
2022
commands.addAll(editCommands);
2123
commands.removeAll(appliedEditCommands);
2224
separator("UNUSED EditCommand");
23-
commands.forEach((cmd) => log(cmd.toString()));
25+
for (var cmd in commands) {
26+
log(cmd.toString());
27+
}
2428
}
2529
appliedEditCommands.clear();
2630
}
@@ -125,10 +129,9 @@ class EditAndroidModuleLibraryManager extends EditCommand {
125129
// Starting with 3.6 we need to call a simplified init().
126130
// This is where the $PROJECT_FILE$ macro is defined, #registerComponents.
127131
if (spec.version.startsWith('4.2')) {
128-
var processedFile, source;
129-
processedFile = File(
132+
var processedFile = File(
130133
'flutter-studio/src/io/flutter/android/AndroidModuleLibraryManager.java');
131-
source = processedFile.readAsStringSync();
134+
var source = processedFile.readAsStringSync();
132135
var original = source;
133136
source = source.replaceAll("ProjectExImpl", "ProjectImpl");
134137
source = source.replaceAll(
@@ -170,7 +173,7 @@ Future<int> applyEdits(BuildSpec spec, Function compileFn) async {
170173
if (entity is File) {
171174
var stubFile = File('${file}_stub');
172175
if (stubFile.existsSync()) {
173-
await stubFile.copy('$file');
176+
await stubFile.copy(file);
174177
log('copied ${file}_stub');
175178
}
176179
}
@@ -179,13 +182,13 @@ Future<int> applyEdits(BuildSpec spec, Function compileFn) async {
179182

180183
var edited = <EditCommand, String>{};
181184
try {
182-
editCommands.forEach((edit) {
185+
for (var edit in editCommands) {
183186
var source = edit.convert(spec);
184187
if (source != null) {
185188
edited[edit] = source;
186189
appliedEditCommands.add(edit);
187190
}
188-
});
191+
}
189192

190193
return await compileFn.call();
191194
} finally {
@@ -231,9 +234,9 @@ class Subst extends EditCommand {
231234

232235
Subst(
233236
{this.versions,
234-
this.initial,
235-
this.replacement,
236-
this.path,
237+
@required this.initial,
238+
@required this.replacement,
239+
@required this.path,
237240
String version})
238241
: assert(initial != null),
239242
assert(replacement != null),
@@ -260,6 +263,7 @@ class Subst extends EditCommand {
260263
}
261264
}
262265

266+
@override
263267
String toString() => "Subst(path: $path, versions: $versions)";
264268

265269
bool versionMatches(BuildSpec spec) {
@@ -279,7 +283,7 @@ class MultiSubst extends EditCommand {
279283
this.versions,
280284
this.initials,
281285
this.replacements,
282-
this.path,
286+
@required this.path,
283287
}) {
284288
assert(initials.length == replacements.length);
285289
assert(path != null);
@@ -303,6 +307,7 @@ class MultiSubst extends EditCommand {
303307
}
304308
}
305309

310+
@override
306311
String toString() => "Subst(path: $path, versions: $versions)";
307312

308313
bool versionMatches(BuildSpec spec) {

tool/plugin/lib/globals.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// @dart = 2.10
55

66
// Map plugin ID to JetBrains registry ID.
7-
const Map<String, String> pluginRegistryIds = const {
7+
const Map<String, String> pluginRegistryIds = {
88
'io.flutter': '9212',
99
'io.flutter.as': '10139', // Currently unused.
1010
};

tool/plugin/lib/lint.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ import 'runner.dart';
1212
import 'util.dart';
1313

1414
class LintCommand extends Command {
15+
@override
1516
final BuildCommandRunner runner;
1617

1718
LintCommand(this.runner);
1819

20+
@override
1921
String get name => 'lint';
2022

23+
@override
2124
String get description =>
2225
'Perform simple validations on the flutter-intellij repo code.';
2326

27+
@override
2428
Future<int> run() async {
2529
// Check for unintentionally imported annotations.
2630
if (checkForBadImports()) {
@@ -70,7 +74,9 @@ class LintCommand extends Command {
7074
for (var import in keys) {
7175
print('$import:');
7276
var places = usages[import];
73-
places.forEach((String place) => print(' $place'));
77+
for (var place in places) {
78+
print(' $place');
79+
}
7480
print('');
7581
}
7682
}

0 commit comments

Comments
 (0)