Skip to content

Commit de4deb4

Browse files
authored
misc: enable and fix a number of lints (#235)
1 parent 2c4d41d commit de4deb4

12 files changed

+41
-33
lines changed

analysis_options.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@ analyzer:
22
strong-mode:
33
implicit-casts: false
44
errors:
5+
dead_code: error
6+
override_on_non_overriding_method: error
57
unused_element: error
68
unused_import: error
79
unused_local_variable: error
8-
dead_code: error
910
linter:
1011
rules:
12+
- always_declare_return_types
1113
- annotate_overrides
1214
- avoid_empty_else
1315
- avoid_function_literals_in_foreach_calls
1416
- avoid_init_to_null
1517
- avoid_null_checks_in_equality_operators
18+
- avoid_renaming_method_parameters
1619
- avoid_return_types_on_setters
1720
- avoid_returning_null
1821
- avoid_types_as_parameter_names
@@ -35,6 +38,7 @@ linter:
3538
- library_names
3639
- library_prefixes
3740
- list_remove_unrelated_type
41+
- literal_only_boolean_expressions
3842
- no_adjacent_strings_in_list
3943
- no_duplicate_case_values
4044
- non_constant_identifier_names
@@ -49,6 +53,7 @@ linter:
4953
- prefer_conditional_assignment
5054
- prefer_const_constructors
5155
- prefer_contains
56+
- prefer_equal_for_default_values
5257
- prefer_final_fields
5358
- prefer_initializing_formals
5459
- prefer_interpolation_to_compose_strings
@@ -70,4 +75,5 @@ linter:
7075
- unnecessary_statements
7176
- unnecessary_this
7277
- unrelated_type_equality_checks
78+
- use_rethrow_when_possible
7379
- valid_regexps

json_annotation/lib/src/json_literal.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ class JsonLiteral {
2424
final bool asConst;
2525

2626
/// Creates a new [JsonLiteral] instance.
27-
const JsonLiteral(this.path, {bool asConst: false})
27+
const JsonLiteral(this.path, {bool asConst = false})
2828
: this.asConst = asConst ?? false;
2929
}

json_annotation/lib/src/json_serializable.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ class JsonSerializable {
7474

7575
/// Creates a new [JsonSerializable] instance.
7676
const JsonSerializable({
77-
bool disallowUnrecognizedKeys: false,
78-
bool createFactory: true,
79-
bool createToJson: true,
80-
bool includeIfNull: true,
81-
bool nullable: true,
77+
bool disallowUnrecognizedKeys = false,
78+
bool createFactory = true,
79+
bool createToJson = true,
80+
bool includeIfNull = true,
81+
bool nullable = true,
8282
}) : this.disallowUnrecognizedKeys = disallowUnrecognizedKeys ?? false,
8383
this.createFactory = createFactory ?? true,
8484
this.createToJson = createToJson ?? true,

json_serializable/lib/src/json_part_builder.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import 'json_serializable_generator.dart';
2323
Builder jsonPartBuilder({
2424
String header,
2525
String formatOutput(String code),
26-
bool useWrappers: false,
27-
bool anyMap: false,
28-
bool checked: false,
29-
bool explicitToJson: false,
30-
bool generateToJsonFunction: false,
26+
bool useWrappers = false,
27+
bool anyMap = false,
28+
bool checked = false,
29+
bool explicitToJson = false,
30+
bool generateToJsonFunction = false,
3131
}) {
3232
return new PartBuilder([
3333
new JsonSerializableGenerator(

json_serializable/lib/src/json_serializable_generator.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'dart:async';
66

77
import 'package:analyzer/dart/element/element.dart';
8+
import 'package:build/build.dart';
89

910
import 'package:json_annotation/json_annotation.dart';
1011
import 'package:source_gen/source_gen.dart';
@@ -121,11 +122,11 @@ class JsonSerializableGenerator
121122
/// [JsonHelper], [DateTimeHelper], and [UriHelper].
122123
const JsonSerializableGenerator({
123124
List<TypeHelper> typeHelpers,
124-
bool useWrappers: false,
125-
bool anyMap: false,
126-
bool checked: false,
127-
bool explicitToJson: false,
128-
bool generateToJsonFunction: false,
125+
bool useWrappers = false,
126+
bool anyMap = false,
127+
bool checked = false,
128+
bool explicitToJson = false,
129+
bool generateToJsonFunction = false,
129130
}) : this.useWrappers = useWrappers ?? false,
130131
this.anyMap = anyMap ?? false,
131132
this.checked = checked ?? false,
@@ -140,10 +141,10 @@ class JsonSerializableGenerator
140141
/// [JsonHelper], [DateTimeHelper], and [UriHelper].
141142
factory JsonSerializableGenerator.withDefaultHelpers(
142143
Iterable<TypeHelper> typeHelpers, {
143-
bool useWrappers: false,
144-
bool anyMap: false,
145-
bool checked: false,
146-
bool generateToJsonFunction: false,
144+
bool useWrappers = false,
145+
bool anyMap = false,
146+
bool checked = false,
147+
bool generateToJsonFunction = false,
147148
}) =>
148149
new JsonSerializableGenerator(
149150
useWrappers: useWrappers,
@@ -155,6 +156,6 @@ class JsonSerializableGenerator
155156

156157
@override
157158
Future<String> generateForAnnotatedElement(
158-
Element element, ConstantReader annotation, _) =>
159+
Element element, ConstantReader annotation, BuildStep buildStep) =>
159160
generate(this, element, annotation);
160161
}

json_serializable/lib/src/type_helpers/value_helper.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class ValueHelper extends TypeHelper {
1212
const ValueHelper();
1313

1414
@override
15-
String serialize(DartType targetType, String expression, _) {
15+
String serialize(
16+
DartType targetType, String expression, SerializeContext context) {
1617
if (targetType.isDynamic ||
1718
targetType.isObject ||
1819
simpleJsonTypeChecker.isAssignableFromType(targetType)) {

json_serializable/test/integration/integration_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'json_test_example.dart';
1010

1111
void main() {
1212
group('Person', () {
13-
roundTripPerson(Person p) {
13+
void roundTripPerson(Person p) {
1414
roundTripObject(p, (json) => new Person.fromJson(json));
1515
}
1616

@@ -49,7 +49,7 @@ void main() {
4949
});
5050

5151
group('Order', () {
52-
roundTripOrder(Order p) {
52+
void roundTripOrder(Order p) {
5353
roundTripObject(p, (json) => new Order.fromJson(json));
5454
}
5555

@@ -116,7 +116,7 @@ void main() {
116116
});
117117

118118
group('Item', () {
119-
roundTripItem(Item p) {
119+
void roundTripItem(Item p) {
120120
roundTripObject(p, (json) => new Item.fromJson(json));
121121
}
122122

@@ -141,7 +141,7 @@ void main() {
141141
});
142142

143143
group('Numbers', () {
144-
roundTripNumber(Numbers p) {
144+
void roundTripNumber(Numbers p) {
145145
roundTripObject(p, (json) => new Numbers.fromJson(json));
146146
}
147147

json_serializable/test/kitchen_sink/kitchen_sink_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ typedef KitchenSink KitchenSinkCtor(
7979
Iterable<DateTime> dateTimeIterable});
8080

8181
void _nonNullableTests(KitchenSinkCtor ctor, KitchenSink fromJson(Map json),
82-
{bool isChecked: false}) {
82+
{bool isChecked = false}) {
8383
test('with null values fails serialization', () {
8484
expect(() => (ctor()..objectDateTimeMap = null).toJson(),
8585
throwsNoSuchMethodError);
@@ -150,7 +150,7 @@ void _nullableTests(KitchenSinkCtor ctor, KitchenSink fromJson(Map json)) {
150150
}
151151

152152
void _sharedTests(KitchenSinkCtor ctor, KitchenSink fromJson(Map json),
153-
{bool isChecked: false}) {
153+
{bool isChecked = false}) {
154154
void roundTripSink(KitchenSink p) {
155155
roundTripObject(p, fromJson);
156156
}

json_serializable/test/literal/json_literal_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import '../test_file_utils.dart';
1313
import '../test_utils.dart';
1414
import 'json_literal.dart';
1515

16-
main() {
16+
void main() {
1717
test('literal round-trip', () {
1818
var dataFilePath = testFilePath('test', 'literal', 'json_literal.json');
1919
var dataFile = new File(dataFilePath);

json_serializable/test/src/json_serializable_test_input.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class FromJsonOptionalParameters {
6060
}
6161

6262
class ChildWithFromJson {
63-
ChildWithFromJson.fromJson(json, {initValue: false});
63+
ChildWithFromJson.fromJson(json, {initValue = false});
6464
}
6565

6666
@JsonSerializable()

json_serializable/test/test_utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class FeatureMatcher<T> extends CustomMatcher {
1616
: super('`$name`', '`$name`', matcher);
1717

1818
@override
19-
featureValueOf(covariant T actual) => _feature(actual);
19+
Object featureValueOf(covariant T actual) => _feature(actual);
2020
}
2121

2222
T roundTripObject<T>(T object, T factory(Map<String, dynamic> json)) {

json_serializable/tool/build.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,6 @@ final List<BuilderApplication> builders = [
118118
hideOutput: true),
119119
];
120120

121-
main(List<String> args) async {
121+
void main(List<String> args) async {
122122
exitCode = await run(args, builders);
123123
}

0 commit comments

Comments
 (0)