Skip to content

Commit 52a727a

Browse files
committed
Enable a number of lints
1 parent e856173 commit 52a727a

10 files changed

+62
-48
lines changed

analysis_options.yaml

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,65 @@ analyzer:
99
override_on_non_overriding_method: error
1010
linter:
1111
rules:
12-
# Errors
13-
- avoid_empty_else
14-
- await_only_futures
15-
- comment_references
16-
- 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
2912
- annotate_overrides
13+
- avoid_empty_else
3014
- avoid_function_literals_in_foreach_calls
3115
- avoid_init_to_null
16+
- avoid_null_checks_in_equality_operators
3217
- avoid_return_types_on_setters
3318
- avoid_returning_null
3419
- avoid_unused_constructor_parameters
20+
- await_only_futures
3521
- camel_case_types
22+
- cancel_subscriptions
23+
#- cascade_invocations
24+
- comment_references
25+
- constant_identifier_names
26+
- control_flow_in_finally
3627
- directives_ordering
3728
- empty_catches
3829
- empty_constructor_bodies
30+
- empty_statements
31+
- hash_and_equals
3932
- implementation_imports
33+
- invariant_booleans
34+
- iterable_contains_unrelated_type
4035
- library_names
4136
- library_prefixes
37+
- list_remove_unrelated_type
38+
- no_adjacent_strings_in_list
39+
- no_duplicate_case_values
4240
- non_constant_identifier_names
41+
- omit_local_variable_types
4342
- only_throw_errors
43+
- overridden_fields
44+
#- package_api_docs
45+
- package_names
46+
- package_prefixed_library_names
47+
- prefer_adjacent_string_concatenation
48+
- prefer_collection_literals
4449
- prefer_conditional_assignment
50+
#- prefer_const_constructors
51+
- prefer_contains
4552
- prefer_final_fields
53+
- prefer_initializing_formals
54+
- prefer_interpolation_to_compose_strings
4655
- prefer_is_empty
4756
- prefer_is_not_empty
4857
- prefer_single_quotes
4958
- prefer_typing_uninitialized_variables
5059
- recursive_getters
5160
- slash_for_doc_comments
61+
- super_goes_last
62+
- test_types_in_equals
63+
- throw_in_finally
5264
- type_init_formals
65+
- unawaited_futures
5366
- unnecessary_brace_in_string_interps
5467
- unnecessary_getters_setters
5568
- unnecessary_lambdas
5669
- unnecessary_null_aware_assignments
70+
- unnecessary_statements
71+
- unnecessary_this
72+
- unrelated_type_equality_checks
73+
- valid_regexps

