Skip to content

Commit 2b1f992

Browse files
authored
new lints (#8849)
Dart lints added: * Avoid optional new * Avoid optional const * Prefer single quotes * Prefer default assignment `=`
1 parent 0c7a3f2 commit 2b1f992

34 files changed

Lines changed: 467 additions & 481 deletions

‎analysis_options.yaml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ linter:
100100
- prefer_const_literals_to_create_immutables
101101
# - prefer_constructors_over_static_methods # not yet tested
102102
- prefer_contains
103-
# - prefer_equal_for_default_values # not yet tested
103+
- prefer_equal_for_default_values
104104
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
105105
# - prefer_final_fields # DIFFERENT FROM FLUTTER/FLUTTER
106106
- prefer_final_locals
@@ -118,15 +118,16 @@ linter:
118118
- slash_for_doc_comments
119119
# - sort_constructors_first # DIFFERENT FROM FLUTTER/FLUTTER
120120
- sort_unnamed_constructors_first
121-
- super_goes_last
122121
- test_types_in_equals
123122
- throw_in_finally
124123
# - type_annotate_public_apis # subset of always_specify_types
125124
- type_init_formals
126125
# - unawaited_futures # https://github.com/flutter/flutter/issues/5793
127126
- unnecessary_brace_in_string_interps
127+
- unnecessary_const
128128
- unnecessary_getters_setters
129129
# - unnecessary_lambdas # https://github.com/dart-lang/linter/issues/498
130+
- unnecessary_new
130131
- unnecessary_null_aware_assignments
131132
- unnecessary_null_in_if_null_operators
132133
- unnecessary_overrides

‎ci/analyze.sh‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
#!/bin/bash
22
echo "Analyzing dart:ui library..."
3+
4+
echo "Using analyzer from `which dartanalyzer`"
5+
6+
dartanalyzer --version
7+
38
RESULTS=`dartanalyzer \
49
--options flutter/analysis_options.yaml \
510
"$1out/host_debug_unopt/gen/sky/bindings/dart_ui/ui.dart" \
611
2>&1 \
7-
| grep -Ev "No issues found!" \
12+
| grep -Ev "No issues found!" \
813
| grep -Ev "Analyzing.+out/host_debug_unopt/gen/sky/bindings/dart_ui/ui\.dart"`
914

1015
echo "$RESULTS"

‎ci/build.sh‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
set -ex
33

44
PATH="$HOME/depot_tools:$PATH"
5-
65
cd ..
76

7+
PATH=$(pwd)/third_party/dart/tools/sdks/dart-sdk/bin:$PATH
8+
89
# Build the dart UI files
910
flutter/tools/gn --unoptimized
1011
ninja -C out/host_debug_unopt generate_dart_ui

‎ci/licenses.sh‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ set -e
33
shopt -s nullglob
44

55
echo "Verifying license script is still happy..."
6+
echo "Using pub from `which pub`, dart from `which dart`"
7+
8+
dart --version
9+
610
(cd flutter/tools/licenses; pub get; dart --enable-asserts lib/main.dart --src ../../.. --out ../../../out/license_script_output --golden ../../ci/licenses_golden)
711

812
for f in out/license_script_output/licenses_*; do

‎flutter_kernel_transformers/lib/track_widget_constructor_locations.dart‎

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void _maybeAddCreationLocationArgument(
7676
}
7777

7878
final NamedExpression namedArgument =
79-
new NamedExpression(_creationLocationParameterName, creationLocation);
79+
NamedExpression(_creationLocationParameterName, creationLocation);
8080
namedArgument.parent = arguments;
8181
arguments.named.add(namedArgument);
8282
}
@@ -149,26 +149,26 @@ class _WidgetCallSiteTransformer extends Transformer {
149149
Location location, {
150150
String name,
151151
ListLiteral parameterLocations,
152-
bool showFile: true,
152+
bool showFile = true,
153153
}) {
154154
final List<NamedExpression> arguments = <NamedExpression>[
155-
new NamedExpression('line', new IntLiteral(location.line)),
156-
new NamedExpression('column', new IntLiteral(location.column)),
155+
NamedExpression('line', IntLiteral(location.line)),
156+
NamedExpression('column', IntLiteral(location.column)),
157157
];
158158
if (showFile) {
159-
arguments.add(new NamedExpression(
160-
'file', new StringLiteral(location.file.toString())));
159+
arguments.add(NamedExpression(
160+
'file', StringLiteral(location.file.toString())));
161161
}
162162
if (name != null) {
163-
arguments.add(new NamedExpression('name', new StringLiteral(name)));
163+
arguments.add(NamedExpression('name', StringLiteral(name)));
164164
}
165165
if (parameterLocations != null) {
166166
arguments
167-
.add(new NamedExpression('parameterLocations', parameterLocations));
167+
.add(NamedExpression('parameterLocations', parameterLocations));
168168
}
169-
return new ConstructorInvocation(
169+
return ConstructorInvocation(
170170
_locationClass.constructors.first,
171-
new Arguments(<Expression>[], named: arguments),
171+
Arguments(<Expression>[], named: arguments),
172172
isConst: true,
173173
);
174174
}
@@ -243,7 +243,7 @@ class _WidgetCallSiteTransformer extends Transformer {
243243
_creationLocationParameterName,
244244
);
245245
if (creationLocationParameter != null) {
246-
return new VariableGet(creationLocationParameter);
246+
return VariableGet(creationLocationParameter);
247247
}
248248
}
249249

