From 3c581953506ace6d80a4d9e12b2b17cf3d4bf0a9 Mon Sep 17 00:00:00 2001 From: Alexandre Ardhuin Date: Fri, 7 Sep 2018 09:13:13 +0200 Subject: [PATCH] lint unnecessary_const on samples (#21155) --- dev/bots/analyze-sample-code.dart | 6 +++++ .../lib/src/cupertino/segmented_control.dart | 4 ++-- .../lib/src/foundation/annotations.dart | 10 ++++---- .../flutter/lib/src/material/app_bar.dart | 2 +- packages/flutter/lib/src/material/card.dart | 6 ++--- .../flutter/lib/src/material/popup_menu.dart | 12 +++++----- .../flutter/lib/src/painting/box_border.dart | 24 +++++++++---------- .../flutter/lib/src/painting/gradient.dart | 10 ++++---- .../lib/src/services/platform_channel.dart | 2 +- packages/flutter/lib/src/widgets/basic.dart | 8 +++---- .../flutter/lib/src/widgets/scroll_view.dart | 4 ++-- packages/flutter/lib/src/widgets/text.dart | 8 +++---- 12 files changed, 51 insertions(+), 45 deletions(-) diff --git a/dev/bots/analyze-sample-code.dart b/dev/bots/analyze-sample-code.dart index 4507ebb783..a3087b7507 100644 --- a/dev/bots/analyze-sample-code.dart +++ b/dev/bots/analyze-sample-code.dart @@ -107,6 +107,7 @@ Future main(List arguments) async { try { final File mainDart = new File(path.join(tempDir.path, 'main.dart')); final File pubSpec = new File(path.join(tempDir.path, 'pubspec.yaml')); + final File analysisOptions = new File(path.join(tempDir.path, 'analysis_options.yaml')); Directory flutterPackage; if (arguments.length == 1) { // Used for testing. @@ -212,6 +213,11 @@ dependencies: sdk: flutter flutter_test: sdk: flutter +'''); + analysisOptions.writeAsStringSync(''' +linter: + rules: + - unnecessary_const '''); print('Found $sampleCodeSections sample code sections.'); final Process process = await Process.start( diff --git a/packages/flutter/lib/src/cupertino/segmented_control.dart b/packages/flutter/lib/src/cupertino/segmented_control.dart index b3c157e98f..551c0b9792 100644 --- a/packages/flutter/lib/src/cupertino/segmented_control.dart +++ b/packages/flutter/lib/src/cupertino/segmented_control.dart @@ -135,8 +135,8 @@ class CupertinoSegmentedControl extends StatefulWidget { /// /// class SegmentedControlExampleState extends State { /// final Map children = const { - /// 0: const Text('Child 1'), - /// 1: const Text('Child 2'), + /// 0: Text('Child 1'), + /// 1: Text('Child 2'), /// }; /// /// int currentValue; diff --git a/packages/flutter/lib/src/foundation/annotations.dart b/packages/flutter/lib/src/foundation/annotations.dart index 87b9f1161c..a01278be34 100644 --- a/packages/flutter/lib/src/foundation/annotations.dart +++ b/packages/flutter/lib/src/foundation/annotations.dart @@ -18,8 +18,8 @@ /// ```dart /// /// A copper coffee pot, as desired by Ben Turpin. /// /// ...documentation... -/// @Category(const ['Pots', 'Coffee']) -/// @Category(const ['Copper', 'Cookware']) +/// @Category(['Pots', 'Coffee']) +/// @Category(['Copper', 'Cookware']) /// @DocumentationIcon('https://example.com/images/coffee.png') /// @Summary('A proper cup of coffee is made in a proper copper coffee pot.') /// class CopperCoffeePot { @@ -55,7 +55,7 @@ class Category { /// ```dart /// /// Utility class for beginning a dream-sharing sequence. /// /// ...documentation... -/// @Category(const ['Military Technology', 'Experimental']) +/// @Category(['Military Technology', 'Experimental']) /// @DocumentationIcon('https://docs.example.org/icons/top.png') /// class DreamSharing { /// // ...code... @@ -89,8 +89,8 @@ class DocumentationIcon { /// /// /// /// Instances of this class can hunt small animals. /// /// This cat has three legs. -/// @Category(const ['Animals', 'Cats']) -/// @Category(const ['Cute', 'Pets']) +/// @Category(['Animals', 'Cats']) +/// @Category(['Cute', 'Pets']) /// @DocumentationIcon('https://www.examples.net/docs/images/icons/pillar.jpeg') /// @Summary('A famous three-legged cat.') /// class Pillar extends Cat { diff --git a/packages/flutter/lib/src/material/app_bar.dart b/packages/flutter/lib/src/material/app_bar.dart index 87e6a953a6..c99af2cc2e 100644 --- a/packages/flutter/lib/src/material/app_bar.dart +++ b/packages/flutter/lib/src/material/app_bar.dart @@ -696,7 +696,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { /// new SliverAppBar( /// expandedHeight: 150.0, /// flexibleSpace: const FlexibleSpaceBar( -/// title: const Text('Available seats'), +/// title: Text('Available seats'), /// ), /// actions: [ /// new IconButton( diff --git a/packages/flutter/lib/src/material/card.dart b/packages/flutter/lib/src/material/card.dart index 147bc8454c..688f6f0178 100644 --- a/packages/flutter/lib/src/material/card.dart +++ b/packages/flutter/lib/src/material/card.dart @@ -22,9 +22,9 @@ import 'theme.dart'; /// mainAxisSize: MainAxisSize.min, /// children: [ /// const ListTile( -/// leading: const Icon(Icons.album), -/// title: const Text('The Enchanted Nightingale'), -/// subtitle: const Text('Music by Julie Gable. Lyrics by Sidney Stein.'), +/// leading: Icon(Icons.album), +/// title: Text('The Enchanted Nightingale'), +/// subtitle: Text('Music by Julie Gable. Lyrics by Sidney Stein.'), /// ), /// new ButtonTheme.bar( // make buttons use the appropriate styles for cards /// child: new ButtonBar( diff --git a/packages/flutter/lib/src/material/popup_menu.dart b/packages/flutter/lib/src/material/popup_menu.dart index 1f2dcd9a93..ac542026cb 100644 --- a/packages/flutter/lib/src/material/popup_menu.dart +++ b/packages/flutter/lib/src/material/popup_menu.dart @@ -137,7 +137,7 @@ class _PopupMenuDividerState extends State { /// ```dart /// const PopupMenuItem( /// value: WhyFarther.harder, -/// child: const Text('Working a lot harder'), +/// child: Text('Working a lot harder'), /// ) /// ``` /// @@ -312,7 +312,7 @@ class PopupMenuItemState> extends State { /// const PopupMenuDivider(), /// const PopupMenuItem( /// value: Commands.hurricaneCame, -/// child: const ListTile(leading: const Icon(null), title: const Text('Bring hurricane')), +/// child: ListTile(leading: Icon(null), title: Text('Bring hurricane')), /// ), /// // ...other items listed here /// ], @@ -779,19 +779,19 @@ typedef List> PopupMenuItemBuilder(BuildContext context); /// itemBuilder: (BuildContext context) => >[ /// const PopupMenuItem( /// value: WhyFarther.harder, -/// child: const Text('Working a lot harder'), +/// child: Text('Working a lot harder'), /// ), /// const PopupMenuItem( /// value: WhyFarther.smarter, -/// child: const Text('Being a lot smarter'), +/// child: Text('Being a lot smarter'), /// ), /// const PopupMenuItem( /// value: WhyFarther.selfStarter, -/// child: const Text('Being a self-starter'), +/// child: Text('Being a self-starter'), /// ), /// const PopupMenuItem( /// value: WhyFarther.tradingCharter, -/// child: const Text('Placed in charge of trading charter'), +/// child: Text('Placed in charge of trading charter'), /// ), /// ], /// ) diff --git a/packages/flutter/lib/src/painting/box_border.dart b/packages/flutter/lib/src/painting/box_border.dart index 462462bc8e..04356038e2 100644 --- a/packages/flutter/lib/src/painting/box_border.dart +++ b/packages/flutter/lib/src/painting/box_border.dart @@ -265,28 +265,28 @@ abstract class BoxBorder extends ShapeBorder { /// ```dart /// new Container( /// decoration: const BoxDecoration( -/// border: const Border( -/// top: const BorderSide(width: 1.0, color: const Color(0xFFFFFFFFFF)), -/// left: const BorderSide(width: 1.0, color: const Color(0xFFFFFFFFFF)), -/// right: const BorderSide(width: 1.0, color: const Color(0xFFFF000000)), -/// bottom: const BorderSide(width: 1.0, color: const Color(0xFFFF000000)), +/// border: Border( +/// top: BorderSide(width: 1.0, color: Color(0xFFFFFFFFFF)), +/// left: BorderSide(width: 1.0, color: Color(0xFFFFFFFFFF)), +/// right: BorderSide(width: 1.0, color: Color(0xFFFF000000)), +/// bottom: BorderSide(width: 1.0, color: Color(0xFFFF000000)), /// ), /// ), /// child: new Container( /// padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 2.0), /// decoration: const BoxDecoration( -/// border: const Border( -/// top: const BorderSide(width: 1.0, color: const Color(0xFFFFDFDFDF)), -/// left: const BorderSide(width: 1.0, color: const Color(0xFFFFDFDFDF)), -/// right: const BorderSide(width: 1.0, color: const Color(0xFFFF7F7F7F)), -/// bottom: const BorderSide(width: 1.0, color: const Color(0xFFFF7F7F7F)), +/// border: Border( +/// top: BorderSide(width: 1.0, color: Color(0xFFFFDFDFDF)), +/// left: BorderSide(width: 1.0, color: Color(0xFFFFDFDFDF)), +/// right: BorderSide(width: 1.0, color: Color(0xFFFF7F7F7F)), +/// bottom: BorderSide(width: 1.0, color: Color(0xFFFF7F7F7F)), /// ), -/// color: const Color(0xFFBFBFBF), +/// color: Color(0xFFBFBFBF), /// ), /// child: const Text( /// 'OK', /// textAlign: TextAlign.center, -/// style: const TextStyle(color: const Color(0xFF000000)) +/// style: TextStyle(color: Color(0xFF000000)) /// ), /// ), /// ) diff --git a/packages/flutter/lib/src/painting/gradient.dart b/packages/flutter/lib/src/painting/gradient.dart index 4a80840cc1..b6b1a69b9e 100644 --- a/packages/flutter/lib/src/painting/gradient.dart +++ b/packages/flutter/lib/src/painting/gradient.dart @@ -740,11 +740,11 @@ class RadialGradient extends Gradient { /// startAngle: 0.0, /// endAngle: math.pi * 2, /// colors: const [ -/// const Color(0xFF4285F4), // blue -/// const Color(0xFF34A853), // green -/// const Color(0xFFFBBC05), // yellow -/// const Color(0xFFEA4335), // red -/// const Color(0xFF4285F4), // blue again to seamlessly transition to the start +/// Color(0xFF4285F4), // blue +/// Color(0xFF34A853), // green +/// Color(0xFFFBBC05), // yellow +/// Color(0xFFEA4335), // red +/// Color(0xFF4285F4), // blue again to seamlessly transition to the start /// ], /// stops: const [0.0, 0.25, 0.5, 0.75, 1.0], /// ), diff --git a/packages/flutter/lib/src/services/platform_channel.dart b/packages/flutter/lib/src/services/platform_channel.dart index dee5be5f7c..98c89fbc75 100644 --- a/packages/flutter/lib/src/services/platform_channel.dart +++ b/packages/flutter/lib/src/services/platform_channel.dart @@ -144,7 +144,7 @@ class MethodChannel { /// /// ```dart /// class Music { - /// static const MethodChannel _channel = const MethodChannel('music'); + /// static const MethodChannel _channel = MethodChannel('music'); /// /// static Future isLicensed() async { /// // invokeMethod returns a Future, and we cannot pass that for diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index 3c772a0dc9..0f9f224c34 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -370,7 +370,7 @@ class BackdropFilter extends SingleChildRenderObjectWidget { /// style: const TextStyle( /// fontSize: 40.0, /// fontWeight: FontWeight.w900, -/// color: const Color(0xFFFFFFFF), +/// color: Color(0xFFFFFFFF), /// ), /// ), /// ), @@ -1360,7 +1360,7 @@ class RotatedBox extends SingleChildRenderObjectWidget { /// ```dart /// new Padding( /// padding: new EdgeInsets.all(8.0), -/// child: const Card(child: const Text('Hello World!')), +/// child: const Card(child: Text('Hello World!')), /// ) /// ``` /// @@ -1700,7 +1700,7 @@ class CustomMultiChildLayout extends MultiChildRenderObjectWidget { /// new SizedBox( /// width: 200.0, /// height: 300.0, -/// child: const Card(child: const Text('Hello World!')), +/// child: const Card(child: Text('Hello World!')), /// ) /// ``` /// @@ -1806,7 +1806,7 @@ class SizedBox extends SingleChildRenderObjectWidget { /// ```dart /// new ConstrainedBox( /// constraints: const BoxConstraints.expand(), -/// child: const Card(child: const Text('Hello World!')), +/// child: const Card(child: Text('Hello World!')), /// ) /// ``` /// diff --git a/packages/flutter/lib/src/widgets/scroll_view.dart b/packages/flutter/lib/src/widgets/scroll_view.dart index b6ed75f2cc..3d6075850b 100644 --- a/packages/flutter/lib/src/widgets/scroll_view.dart +++ b/packages/flutter/lib/src/widgets/scroll_view.dart @@ -279,8 +279,8 @@ abstract class ScrollView extends StatelessWidget { /// const SliverAppBar( /// pinned: true, /// expandedHeight: 250.0, -/// flexibleSpace: const FlexibleSpaceBar( -/// title: const Text('Demo'), +/// flexibleSpace: FlexibleSpaceBar( +/// title: Text('Demo'), /// ), /// ), /// new SliverGrid( diff --git a/packages/flutter/lib/src/widgets/text.dart b/packages/flutter/lib/src/widgets/text.dart index bba75c5414..0a225904f0 100644 --- a/packages/flutter/lib/src/widgets/text.dart +++ b/packages/flutter/lib/src/widgets/text.dart @@ -184,11 +184,11 @@ class DefaultTextStyle extends InheritedWidget { /// /// ```dart /// const Text.rich( -/// const TextSpan( +/// TextSpan( /// text: 'Hello', // default text style -/// children: const [ -/// const TextSpan(text: ' beautiful ', style: const TextStyle(fontStyle: FontStyle.italic)), -/// const TextSpan(text: 'world', style: const TextStyle(fontWeight: FontWeight.bold)), +/// children: [ +/// TextSpan(text: ' beautiful ', style: TextStyle(fontStyle: FontStyle.italic)), +/// TextSpan(text: 'world', style: TextStyle(fontWeight: FontWeight.bold)), /// ], /// ), /// )