lib/src/builder.dart

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class _Builder extends Builder {
6464
throw new ArgumentError.value(_generatedExtension, 'generatedExtension',
6565
'Extension must be in the format of .*');
6666
}
67-
if (this._isStandalone && this._generators.length > 1) {
67+
if (_isStandalone && _generators.length > 1) {
6868
throw new ArgumentError(
6969
'A standalone file can only be generated from a single Generator.');
7070
}
@@ -125,14 +125,13 @@ class _Builder extends Builder {
125125
contentBuffer.writeln();
126126
}
127127

128-
for (GeneratedOutput output in generatedOutputs) {
129-
contentBuffer.writeln('');
130-
contentBuffer.writeln(_headerLine);
131-
contentBuffer.writeln('// Generator: ${output.generator}');
132-
contentBuffer.writeln(_headerLine);
133-
contentBuffer.writeln('');
134-
135-
contentBuffer.writeln(output.output);
128+
for (var output in generatedOutputs) {
129+
contentBuffer..writeln('')
130+
..writeln(_headerLine)
131+
..writeln('// Generator: ${output.generator}')
132+
..writeln(_headerLine)
133+
..writeln('')
134+
..writeln(output.output);
136135
}
137136

138137
var genPartContent = contentBuffer.toString();

lib/src/constants/utils.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ void assertHasField(ClassElement root, String name) {
1717
}
1818
element = element.supertype?.element;
1919
}
20-
final allFields = root.fields.toSet();
21-
allFields.addAll(root.allSupertypes.expand((t) => t.element.fields));
20+
final allFields = root.fields.toSet()
21+
..addAll(root.allSupertypes.expand((t) => t.element.fields));
2222
throw new FormatException(
2323
'Class ${root.name} does not have field "$name".',
2424
'Fields: \n - ${allFields.map((e) => e.name).join('\n - ')}',

lib/src/generated_output.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ class GeneratedOutput {
1818
: error = null,
1919
stackTrace = null;
2020

21-
GeneratedOutput.fromError(this.generator, Object error, [this.stackTrace])
22-
: this.output = _outputFromError(error),
23-
this.error = error;
21+
GeneratedOutput.fromError(this.generator, this.error, [this.stackTrace])
22+
: this.output = _outputFromError(error);
2423
}
2524

2625
String _outputFromError(Object error) {

lib/src/generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ abstract class Generator {
2323
FutureOr<String> generate(LibraryReader library, BuildStep buildStep) => null;
2424

2525
@override
26-
String toString() => this.runtimeType.toString();
26+
String toString() => runtimeType.toString();
2727
}
2828

2929
/// May be thrown by generators during [Generator.generate].

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: source_gen
2-
version: 0.7.6
2+
version: 0.8.0-dev
33
author: Dart Team <[email protected]>
44
description: Automated source code generation for Dart.
55
homepage: https://github.com/dart-lang/source_gen

test/builder_test.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void main() {
4949
generateFor: new Set.from(['$pkgName|lib/test_lib.dart']),
5050
outputs: {
5151
'$pkgName|lib/test_lib.g.dart':
52-
decodedMatches(startsWith(_customHeader + '\n\n// ***'))
52+
decodedMatches(startsWith('$_customHeader\n\n// ***'))
5353
});
5454
});
5555

@@ -94,7 +94,7 @@ void main() {
9494

9595
test('Does not fail when there is no output', () async {
9696
var sources = _createPackageStub(pkgName, testLibContent: 'class A {}');
97-
var builder = new PartBuilder([new CommentGenerator(forClasses: false)]);
97+
var builder = new PartBuilder([const CommentGenerator(forClasses: false)]);
9898
await testBuilder(builder, sources, outputs: {});
9999
});
100100

@@ -151,7 +151,7 @@ void main() {
151151

152152
test('defaults to formatting generated code with the DartFormatter',
153153
() async {
154-
await testBuilder(new PartBuilder([new UnformattedCodeGenerator()]),
154+
await testBuilder(new PartBuilder([const UnformattedCodeGenerator()]),
155155
{'$pkgName|lib/a.dart': 'library a; part "a.part.dart";'},
156156
generateFor: new Set.from(['$pkgName|lib/a.dart']),
157157
outputs: {
@@ -162,19 +162,19 @@ void main() {
162162

163163
test('PartBuilder uses a custom header when provided', () async {
164164
await testBuilder(
165-
new PartBuilder([new UnformattedCodeGenerator()],
165+
new PartBuilder([const UnformattedCodeGenerator()],
166166
header: _customHeader),
167167
{'$pkgName|lib/a.dart': 'library a; part "a.part.dart";'},
168168
generateFor: new Set.from(['$pkgName|lib/a.dart']),
169169
outputs: {
170170
'$pkgName|lib/a.g.dart':
171-
decodedMatches(startsWith(_customHeader + '\npart of')),
171+
decodedMatches(startsWith('$_customHeader\npart of')),
172172
});
173173
});
174174

175175
test('PartBuilder includes no header when `header` is empty', () async {
176176
await testBuilder(
177-
new PartBuilder([new UnformattedCodeGenerator()], header: ''),
177+
new PartBuilder([const UnformattedCodeGenerator()], header: ''),
178178
{'$pkgName|lib/a.dart': 'library a; part "a.part.dart";'},
179179
generateFor: new Set.from(['$pkgName|lib/a.dart']),
180180
outputs: {
@@ -184,7 +184,7 @@ void main() {
184184

185185
test('can skip formatting with a trivial lambda', () async {
186186
await testBuilder(
187-
new PartBuilder([new UnformattedCodeGenerator()],
187+
new PartBuilder([const UnformattedCodeGenerator()],
188188
formatOutput: (s) => s),
189189
{'$pkgName|lib/a.dart': 'library a; part "a.part.dart";'},
190190
generateFor: new Set.from(['$pkgName|lib/a.dart']),
@@ -197,7 +197,7 @@ void main() {
197197
test('can pass a custom formatter with formatOutput', () async {
198198
var customOutput = 'final String hello = "hello";';
199199
await testBuilder(
200-
new PartBuilder([new UnformattedCodeGenerator()],
200+
new PartBuilder([const UnformattedCodeGenerator()],
201201
formatOutput: (_) => customOutput),
202202
{'$pkgName|lib/a.dart': 'library a; part "a.part.dart";'},
203203
generateFor: new Set.from(['$pkgName|lib/a.dart']),
@@ -217,12 +217,12 @@ void main() {
217217
});
218218

219219
test('Should have a readable toString() message for builders', () {
220-
final builder = new LibraryBuilder(new _NoOpGenerator());
220+
final builder = new LibraryBuilder(const _NoOpGenerator());
221221
expect(builder.toString(), 'Generating .g.dart: NOOP');
222222

223223
final builders = new PartBuilder([
224-
new _NoOpGenerator(),
225-
new _NoOpGenerator(),
224+
const _NoOpGenerator(),
225+
const _NoOpGenerator(),
226226
]);
227227
expect(builders.toString(), 'Generating .g.dart: NOOP, NOOP');
228228
});

test/constants_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void main() {
176176

177177
test('should compare using TypeChecker', () {
178178
final $deprecated = constants[8];
179-
final check = new TypeChecker.fromRuntime(Deprecated);
179+
final check = const TypeChecker.fromRuntime(Deprecated);
180180
expect($deprecated.instanceOf(check), isTrue, reason: '$deprecated');
181181
});
182182
});

test/test_files/annotation_part.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
part of source_gen.test.annotation_test.defs;
5+
part of 'annotations.dart';
66

77
class PublicAnnotationClassInPart {
88
const PublicAnnotationClassInPart();

test/test_files/annotations.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
library source_gen.test.annotation_test.defs;
6-
5+
// ignore_for_file: prefer_initializing_formals
76
import 'dart:collection' as collection;
87

98
part 'annotation_part.dart';

0 commit comments

Comments
 (0)