@@ -270,7 +270,7 @@ class _WidgetCallSiteTransformer extends Transformer {
270270
}
271271
return _constructLocation(
272272
location,
273-
parameterLocations: new ListLiteral(
273+
parameterLocations: ListLiteral(
274274
parameterLocations,
275275
typeArgument: _locationClass.thisType,
276276
isConst: true,
@@ -342,12 +342,12 @@ class WidgetCreatorTracker implements ProgramTransformer {
342342
return;
343343
}
344344
clazz.implementedTypes
345-
.add(new Supertype(_hasCreationLocationClass, <DartType>[]));
345+
.add(Supertype(_hasCreationLocationClass, <DartType>[]));
346346
// We intentionally use the library context of the _HasCreationLocation
347347
// class for the private field even if [clazz] is in a different library
348348
// so that all classes implementing Widget behave consistently.
349-
final Field locationField = new Field(
350-
new Name(
349+
final Field locationField = Field(
350+
Name(
351351
_locationFieldName,
352352
_hasCreationLocationClass.enclosingLibrary,
353353
),
@@ -356,7 +356,7 @@ class WidgetCreatorTracker implements ProgramTransformer {
356356
clazz.addMember(locationField);
357357

358358
final Set<Constructor> _handledConstructors =
359-
new Set<Constructor>.identity();
359+
Set<Constructor>.identity();
360360

361361
void handleConstructor(Constructor constructor) {
362362
if (!_handledConstructors.add(constructor)) {
@@ -366,7 +366,7 @@ class WidgetCreatorTracker implements ProgramTransformer {
366366
constructor.function,
367367
_creationLocationParameterName,
368368
));
369-
final VariableDeclaration variable = new VariableDeclaration(
369+
final VariableDeclaration variable = VariableDeclaration(
370370
_creationLocationParameterName,
371371
type: _locationClass.thisType,
372372
);
@@ -386,17 +386,17 @@ class WidgetCreatorTracker implements ProgramTransformer {
386386
_maybeAddCreationLocationArgument(
387387
initializer.arguments,
388388
initializer.target.function,
389-
new VariableGet(variable),
389+
VariableGet(variable),
390390
_locationClass,
391391
);
392392
hasRedirectingInitializer = true;
393393
break;
394394
}
395395
}
396396
if (!hasRedirectingInitializer) {
397-
constructor.initializers.add(new FieldInitializer(
397+
constructor.initializers.add(FieldInitializer(
398398
locationField,
399-
new VariableGet(variable),
399+
VariableGet(variable),
400400
));
401401
// TODO(jacobr): add an assert verifying the locationField is not
402402
// null. Currently, we cannot safely add this assert because we do not
@@ -405,9 +405,9 @@ class WidgetCreatorTracker implements ProgramTransformer {
405405
// arguments but it is possible users could add classes with optional
406406
// positional arguments.
407407
//
408-
// constructor.initializers.add(new AssertInitializer(new AssertStatement(
409-
// new IsExpression(
410-
// new VariableGet(variable), _locationClass.thisType),
408+
// constructor.initializers.add(AssertInitializer(AssertStatement(
409+
// IsExpression(
410+
// VariableGet(variable), _locationClass.thisType),
411411
// conditionStartOffset: constructor.fileOffset,
412412
// conditionEndOffset: constructor.fileOffset,
413413
// )));
@@ -434,7 +434,7 @@ class WidgetCreatorTracker implements ProgramTransformer {
434434
}
435435
}
436436
}
437-
return new Component()..libraries.addAll(libraries);
437+
return Component()..libraries.addAll(libraries);
438438
}
439439

440440
/// Transform the given [program].
@@ -459,13 +459,13 @@ class WidgetCreatorTracker implements ProgramTransformer {
459459
// TODO(jacobr): once there is a working incremental ClassHierarchy
460460
// constructor switch to using it instead of building a ClassHierarchy off
461461
// the full program.
462-
hierarchy = new ClassHierarchy(
462+
hierarchy = ClassHierarchy(
463463
_computeFullProgram(program),
464464
onAmbiguousSupertypes: (Class cls, Supertype a, Supertype b) { },
465465
);
466466

467-
final Set<Class> transformedClasses = new Set<Class>.identity();
468-
final Set<Library> librariesToTransform = new Set<Library>.identity()
467+
final Set<Class> transformedClasses = Set<Class>.identity();
468+
final Set<Library> librariesToTransform = Set<Library>.identity()
469469
..addAll(libraries);
470470

471471
for (Library library in libraries) {
@@ -483,7 +483,7 @@ class WidgetCreatorTracker implements ProgramTransformer {
483483

484484
// Transform call sites to pass the location parameter.
485485
final _WidgetCallSiteTransformer callsiteTransformer =
486-
new _WidgetCallSiteTransformer(
486+
_WidgetCallSiteTransformer(
487487
hierarchy,
488488
widgetClass: _widgetClass,
489489
locationClass: _locationClass,
@@ -528,7 +528,7 @@ class WidgetCreatorTracker implements ProgramTransformer {
528528
if (procedure.isFactory) {
529529
_maybeAddNamedParameter(
530530
procedure.function,
531-
new VariableDeclaration(
531+
VariableDeclaration(
532532
_creationLocationParameterName,
533533
type: _locationClass.thisType,
534534
),
@@ -544,14 +544,14 @@ class WidgetCreatorTracker implements ProgramTransformer {
544544
}
545545

546546
final Set<Constructor> _handledConstructors =
547-
new Set<Constructor>.identity();
547+
Set<Constructor>.identity();
548548

549549
void handleConstructor(Constructor constructor) {
550550
if (!_handledConstructors.add(constructor)) {
551551
return;
552552
}
553553

554-
final VariableDeclaration variable = new VariableDeclaration(
554+
final VariableDeclaration variable = VariableDeclaration(
555555
_creationLocationParameterName,
556556
type: _locationClass.thisType,
557557
);
@@ -575,15 +575,15 @@ class WidgetCreatorTracker implements ProgramTransformer {
575575
_maybeAddCreationLocationArgument(
576576
initializer.arguments,
577577
initializer.target.function,
578-
new VariableGet(variable),
578+
VariableGet(variable),
579579
_locationClass,
580580
);
581581
} else if (initializer is SuperInitializer &&
582582
_isSubclassOfWidget(initializer.target.enclosingClass)) {
583583
_maybeAddCreationLocationArgument(
584584
initializer.arguments,
585585
initializer.target.function,
586-
new VariableGet(variable),
586+
VariableGet(variable),
587587
_locationClass,
588588
);
589589
}

‎frontend_server/lib/server.dart‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class _FlutterFrontendCompiler implements frontend.CompilerInterface{
2121
final frontend.CompilerInterface _compiler;
2222

2323
_FlutterFrontendCompiler(StringSink output,
24-
{bool trackWidgetCreation: false, bool unsafePackageSerialization}) :
25-
_compiler = new frontend.FrontendCompiler(output,
26-
transformer: trackWidgetCreation ? new WidgetCreatorTracker() : null,
24+
{bool trackWidgetCreation = false, bool unsafePackageSerialization}) :
25+
_compiler = frontend.FrontendCompiler(output,
26+
transformer: trackWidgetCreation ? WidgetCreatorTracker() : null,
2727
unsafePackageSerialization: unsafePackageSerialization);
2828

2929
@override
@@ -108,7 +108,7 @@ Future<int> starter(
108108
'--sdk-root=$sdkRoot',
109109
'--output-dill=$outputTrainingDill',
110110
'--target=flutter']);
111-
compiler ??= new _FlutterFrontendCompiler(output, trackWidgetCreation: true);
111+
compiler ??= _FlutterFrontendCompiler(output, trackWidgetCreation: true);
112112

113113
await compiler.compile(Platform.script.toFilePath(), options);
114114
compiler.acceptLastDelta();
@@ -125,15 +125,15 @@ Future<int> starter(
125125
}
126126
}
127127

128-
compiler ??= new _FlutterFrontendCompiler(output,
128+
compiler ??= _FlutterFrontendCompiler(output,
129129
trackWidgetCreation: options['track-widget-creation'],
130130
unsafePackageSerialization: options['unsafe-package-serialization']);
131131

132132
if (options.rest.isNotEmpty) {
133133
return await compiler.compile(options.rest[0], options) ? 0 : 254;
134134
}
135135

136-
final Completer<int> completer = new Completer<int>();
136+
final Completer<int> completer = Completer<int>();
137137
frontend.listenAndCompile(compiler, input ?? stdin, options, completer);
138138
return completer.future;
139139
}

‎frontend_server/test/server_test.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class _MockedCompiler extends Mock implements frontend.CompilerInterface {}
99

1010
Future<int> main() async {
1111
group('basic', () {
12-
final frontend.CompilerInterface compiler = new _MockedCompiler();
12+
final frontend.CompilerInterface compiler = _MockedCompiler();
1313

1414
test('train with mocked compiler completes', () async {
1515
expect(await starter(<String>['--train'], compiler: compiler), equals(0));

‎lib/ui/compositing.dart‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Scene extends NativeFieldWrapperClass2 {
2424
/// This is a slow operation that is performed on a background thread.
2525
Future<Image> toImage(int width, int height) {
2626
if (width <= 0 || height <= 0)
27-
throw new Exception('Invalid image dimensions.');
27+
throw Exception('Invalid image dimensions.');
2828
return _futurize(
2929
(_Callback<Image> callback) => _toImage(width, height, callback)
3030
);
@@ -242,7 +242,7 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
242242
/// Adds a [Picture] to the scene.
243243
///
244244
/// The picture is rasterized at the given offset.
245-
void addPicture(Offset offset, Picture picture, { bool isComplexHint: false, bool willChangeHint: false }) {
245+
void addPicture(Offset offset, Picture picture, { bool isComplexHint = false, bool willChangeHint = false }) {
246246
int hints = 0;
247247
if (isComplexHint)
248248
hints |= 1;
@@ -263,7 +263,7 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
263263
/// previous or new size, to workaround this the framework "freezes" the
264264
/// texture just before resizing the Android view and un-freezes it when it is
265265
/// certain that a frame with the new size is ready.
266-
void addTexture(int textureId, { Offset offset: Offset.zero, double width: 0.0, double height: 0.0 , bool freeze: false}) {
266+
void addTexture(int textureId, { Offset offset = Offset.zero, double width = 0.0, double height = 0.0 , bool freeze = false}) {
267267
assert(offset != null, 'Offset argument was null');
268268
_addTexture(offset.dx, offset.dy, width, height, textureId, freeze);
269269
}
@@ -285,7 +285,7 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
285285
/// With a platform view in the scene, Quartz has to composite the two Flutter surfaces and the
286286
/// embedded UIView. In addition to that, on iOS versions greater than 9, the Flutter frames are
287287
/// synchronized with the UIView frames adding additional performance overhead.
288-
void addPlatformView(int viewId, { Offset offset: Offset.zero, double width: 0.0, double height: 0.0}) {
288+
void addPlatformView(int viewId, { Offset offset = Offset.zero, double width = 0.0, double height = 0.0}) {
289289
assert(offset != null, 'Offset argument was null');
290290
_addPlatformView(offset.dx, offset.dy, width, height, viewId);
291291
}
@@ -294,11 +294,11 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
294294
/// (Fuchsia-only) Adds a scene rendered by another application to the scene
295295
/// for this application.
296296
void addChildScene({
297-
Offset offset: Offset.zero,
298-
double width: 0.0,
299-
double height: 0.0,
297+
Offset offset = Offset.zero,
298+
double width = 0.0,
299+
double height = 0.0,
300300
SceneHost sceneHost,
301-
bool hitTestable: true
301+
bool hitTestable = true
302302
}) {
303303
_addChildScene(offset.dx,
304304
offset.dy,

0 commit comments

Comments
 (0)