Auto-format Framework (#160545)
This auto-formats all *.dart files in the repository outside of the `engine` subdirectory and enforces that these files stay formatted with a presubmit check. **Reviewers:** Please carefully review all the commits except for the one titled "formatted". The "formatted" commit was auto-generated by running `dev/tools/format.sh -a -f`. The other commits were hand-crafted to prepare the repo for the formatting change. I recommend reviewing the commits one-by-one via the "Commits" tab and avoiding Github's "Files changed" tab as it will likely slow down your browser because of the size of this PR. --------- Co-authored-by: Kate Lovett <katelovett@google.com> Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
8e0993eda8
commit
5491c8c146
@@ -4,9 +4,9 @@
|
||||
|
||||
void main(List<String> args) {
|
||||
final String type = switch (args.first) {
|
||||
'--material' => 'material',
|
||||
'--material' => 'material',
|
||||
'--cupertino' => 'cupertino',
|
||||
_ => '',
|
||||
_ => '',
|
||||
};
|
||||
print('''
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
|
||||
@@ -34,18 +34,18 @@ void testNoDoubleClamp(int input) {
|
||||
|
||||
nonDoubleClamp.clamp(0, 2);
|
||||
input.clamp(0, 2);
|
||||
input.clamp(0.0, 2); // bad.
|
||||
input.clamp(0.0, 2); // bad.
|
||||
input.toDouble().clamp(0, 2); // bad.
|
||||
|
||||
nonDoubleClamp2?.clamp(0, 2);
|
||||
nullableInt?.clamp(0, 2);
|
||||
nullableInt?.clamp(0, 2.0); // bad
|
||||
nullableDouble?.clamp(0, 2); // bad.
|
||||
nullableInt?.clamp(0, 2.0); // bad
|
||||
nullableDouble?.clamp(0, 2); // bad.
|
||||
|
||||
// ignore: unused_local_variable
|
||||
final ClassWithAClampMethod Function(double, double)? tearOff1 = nonDoubleClamp2?.clamp;
|
||||
// ignore: unused_local_variable
|
||||
final num Function(num, num)? tearOff2 = nullableInt?.clamp; // bad.
|
||||
final num Function(num, num)? tearOff2 = nullableInt?.clamp; // bad.
|
||||
// ignore: unused_local_variable
|
||||
final num Function(num, num)? tearOff3 = nullableDouble?.clamp; // bad.
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import '../../foo/fake_render_box.dart';
|
||||
|
||||
mixin ARenderBoxMixin on RenderBox {
|
||||
@override
|
||||
void computeMaxIntrinsicWidth() { }
|
||||
void computeMaxIntrinsicWidth() {}
|
||||
|
||||
@override
|
||||
void computeMinIntrinsicWidth() => computeMaxIntrinsicWidth(); // BAD
|
||||
@@ -41,7 +41,7 @@ class RenderBoxSubclass2 extends RenderBox with ARenderBoxMixin {
|
||||
@override
|
||||
void computeMaxIntrinsicWidth() {
|
||||
super.computeMinIntrinsicHeight(); // OK
|
||||
super.computeMaxIntrinsicWidth(); // OK
|
||||
super.computeMaxIntrinsicWidth(); // OK
|
||||
final void Function() f = super.computeDryBaseline; // OK
|
||||
f();
|
||||
}
|
||||
|
||||
@@ -8,49 +8,63 @@ typedef ExternalStopwatchConstructor = externallib.MyStopwatch Function();
|
||||
|
||||
class StopwatchAtHome extends Stopwatch {
|
||||
StopwatchAtHome();
|
||||
StopwatchAtHome.create(): this();
|
||||
StopwatchAtHome.create() : this();
|
||||
|
||||
Stopwatch get stopwatch => this;
|
||||
}
|
||||
|
||||
void testNoStopwatches(Stopwatch stopwatch) {
|
||||
stopwatch.runtimeType; // OK for now, but we probably want to catch public APIs that take a Stopwatch?
|
||||
final Stopwatch localVariable = Stopwatch(); // Bad: introducing Stopwatch from dart:core.
|
||||
Stopwatch().runtimeType; // Bad: introducing Stopwatch from dart:core.
|
||||
// OK for now, but we probably want to catch public APIs that take a Stopwatch?
|
||||
stopwatch.runtimeType;
|
||||
// Bad: introducing Stopwatch from dart:core.
|
||||
final Stopwatch localVariable = Stopwatch();
|
||||
// Bad: introducing Stopwatch from dart:core.
|
||||
Stopwatch().runtimeType;
|
||||
|
||||
(localVariable..runtimeType) // OK: not directly introducing Stopwatch.
|
||||
.runtimeType;
|
||||
(localVariable..runtimeType) // OK: not directly introducing Stopwatch.
|
||||
.runtimeType;
|
||||
|
||||
StopwatchAtHome().runtimeType; // Bad: introducing a Stopwatch subclass.
|
||||
// Bad: introducing a Stopwatch subclass.
|
||||
StopwatchAtHome().runtimeType;
|
||||
|
||||
Stopwatch anotherStopwatch = stopwatch; // OK: not directly introducing Stopwatch.
|
||||
StopwatchAtHome Function() constructor = StopwatchAtHome.new; // Bad: introducing a Stopwatch constructor.
|
||||
// OK: not directly introducing Stopwatch.
|
||||
Stopwatch anotherStopwatch = stopwatch;
|
||||
// Bad: introducing a Stopwatch constructor.
|
||||
StopwatchAtHome Function() constructor = StopwatchAtHome.new;
|
||||
assert(() {
|
||||
anotherStopwatch = constructor()..runtimeType;
|
||||
constructor = StopwatchAtHome.create; // Bad: introducing a Stopwatch constructor.
|
||||
// Bad: introducing a Stopwatch constructor.
|
||||
constructor = StopwatchAtHome.create;
|
||||
anotherStopwatch = constructor()..runtimeType;
|
||||
return true;
|
||||
}());
|
||||
anotherStopwatch.runtimeType;
|
||||
|
||||
externallib.MyStopwatch.create(); // Bad: introducing an external Stopwatch constructor.
|
||||
// Bad: introducing an external Stopwatch constructor.
|
||||
externallib.MyStopwatch.create();
|
||||
ExternalStopwatchConstructor? externalConstructor;
|
||||
|
||||
assert(() {
|
||||
externalConstructor = externallib.MyStopwatch.new; // Bad: introducing an external Stopwatch constructor.
|
||||
// Bad: introducing an external Stopwatch constructor.
|
||||
externalConstructor = externallib.MyStopwatch.new;
|
||||
return true;
|
||||
}());
|
||||
externalConstructor?.call();
|
||||
|
||||
externallib.stopwatch.runtimeType; // Bad: introducing an external Stopwatch.
|
||||
externallib.createMyStopwatch().runtimeType; // Bad: calling an external function that returns a Stopwatch.
|
||||
externallib.createStopwatch().runtimeType; // Bad: calling an external function that returns a Stopwatch.
|
||||
externalConstructor = externallib.createMyStopwatch; // Bad: introducing the tear-off form of an external function that returns a Stopwatch.
|
||||
// Bad: introducing an external Stopwatch.
|
||||
externallib.stopwatch.runtimeType;
|
||||
// Bad: calling an external function that returns a Stopwatch.
|
||||
externallib.createMyStopwatch().runtimeType;
|
||||
// Bad: calling an external function that returns a Stopwatch.
|
||||
externallib.createStopwatch().runtimeType;
|
||||
// Bad: introducing the tear-off form of an external function that returns a Stopwatch.
|
||||
externalConstructor = externallib.createMyStopwatch;
|
||||
|
||||
constructor.call().stopwatch; // OK: existing instance.
|
||||
// OK: existing instance.
|
||||
constructor.call().stopwatch;
|
||||
}
|
||||
|
||||
void testStopwatchIgnore(Stopwatch stopwatch) {
|
||||
Stopwatch().runtimeType; // flutter_ignore: stopwatch (see analyze.dart)
|
||||
Stopwatch().runtimeType; // flutter_ignore: some_other_ignores, stopwatch (see analyze.dart)
|
||||
Stopwatch().runtimeType; // flutter_ignore: stopwatch (see analyze.dart)
|
||||
Stopwatch().runtimeType; // flutter_ignore: some_other_ignores, stopwatch (see analyze.dart)
|
||||
}
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
|
||||
@Deprecated(
|
||||
'This is the reason and what you should use instead. '
|
||||
'This feature was deprecated after v1.2.3.'
|
||||
'This feature was deprecated after v1.2.3.',
|
||||
)
|
||||
void test1() { }
|
||||
void test1() {}
|
||||
|
||||
// The code below is intentionally miss-formatted for testing.
|
||||
// dart format off
|
||||
@Deprecated(
|
||||
'Missing space ->.' //ignore: missing_whitespace_between_adjacent_strings
|
||||
'This feature was deprecated after v1.2.3.'
|
||||
@@ -105,3 +107,14 @@ void test18() { }
|
||||
'Missing the version line. '
|
||||
)
|
||||
void test19() { }
|
||||
// dart format on
|
||||
|
||||
// flutter_ignore: deprecation_syntax, https://github.com/flutter/flutter/issues/000000
|
||||
@Deprecated('Missing the version line. ')
|
||||
void test20() {}
|
||||
|
||||
class TestClass1 {
|
||||
// flutter_ignore: deprecation_syntax, https://github.com/flutter/flutter/issues/000000
|
||||
@Deprecated('Missing the version line. ')
|
||||
void test() {}
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
|
||||
bool isThereMeaningOfLife = true;
|
||||
|
||||
void main() {
|
||||
if (isThereMeaningOfLife) {}
|
||||
if(isThereMeaningOfLife) {}
|
||||
//^
|
||||
|
||||
switch (isThereMeaningOfLife) {
|
||||
case false:
|
||||
case true:
|
||||
}
|
||||
switch(isThereMeaningOfLife) {
|
||||
// ^
|
||||
case false:
|
||||
case true:
|
||||
}
|
||||
|
||||
for (int index = 0; index < 10; index++) {}
|
||||
for(int index = 0; index < 10; index++) {}
|
||||
// ^
|
||||
|
||||
while (isThereMeaningOfLife) {}
|
||||
while(isThereMeaningOfLife) {}
|
||||
// ^
|
||||
|
||||
try {
|
||||
} catch (e) {}
|
||||
try {
|
||||
} catch(e) {}
|
||||
// ^
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
class MyStopwatch implements Stopwatch {
|
||||
MyStopwatch();
|
||||
MyStopwatch.create(): this();
|
||||
MyStopwatch.create() : this();
|
||||
|
||||
@override
|
||||
Duration get elapsed => throw UnimplementedError();
|
||||
@@ -28,13 +28,13 @@ class MyStopwatch implements Stopwatch {
|
||||
bool get isRunning => throw UnimplementedError();
|
||||
|
||||
@override
|
||||
void reset() { }
|
||||
void reset() {}
|
||||
|
||||
@override
|
||||
void start() { }
|
||||
void start() {}
|
||||
|
||||
@override
|
||||
void stop() { }
|
||||
void stop() {}
|
||||
}
|
||||
|
||||
final MyStopwatch stopwatch = MyStopwatch.create();
|
||||
|
||||
Reference in New Issue
Block a user