Commit bb4f4070 authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

Prefer const constructors (#11853)

* upgrade to linter-0.1.35

* re-enable lint prefer_const_constructors

* address review comments
parent f0bf7b5c
......@@ -71,6 +71,7 @@ linter:
# === style rules ===
- always_declare_return_types
- always_put_control_body_on_new_line
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
- always_require_non_null_named_parameters
- always_specify_types
- annotate_overrides
......@@ -108,9 +109,11 @@ linter:
- package_prefixed_library_names
# - parameter_assignments # we do this commonly
- prefer_adjacent_string_concatenation
# - prefer_asserts_in_initializer_lists # not yet tested
- prefer_collection_literals
# - prefer_conditional_assignment # not yet tested
# - prefer_const_constructors # https://github.com/dart-lang/linter/issues/752
- prefer_const_constructors
# - prefer_const_constructors_in_immutables # not yet tested
# - prefer_constructors_over_static_methods # not yet tested
- prefer_contains
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
......@@ -122,6 +125,7 @@ linter:
# - prefer_interpolation_to_compose_strings # not yet tested
- prefer_is_empty
- prefer_is_not_empty
# - prefer_single_quote_strings # not yet tested
# - public_member_api_docs # this is the only difference from analysis_options_repo.yaml
# - recursive_getters # https://github.com/dart-lang/linter/issues/452
- slash_for_doc_comments
......
......@@ -65,6 +65,7 @@ linter:
# === style rules ===
- always_declare_return_types
- always_put_control_body_on_new_line
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
- always_require_non_null_named_parameters
- always_specify_types
- annotate_overrides
......@@ -102,9 +103,11 @@ linter:
- package_prefixed_library_names
# - parameter_assignments # we do this commonly
- prefer_adjacent_string_concatenation
# - prefer_asserts_in_initializer_lists # not yet tested
- prefer_collection_literals
# - prefer_conditional_assignment # not yet tested
# - prefer_const_constructors # https://github.com/dart-lang/linter/issues/752
- prefer_const_constructors
# - prefer_const_constructors_in_immutables # not yet tested
# - prefer_constructors_over_static_methods # not yet tested
- prefer_contains
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
......@@ -116,6 +119,7 @@ linter:
# - prefer_interpolation_to_compose_strings # not yet tested
- prefer_is_empty
- prefer_is_not_empty
# - prefer_single_quote_strings # not yet tested
- public_member_api_docs # this is the only difference from analysis_options_repo.yaml
# - recursive_getters # https://github.com/dart-lang/linter/issues/452
- slash_for_doc_comments
......
......@@ -98,7 +98,7 @@ void main() {
if (result != 0)
throw 'Received unexpected exit code $result from run process.';
print('test: validating that the app has in fact closed...');
await client.done.timeout(new Duration(seconds: 5));
await client.done.timeout(const Duration(seconds: 5));
});
return new TaskResult.success(null);
});
......
......@@ -18,7 +18,7 @@ class _FlavorState extends State<Flavor> {
@override
void initState() {
super.initState();
new MethodChannel('flavor').invokeMethod('getFlavor').then((String flavor) {
const MethodChannel('flavor').invokeMethod('getFlavor').then((String flavor) {
setState(() {
_flavor = flavor;
});
......@@ -28,7 +28,7 @@ class _FlavorState extends State<Flavor> {
@override
Widget build(BuildContext context) {
return _flavor == null
? new Text('Awaiting flavor...')
? const Text('Awaiting flavor...')
: new Text(_flavor, key: const ValueKey<String>('flavor'));
}
}
......@@ -16,7 +16,7 @@ Future<TestStepResult> systemNavigatorPop() {
channel.setMessageHandler((String message) async {
completer.complete(
new TestStepResult('System navigation pop', '', TestStatus.ok));
const TestStepResult('System navigation pop', '', TestStatus.ok));
return '';
});
SystemNavigator.pop();
......
......@@ -318,7 +318,7 @@ class _RenderInspectorOverlay extends RenderBox {
@override
void performResize() {
size = constraints.constrain(new Size(double.INFINITY, double.INFINITY));
size = constraints.constrain(const Size(double.INFINITY, double.INFINITY));
}
@override
......
......@@ -181,9 +181,9 @@ void main() {
));
// Disable slider
await tester.pumpWidget(new Directionality(
await tester.pumpWidget(const Directionality(
textDirection: TextDirection.ltr,
child: new CupertinoSlider(
child: const CupertinoSlider(
value: 0.5,
onChanged: null,
),
......
......@@ -253,7 +253,7 @@ void main() {
tester.route(pointer.move(const Offset(30.0, 25.0), timeStamp: const Duration(milliseconds: 30)));
tester.route(pointer.move(const Offset(40.0, 25.0), timeStamp: const Duration(milliseconds: 40)));
tester.route(pointer.move(const Offset(50.0, 25.0), timeStamp: const Duration(milliseconds: 50)));
tester.route(new PointerMoveEvent(
tester.route(const PointerMoveEvent(
pointer: 1,
// Simulate a small synthesized wobble which would have slowed down the
// horizontal velocity from 1 px/ms and introduced a slight vertical velocity.
......
......@@ -8,7 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('ButtonBar default control smoketest', (WidgetTester tester) async {
await tester.pumpWidget(
new Directionality(
const Directionality(
textDirection: TextDirection.ltr,
child: const ButtonBar(),
),
......
......@@ -178,13 +178,13 @@ void main() {
});
testWidgets('Chip in row works ok', (WidgetTester tester) async {
final TextStyle style = new TextStyle(fontFamily: 'Ahem', fontSize: 10.0);
final TextStyle style = const TextStyle(fontFamily: 'Ahem', fontSize: 10.0);
await tester.pumpWidget(
new MaterialApp(
home: new Material(
child: new Row(
children: <Widget>[
new Chip(label: new Text('Test'), labelStyle: style),
new Chip(label: const Text('Test'), labelStyle: style),
],
),
),
......@@ -197,7 +197,7 @@ void main() {
home: new Material(
child: new Row(
children: <Widget>[
new Flexible(child: new Chip(label: new Text('Test'), labelStyle: style)),
new Flexible(child: new Chip(label: const Text('Test'), labelStyle: style)),
],
),
),
......@@ -210,7 +210,7 @@ void main() {
home: new Material(
child: new Row(
children: <Widget>[
new Expanded(child: new Chip(label: new Text('Test'), labelStyle: style)),
new Expanded(child: new Chip(label: const Text('Test'), labelStyle: style)),
],
),
),
......@@ -228,7 +228,7 @@ void main() {
child: new Center(
child: new Chip(
onDeleted: () { },
label: new Text('ABC'),
label: const Text('ABC'),
),
),
);
......
......@@ -276,11 +276,11 @@ void main() {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (BuildContext context) => new Material(
child: new FlatButton(
child: new Text('PUSH'),
child: const Text('PUSH'),
onPressed: () { Navigator.of(context).pushNamed('/b'); },
),
),
'/b': (BuildContext context) => new Container(child: new Text('HELLO')),
'/b': (BuildContext context) => new Container(child: const Text('HELLO')),
};
await tester.pumpWidget(
new MaterialApp(
......
......@@ -110,7 +110,7 @@ void main() {
icon: const Icon(Icons.view_carousel),
itemBuilder: simplePopupMenuItemBuilder,
);
}, throwsA(new isInstanceOf<AssertionError>()));
}, throwsA(const isInstanceOf<AssertionError>()));
});
testWidgets('PopupMenuButton creates IconButton when given an icon', (WidgetTester tester) async {
......
......@@ -148,11 +148,11 @@ void main() {
Widget build(TextDirection textDirection) {
return new Directionality(
textDirection: textDirection,
child: new MediaQuery(
child: const MediaQuery(
data: const MediaQueryData(
padding: const EdgeInsets.only(bottom: 200.0),
),
child: new Scaffold(
child: const Scaffold(
floatingActionButton: const FloatingActionButton(
onPressed: null,
child: const Text('1'),
......
......@@ -472,10 +472,10 @@ void main() {
));
// Disable slider
await tester.pumpWidget(new Directionality(
await tester.pumpWidget(const Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new Slider(
child: const Material(
child: const Slider(
value: 0.5,
onChanged: null,
),
......
......@@ -358,7 +358,7 @@ void main() {
expect(exceptions, isEmpty);
layout(parent);
expect(exceptions, isNotEmpty);
expect(exceptions.first, new isInstanceOf<FlutterError>());
expect(exceptions.first, const isInstanceOf<FlutterError>());
});
test('MainAxisSize.min inside unconstrained', () {
......@@ -388,7 +388,7 @@ void main() {
expect(exceptions, isEmpty);
layout(parent);
expect(exceptions, isNotEmpty);
expect(exceptions.first, new isInstanceOf<FlutterError>());
expect(exceptions.first, const isInstanceOf<FlutterError>());
});
test('Flex RTL', () {
......
......@@ -8,7 +8,8 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
test('NetworkImage non-null url test', () {
expect(() {
new NetworkImage(null); // ignore: prefer_const_constructors
final String url = null; // we don't want this instance to be const because otherwise it would throw at compile time.
new NetworkImage(url);
}, throwsAssertionError);
});
}
......@@ -11,7 +11,7 @@ void main() {
final Widget inner = new Builder(
builder: (BuildContext context) {
log.add(Directionality.of(context));
return new Placeholder();
return const Placeholder();
}
);
await tester.pumpWidget(
......@@ -57,13 +57,16 @@ void main() {
builder: (BuildContext context) {
expect(Directionality.of(context), isNull);
good = true;
return new Placeholder();
return const Placeholder();
},
));
expect(good, isTrue);
});
testWidgets('Directionality can\'t be null', (WidgetTester tester) async {
expect(() { new Directionality(textDirection: null, child: new Placeholder()); }, throwsAssertionError);
expect(() {
final TextDirection textDirection = null; // we don't want this instance to be const because otherwise it would throw at compile time.
new Directionality(textDirection: textDirection, child: const Placeholder());
}, throwsAssertionError);
});
}
......@@ -130,7 +130,7 @@ void main() {
buildFrame(
buildContent: (BuildContext context) {
pageContext = context;
return new Text('Hello World');
return const Text('Hello World');
}
)
);
......@@ -153,7 +153,7 @@ void main() {
locale: locale,
buildContent: (BuildContext context) {
pageContext = context;
return new Text('Hello World');
return const Text('Hello World');
},
)
);
......@@ -295,7 +295,7 @@ void main() {
locale: const Locale('en', 'GB'),
delegates: <LocalizationsDelegate<dynamic>>[
new SyncTestLocalizationsDelegate(),
new DefaultWidgetsLocalizationsDelegate(),
const DefaultWidgetsLocalizationsDelegate(),
],
// Create a new context within the en_GB Localization
child: new Builder(
......
......@@ -7,9 +7,9 @@ import 'package:flutter/widgets.dart';
void main() {
testWidgets('Padding RTL', (WidgetTester tester) async {
final Widget child = new Padding(
padding: new EdgeInsetsDirectional.only(start: 10.0),
child: new Placeholder(),
final Widget child = const Padding(
padding: const EdgeInsetsDirectional.only(start: 10.0),
child: const Placeholder(),
);
await tester.pumpWidget(new Directionality(
textDirection: TextDirection.ltr,
......@@ -25,9 +25,9 @@ void main() {
testWidgets('Container padding/margin RTL', (WidgetTester tester) async {
final Widget child = new Container(
padding: new EdgeInsetsDirectional.only(start: 6.0),
margin: new EdgeInsetsDirectional.only(end: 20.0, start: 4.0),
child: new Placeholder(),
padding: const EdgeInsetsDirectional.only(start: 6.0),
margin: const EdgeInsetsDirectional.only(end: 20.0, start: 4.0),
child: const Placeholder(),
);
await tester.pumpWidget(new Directionality(
textDirection: TextDirection.ltr,
......@@ -45,9 +45,9 @@ void main() {
testWidgets('Container padding/margin mixed RTL/absolute', (WidgetTester tester) async {
final Widget child = new Container(
padding: new EdgeInsets.only(left: 6.0),
margin: new EdgeInsetsDirectional.only(end: 20.0, start: 4.0),
child: new Placeholder(),
padding: const EdgeInsets.only(left: 6.0),
margin: const EdgeInsetsDirectional.only(end: 20.0, start: 4.0),
child: const Placeholder(),
);
await tester.pumpWidget(new Directionality(
textDirection: TextDirection.ltr,
......@@ -64,7 +64,7 @@ void main() {
});
testWidgets('EdgeInsetsDirectional without Directionality', (WidgetTester tester) async {
await tester.pumpWidget(new Padding(padding: new EdgeInsetsDirectional.only()));
await tester.pumpWidget(const Padding(padding: const EdgeInsetsDirectional.only()));
expect(tester.takeException(), isAssertionError);
});
}
......@@ -51,10 +51,10 @@ Widget buildTestWidgets({bool excludeSemantics, String label, bool isSemanticsBo
isSemanticBoundary: isSemanticsBoundary,
child: new Column(
children: <Widget>[
new Semantics(
const Semantics(
label: 'child1',
),
new Semantics(
const Semantics(
label: 'child2',
),
],
......
......@@ -13,7 +13,7 @@ void main() {
testWidgets('markNeedsSemanticsUpdate allways resets node', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
await tester.pumpWidget(new TestWidget());
await tester.pumpWidget(const TestWidget());
final RenderTest renderObj = tester.renderObject(find.byType(TestWidget));
expect(renderObj.labelWasReset, hasLength(1));
expect(renderObj.labelWasReset.last, true);
......
......@@ -29,7 +29,7 @@ void main() {
child: new CustomScrollView(
controller: scrollController,
slivers: <Widget>[
new SliverAppBar(
const SliverAppBar(
pinned: true,
expandedHeight: appBarExpandedHeight,
title: const Text('Semantics Test with Slivers'),
......@@ -295,10 +295,10 @@ void main() {
final ScrollController controller = new ScrollController(initialScrollOffset: 280.0);
await tester.pumpWidget(
new MediaQuery(
data: new MediaQueryData(),
data: const MediaQueryData(),
child: new CustomScrollView(
slivers: <Widget>[
new SliverAppBar(
const SliverAppBar(
pinned: true,
expandedHeight: 100.0,
),
......@@ -377,11 +377,11 @@ void main() {
});
await tester.pumpWidget(
new MediaQuery(
data: new MediaQueryData(),
data: const MediaQueryData(),
child: new CustomScrollView(
controller: controller,
slivers: <Widget>[
new SliverAppBar(
const SliverAppBar(
pinned: true,
expandedHeight: 100.0,
),
......@@ -454,11 +454,11 @@ void main() {
final ScrollController controller = new ScrollController(initialScrollOffset: 280.0);
await tester.pumpWidget(
new MediaQuery(
data: new MediaQueryData(),
data: const MediaQueryData(),
child: new CustomScrollView(
reverse: true, // This is the important setting for this test.
slivers: <Widget>[
new SliverAppBar(
const SliverAppBar(
pinned: true,
expandedHeight: 100.0,
),
......@@ -538,12 +538,12 @@ void main() {
});
await tester.pumpWidget(
new MediaQuery(
data: new MediaQueryData(),
data: const MediaQueryData(),
child: new CustomScrollView(
reverse: true, // This is the important setting for this test.
controller: controller,
slivers: <Widget>[
new SliverAppBar(
const SliverAppBar(
pinned: true,
expandedHeight: 100.0,
),
......@@ -624,7 +624,7 @@ void main() {
});
await tester.pumpWidget(
new MediaQuery(
data: new MediaQueryData(),
data: const MediaQueryData(),
child: new Scrollable(
controller: controller,
viewportBuilder: (BuildContext context, ViewportOffset offset) {
......@@ -635,7 +635,7 @@ void main() {
new SliverList(
delegate: new SliverChildListDelegate(backwardChildren),
),
new SliverAppBar(
const SliverAppBar(
pinned: true,
expandedHeight: 100.0,
flexibleSpace: const FlexibleSpaceBar(
......
......@@ -90,7 +90,7 @@ iPhone SE (11.0) [667E8DCD-5DCD-4C80-93A9-60D1D995206F] (Simulator)
Runner(libsystem_asl.dylib)[297] <Notice>: libMobileGestalt MobileGestalt.c:550: no access to InverseDeviceID (see <rdar://problem/11744455>)
Runner(libsystem_asl.dylib)[297] <Notice>: I is for ichigo
'''.codeUnits]));
when(mockProcess.stderr).thenReturn(new Stream<List<int>>.empty());
when(mockProcess.stderr).thenReturn(const Stream<List<int>>.empty());
// Delay return of exitCode until after stdout stream data, since it terminates the logger.
when(mockProcess.exitCode).thenReturn(new Future<int>.delayed(Duration.ZERO, () => 0));
return new Future<Process>.value(mockProcess);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment