Skip to content

Commit

Permalink
new lints (flutter#8849)
Browse files Browse the repository at this point in the history
Dart lints added:
* Avoid optional new
* Avoid optional const
* Prefer single quotes
* Prefer default assignment `=`
  • Loading branch information
dnfield authored May 7, 2019
1 parent 0c7a3f2 commit 2b1f992
Show file tree
Hide file tree
Showing 34 changed files with 467 additions and 481 deletions.
5 changes: 3 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ linter:
- prefer_const_literals_to_create_immutables
# - prefer_constructors_over_static_methods # not yet tested
- prefer_contains
# - prefer_equal_for_default_values # not yet tested
- prefer_equal_for_default_values
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
# - prefer_final_fields # DIFFERENT FROM FLUTTER/FLUTTER
- prefer_final_locals
Expand All @@ -118,15 +118,16 @@ linter:
- slash_for_doc_comments
# - sort_constructors_first # DIFFERENT FROM FLUTTER/FLUTTER
- sort_unnamed_constructors_first
- super_goes_last
- test_types_in_equals
- throw_in_finally
# - type_annotate_public_apis # subset of always_specify_types
- type_init_formals
# - unawaited_futures # https://github.com/flutter/flutter/issues/5793
- unnecessary_brace_in_string_interps
- unnecessary_const
- unnecessary_getters_setters
# - unnecessary_lambdas # https://github.com/dart-lang/linter/issues/498
- unnecessary_new
- unnecessary_null_aware_assignments
- unnecessary_null_in_if_null_operators
- unnecessary_overrides
Expand Down
7 changes: 6 additions & 1 deletion ci/analyze.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#!/bin/bash
echo "Analyzing dart:ui library..."

echo "Using analyzer from `which dartanalyzer`"

dartanalyzer --version

RESULTS=`dartanalyzer \
--options flutter/analysis_options.yaml \
"$1out/host_debug_unopt/gen/sky/bindings/dart_ui/ui.dart" \
2>&1 \
| grep -Ev "No issues found!" \
| grep -Ev "No issues found!" \
| grep -Ev "Analyzing.+out/host_debug_unopt/gen/sky/bindings/dart_ui/ui\.dart"`

echo "$RESULTS"
Expand Down
3 changes: 2 additions & 1 deletion ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
set -ex

PATH="$HOME/depot_tools:$PATH"

cd ..

PATH=$(pwd)/third_party/dart/tools/sdks/dart-sdk/bin:$PATH

# Build the dart UI files
flutter/tools/gn --unoptimized
ninja -C out/host_debug_unopt generate_dart_ui
Expand Down
4 changes: 4 additions & 0 deletions ci/licenses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ set -e
shopt -s nullglob

echo "Verifying license script is still happy..."
echo "Using pub from `which pub`, dart from `which dart`"

dart --version

(cd flutter/tools/licenses; pub get; dart --enable-asserts lib/main.dart --src ../../.. --out ../../../out/license_script_output --golden ../../ci/licenses_golden)

for f in out/license_script_output/licenses_*; do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void _maybeAddCreationLocationArgument(
}

final NamedExpression namedArgument =
new NamedExpression(_creationLocationParameterName, creationLocation);
NamedExpression(_creationLocationParameterName, creationLocation);
namedArgument.parent = arguments;
arguments.named.add(namedArgument);
}
Expand Down Expand Up @@ -149,26 +149,26 @@ class _WidgetCallSiteTransformer extends Transformer {
Location location, {
String name,
ListLiteral parameterLocations,
bool showFile: true,
bool showFile = true,
}) {
final List<NamedExpression> arguments = <NamedExpression>[
new NamedExpression('line', new IntLiteral(location.line)),
new NamedExpression('column', new IntLiteral(location.column)),
NamedExpression('line', IntLiteral(location.line)),
NamedExpression('column', IntLiteral(location.column)),
];
if (showFile) {
arguments.add(new NamedExpression(
'file', new StringLiteral(location.file.toString())));
arguments.add(NamedExpression(
'file', StringLiteral(location.file.toString())));
}
if (name != null) {
arguments.add(new NamedExpression('name', new StringLiteral(name)));
arguments.add(NamedExpression('name', StringLiteral(name)));
}
if (parameterLocations != null) {
arguments
.add(new NamedExpression('parameterLocations', parameterLocations));
.add(NamedExpression('parameterLocations', parameterLocations));
}
return new ConstructorInvocation(
return ConstructorInvocation(
_locationClass.constructors.first,
new Arguments(<Expression>[], named: arguments),
Arguments(<Expression>[], named: arguments),
isConst: true,
);
}
Expand Down Expand Up @@ -243,7 +243,7 @@ class _WidgetCallSiteTransformer extends Transformer {
_creationLocationParameterName,
);
if (creationLocationParameter != null) {
return new VariableGet(creationLocationParameter);
return VariableGet(creationLocationParameter);
}
}

Expand All @@ -270,7 +270,7 @@ class _WidgetCallSiteTransformer extends Transformer {
}
return _constructLocation(
location,
parameterLocations: new ListLiteral(
parameterLocations: ListLiteral(
parameterLocations,
typeArgument: _locationClass.thisType,
isConst: true,
Expand Down Expand Up @@ -342,12 +342,12 @@ class WidgetCreatorTracker implements ProgramTransformer {
return;
}
clazz.implementedTypes
.add(new Supertype(_hasCreationLocationClass, <DartType>[]));
.add(Supertype(_hasCreationLocationClass, <DartType>[]));
// We intentionally use the library context of the _HasCreationLocation
// class for the private field even if [clazz] is in a different library
// so that all classes implementing Widget behave consistently.
final Field locationField = new Field(
new Name(
final Field locationField = Field(
Name(
_locationFieldName,
_hasCreationLocationClass.enclosingLibrary,
),
Expand All @@ -356,7 +356,7 @@ class WidgetCreatorTracker implements ProgramTransformer {
clazz.addMember(locationField);

final Set<Constructor> _handledConstructors =
new Set<Constructor>.identity();
Set<Constructor>.identity();

void handleConstructor(Constructor constructor) {
if (!_handledConstructors.add(constructor)) {
Expand All @@ -366,7 +366,7 @@ class WidgetCreatorTracker implements ProgramTransformer {
constructor.function,
_creationLocationParameterName,
));
final VariableDeclaration variable = new VariableDeclaration(
final VariableDeclaration variable = VariableDeclaration(
_creationLocationParameterName,
type: _locationClass.thisType,
);
Expand All @@ -386,17 +386,17 @@ class WidgetCreatorTracker implements ProgramTransformer {
_maybeAddCreationLocationArgument(
initializer.arguments,
initializer.target.function,
new VariableGet(variable),
VariableGet(variable),
_locationClass,
);
hasRedirectingInitializer = true;
break;
}
}
if (!hasRedirectingInitializer) {
constructor.initializers.add(new FieldInitializer(
constructor.initializers.add(FieldInitializer(
locationField,
new VariableGet(variable),
VariableGet(variable),
));
// TODO(jacobr): add an assert verifying the locationField is not
// null. Currently, we cannot safely add this assert because we do not
Expand All @@ -405,9 +405,9 @@ class WidgetCreatorTracker implements ProgramTransformer {
// arguments but it is possible users could add classes with optional
// positional arguments.
//
// constructor.initializers.add(new AssertInitializer(new AssertStatement(
// new IsExpression(
// new VariableGet(variable), _locationClass.thisType),
// constructor.initializers.add(AssertInitializer(AssertStatement(
// IsExpression(
// VariableGet(variable), _locationClass.thisType),
// conditionStartOffset: constructor.fileOffset,
// conditionEndOffset: constructor.fileOffset,
// )));
Expand All @@ -434,7 +434,7 @@ class WidgetCreatorTracker implements ProgramTransformer {
}
}
}
return new Component()..libraries.addAll(libraries);
return Component()..libraries.addAll(libraries);
}

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

final Set<Class> transformedClasses = new Set<Class>.identity();
final Set<Library> librariesToTransform = new Set<Library>.identity()
final Set<Class> transformedClasses = Set<Class>.identity();
final Set<Library> librariesToTransform = Set<Library>.identity()
..addAll(libraries);

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

// Transform call sites to pass the location parameter.
final _WidgetCallSiteTransformer callsiteTransformer =
new _WidgetCallSiteTransformer(
_WidgetCallSiteTransformer(
hierarchy,
widgetClass: _widgetClass,
locationClass: _locationClass,
Expand Down Expand Up @@ -528,7 +528,7 @@ class WidgetCreatorTracker implements ProgramTransformer {
if (procedure.isFactory) {
_maybeAddNamedParameter(
procedure.function,
new VariableDeclaration(
VariableDeclaration(
_creationLocationParameterName,
type: _locationClass.thisType,
),
Expand All @@ -544,14 +544,14 @@ class WidgetCreatorTracker implements ProgramTransformer {
}

final Set<Constructor> _handledConstructors =
new Set<Constructor>.identity();
Set<Constructor>.identity();

void handleConstructor(Constructor constructor) {
if (!_handledConstructors.add(constructor)) {
return;
}

final VariableDeclaration variable = new VariableDeclaration(
final VariableDeclaration variable = VariableDeclaration(
_creationLocationParameterName,
type: _locationClass.thisType,
);
Expand All @@ -575,15 +575,15 @@ class WidgetCreatorTracker implements ProgramTransformer {
_maybeAddCreationLocationArgument(
initializer.arguments,
initializer.target.function,
new VariableGet(variable),
VariableGet(variable),
_locationClass,
);
} else if (initializer is SuperInitializer &&
_isSubclassOfWidget(initializer.target.enclosingClass)) {
_maybeAddCreationLocationArgument(
initializer.arguments,
initializer.target.function,
new VariableGet(variable),
VariableGet(variable),
_locationClass,
);
}
Expand Down
12 changes: 6 additions & 6 deletions frontend_server/lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class _FlutterFrontendCompiler implements frontend.CompilerInterface{
final frontend.CompilerInterface _compiler;

_FlutterFrontendCompiler(StringSink output,
{bool trackWidgetCreation: false, bool unsafePackageSerialization}) :
_compiler = new frontend.FrontendCompiler(output,
transformer: trackWidgetCreation ? new WidgetCreatorTracker() : null,
{bool trackWidgetCreation = false, bool unsafePackageSerialization}) :
_compiler = frontend.FrontendCompiler(output,
transformer: trackWidgetCreation ? WidgetCreatorTracker() : null,
unsafePackageSerialization: unsafePackageSerialization);

@override
Expand Down Expand Up @@ -108,7 +108,7 @@ Future<int> starter(
'--sdk-root=$sdkRoot',
'--output-dill=$outputTrainingDill',
'--target=flutter']);
compiler ??= new _FlutterFrontendCompiler(output, trackWidgetCreation: true);
compiler ??= _FlutterFrontendCompiler(output, trackWidgetCreation: true);

await compiler.compile(Platform.script.toFilePath(), options);
compiler.acceptLastDelta();
Expand All @@ -125,15 +125,15 @@ Future<int> starter(
}
}

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

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

final Completer<int> completer = new Completer<int>();
final Completer<int> completer = Completer<int>();
frontend.listenAndCompile(compiler, input ?? stdin, options, completer);
return completer.future;
}
2 changes: 1 addition & 1 deletion frontend_server/test/server_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class _MockedCompiler extends Mock implements frontend.CompilerInterface {}

Future<int> main() async {
group('basic', () {
final frontend.CompilerInterface compiler = new _MockedCompiler();
final frontend.CompilerInterface compiler = _MockedCompiler();

test('train with mocked compiler completes', () async {
expect(await starter(<String>['--train'], compiler: compiler), equals(0));
Expand Down
16 changes: 8 additions & 8 deletions lib/ui/compositing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Scene extends NativeFieldWrapperClass2 {
/// This is a slow operation that is performed on a background thread.
Future<Image> toImage(int width, int height) {
if (width <= 0 || height <= 0)
throw new Exception('Invalid image dimensions.');
throw Exception('Invalid image dimensions.');
return _futurize(
(_Callback<Image> callback) => _toImage(width, height, callback)
);
Expand Down Expand Up @@ -242,7 +242,7 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
/// Adds a [Picture] to the scene.
///
/// The picture is rasterized at the given offset.
void addPicture(Offset offset, Picture picture, { bool isComplexHint: false, bool willChangeHint: false }) {
void addPicture(Offset offset, Picture picture, { bool isComplexHint = false, bool willChangeHint = false }) {
int hints = 0;
if (isComplexHint)
hints |= 1;
Expand All @@ -263,7 +263,7 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
/// previous or new size, to workaround this the framework "freezes" the
/// texture just before resizing the Android view and un-freezes it when it is
/// certain that a frame with the new size is ready.
void addTexture(int textureId, { Offset offset: Offset.zero, double width: 0.0, double height: 0.0 , bool freeze: false}) {
void addTexture(int textureId, { Offset offset = Offset.zero, double width = 0.0, double height = 0.0 , bool freeze = false}) {
assert(offset != null, 'Offset argument was null');
_addTexture(offset.dx, offset.dy, width, height, textureId, freeze);
}
Expand All @@ -285,7 +285,7 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
/// With a platform view in the scene, Quartz has to composite the two Flutter surfaces and the
/// embedded UIView. In addition to that, on iOS versions greater than 9, the Flutter frames are
/// synchronized with the UIView frames adding additional performance overhead.
void addPlatformView(int viewId, { Offset offset: Offset.zero, double width: 0.0, double height: 0.0}) {
void addPlatformView(int viewId, { Offset offset = Offset.zero, double width = 0.0, double height = 0.0}) {
assert(offset != null, 'Offset argument was null');
_addPlatformView(offset.dx, offset.dy, width, height, viewId);
}
Expand All @@ -294,11 +294,11 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
/// (Fuchsia-only) Adds a scene rendered by another application to the scene
/// for this application.
void addChildScene({
Offset offset: Offset.zero,
double width: 0.0,
double height: 0.0,
Offset offset = Offset.zero,
double width = 0.0,
double height = 0.0,
SceneHost sceneHost,
bool hitTestable: true
bool hitTestable = true
}) {
_addChildScene(offset.dx,
offset.dy,
Expand Down
Loading

0 comments on commit 2b1f992

Please sign in to comment.