Skip to content

Commit 743328a

Browse files
authored
Add additional lints (#282)
Split lints into 'error's and 'style' and sort within each section. Fix a few existing violations.
1 parent ee20156 commit 743328a

File tree

8 files changed

+36
-19
lines changed

8 files changed

+36
-19
lines changed

analysis_options.yaml

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,51 @@ analyzer:
66
unused_import: error
77
unused_local_variable: error
88
dead_code: error
9+
override_on_non_overriding_method: error
910
linter:
1011
rules:
11-
- annotate_overrides
12+
# Errors
1213
- avoid_empty_else
13-
- avoid_init_to_null
14-
- avoid_return_types_on_setters
1514
- await_only_futures
16-
- camel_case_types
1715
- comment_references
1816
- control_flow_in_finally
17+
- empty_statements
18+
- hash_and_equals
19+
- iterable_contains_unrelated_type
20+
- no_duplicate_case_values
21+
- test_types_in_equals
22+
- throw_in_finally
23+
- unawaited_futures
24+
- unnecessary_statements
25+
- unrelated_type_equality_checks
26+
- valid_regexps
27+
28+
# Style
29+
- annotate_overrides
30+
- avoid_function_literals_in_foreach_calls
31+
- avoid_init_to_null
32+
- avoid_return_types_on_setters
33+
- avoid_returning_null
34+
- avoid_unused_constructor_parameters
35+
- camel_case_types
1936
- directives_ordering
2037
- empty_catches
2138
- empty_constructor_bodies
22-
- empty_statements
23-
- hash_and_equals
2439
- implementation_imports
2540
- library_names
2641
- library_prefixes
2742
- non_constant_identifier_names
2843
- only_throw_errors
44+
- prefer_conditional_assignment
2945
- prefer_final_fields
46+
- prefer_is_empty
3047
- prefer_is_not_empty
3148
- prefer_single_quotes
49+
- prefer_typing_uninitialized_variables
50+
- recursive_getters
3251
- slash_for_doc_comments
33-
- test_types_in_equals
34-
- test_types_in_equals
35-
- throw_in_finally
3652
- type_init_formals
37-
- unrelated_type_equality_checks
38-
- valid_regexps
53+
- unnecessary_brace_in_string_interps
54+
- unnecessary_getter_setters
55+
- unnecessary_lambda
56+
- unnecessary_null_aware_assignments

lib/src/builder.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class _Builder extends Builder {
146146
stack);
147147
}
148148

149+
// ignore: unawaited_futures
149150
buildStep.writeAsString(outputId, genPartContent);
150151
}
151152
}

lib/src/constants/revive.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import '../utils.dart';
1313
///
1414
/// Optionally specify the [library] type that contains the reference.
1515
///
16-
/// Returns [null] if not revivable.
16+
/// Returns `null` if not revivable.
1717
Revivable reviveInstance(DartObject object, [LibraryElement library]) {
1818
library ??= object.type.element.library;
1919
var url = Uri.parse(urlOfElement(object.type.element));

lib/src/constants/utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void assertHasField(ClassElement root, String name) {
2020
element = element.supertype?.element;
2121
}
2222
final allFields = root.fields.toSet();
23-
root.allSupertypes.forEach((t) => allFields.addAll(t.element.fields));
23+
allFields.addAll(root.allSupertypes.expand((t) => t.element.fields));
2424
throw new FormatException(
2525
'Class ${root.name} does not have field "$name".',
2626
'Fields: \n - ${allFields.map((e) => e.name).join('\n - ')}',

lib/src/generated_output.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'generator.dart';
99
class GeneratedOutput {
1010
final String output;
1111
final Generator generator;
12-
final error;
12+
final dynamic error;
1313
final StackTrace stackTrace;
1414

1515
bool get isError => error != null;

lib/src/type_checker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class _UriTypeChecker extends TypeChecker {
253253
bool isExactly(Element element) => hasSameUrl(urlOfElement(element));
254254

255255
@override
256-
String toString() => '${uri}';
256+
String toString() => '$uri';
257257
}
258258

259259
class _AnyChecker extends TypeChecker {

lib/src/utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Uri packageToAssetUrl(Uri url) => url.scheme == 'package'
136136
/// are not describable using `package:...`, such as files in the `bin`, `tool`,
137137
/// `web`, or even root directory of a package - `asset:some_lib/web/main.dart`.
138138
Uri assetToPackageUrl(Uri url) => url.scheme == 'asset' &&
139-
url.pathSegments.length >= 1 &&
139+
url.pathSegments.isNotEmpty &&
140140
url.pathSegments[1] == 'lib'
141141
? url.replace(
142142
scheme: 'package',

test/src/io.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ Future<List<String>> getDartFiles(String directoryPath,
2929
/// directories defined in the list.
3030
Stream<String> getFiles(String directoryPath,
3131
{List<String> searchList, bool followLinks: false}) async* {
32-
if (searchList == null) {
33-
searchList = <String>[];
34-
}
32+
searchList ??= [];
3533

3634
var map = await _expandSearchList(directoryPath, searchList);
3735
var searchDirs = <String>[];

0 commit comments

Comments
 (0)