Skip to content

Commit

Permalink
Add new lints (flutter#96)
Browse files Browse the repository at this point in the history
* Update pedantic to 1.9.0

* Remove duplicated lints

* Add pedantic to dev_dependencies

* Fix typo

* Ignore omit_local_variable_types errors

* Update code_segments.dart

* Add const to Icon and Interval

* Update analysis_options.yaml

* Apply omit_local_variable_type

Former-commit-id: 74d9d92
  • Loading branch information
guidezpl authored Apr 10, 2020
1 parent b0c0bf0 commit 25561df
Show file tree
Hide file tree
Showing 66 changed files with 428 additions and 458 deletions.
6 changes: 2 additions & 4 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include: package:pedantic/analysis_options.1.8.0.yaml
include: package:pedantic/analysis_options.1.9.0.yaml

analyzer:
exclude:
Expand All @@ -17,6 +17,7 @@ linter:
- close_sinks
- constant_identifier_names
- control_flow_in_finally
- directives_ordering
- empty_statements
- hash_and_equals
- implementation_imports
Expand All @@ -30,7 +31,4 @@ linter:
- throw_in_finally
- unnecessary_brace_in_string_interps
- unnecessary_getters_setters
- unnecessary_const
- unnecessary_new
- unnecessary_statements
- directives_ordering
2 changes: 1 addition & 1 deletion lib/codeviewer/code_displayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

import 'package:flutter/material.dart';

typedef TextSpan CodeDisplayer(BuildContext context);
typedef CodeDisplayer = TextSpan Function(BuildContext context);
2 changes: 1 addition & 1 deletion lib/codeviewer/code_segments.dart.REMOVED.git-id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ee0f154b0f6f35b5f8cfb448017c700145628523
ff5ab3f978fe246aacc3b78d1c82c58b0cd2587a
2 changes: 1 addition & 1 deletion lib/data/demos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class GalleryDemo {
final IconData icon;
final List<GalleryDemoConfiguration> configurations;

String get describe => '${this.title}@${this.category.name}';
String get describe => '$title@${category.name}';
}

class GalleryDemoConfiguration {
Expand Down
13 changes: 6 additions & 7 deletions lib/data/gallery_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ const systemLocaleOption = Locale('system');
Locale _deviceLocale;
Locale get deviceLocale => _deviceLocale;
set deviceLocale(Locale locale) {
if (_deviceLocale == null) {
_deviceLocale = locale;
}
_deviceLocale ??= locale;
}

class GalleryOptions {
Expand Down Expand Up @@ -80,7 +78,7 @@ class GalleryOptions {
TextDirection textDirection() {
switch (customTextDirection) {
case CustomTextDirection.localeBased:
final String language = locale?.languageCode?.toLowerCase();
final language = locale?.languageCode?.toLowerCase();
if (language == null) return null;
return rtlLanguages.contains(language)
? TextDirection.rtl
Expand All @@ -102,7 +100,7 @@ class GalleryOptions {
}) {
return GalleryOptions(
themeMode: themeMode ?? this.themeMode,
textScaleFactor: textScaleFactor ?? this._textScaleFactor,
textScaleFactor: textScaleFactor ?? _textScaleFactor,
customTextDirection: customTextDirection ?? this.customTextDirection,
locale: locale ?? this.locale,
timeDilation: timeDilation ?? this.timeDilation,
Expand Down Expand Up @@ -131,13 +129,13 @@ class GalleryOptions {
);

static GalleryOptions of(BuildContext context) {
final _ModelBindingScope scope =
final scope =
context.dependOnInheritedWidgetOfExactType<_ModelBindingScope>();
return scope.modelBindingState.currentModel;
}

static void update(BuildContext context, GalleryOptions newModel) {
final _ModelBindingScope scope =
final scope =
context.dependOnInheritedWidgetOfExactType<_ModelBindingScope>();
scope.modelBindingState.updateModel(newModel);
}
Expand Down Expand Up @@ -198,6 +196,7 @@ class ModelBinding extends StatefulWidget {
final GalleryOptions initialModel;
final Widget child;

@override
_ModelBindingState createState() => _ModelBindingState();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/demos/cupertino/cupertino_text_field_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CupertinoTextFieldDemo extends StatelessWidget {
),
),
CupertinoTextField(
prefix: Icon(
prefix: const Icon(
CupertinoIcons.padlock_solid,
size: 28,
),
Expand Down
6 changes: 3 additions & 3 deletions lib/demos/material/bottom_navigation_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ class _BottomNavigationDemoState extends State<BottomNavigationDemo>

@override
void dispose() {
for (_NavigationIconView view in _navigationViews) {
for (final view in _navigationViews) {
view.controller.dispose();
}
super.dispose();
}

Widget _buildTransitionsStack() {
final List<FadeTransition> transitions = <FadeTransition>[];
final transitions = <FadeTransition>[];

for (_NavigationIconView view in _navigationViews) {
for (final view in _navigationViews) {
transitions.add(view.transition(context));
}

Expand Down
2 changes: 1 addition & 1 deletion lib/demos/material/button_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class _ToggleButtonsDemoState extends State<_ToggleButtonsDemo> {
Widget build(BuildContext context) {
return Center(
child: ToggleButtons(
children: [
children: const [
Icon(Icons.ac_unit),
Icon(Icons.call),
Icon(Icons.cake),
Expand Down
9 changes: 4 additions & 5 deletions lib/demos/material/cards_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class _SelectableTravelDestinationItemState

@override
Widget build(BuildContext context) {
final ColorScheme colorScheme = Theme.of(context).colorScheme;
final colorScheme = Theme.of(context).colorScheme;

return SafeArea(
top: false,
Expand Down Expand Up @@ -278,10 +278,9 @@ class TravelDestinationContent extends StatelessWidget {

@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
final TextStyle titleStyle =
theme.textTheme.headline5.copyWith(color: Colors.white);
final TextStyle descriptionStyle = theme.textTheme.subtitle1;
final theme = Theme.of(context);
final titleStyle = theme.textTheme.headline5.copyWith(color: Colors.white);
final descriptionStyle = theme.textTheme.subtitle1;

return Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down
4 changes: 2 additions & 2 deletions lib/demos/material/chip_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class _ActionChipDemo extends StatelessWidget {
return Center(
child: ActionChip(
onPressed: () {},
avatar: Icon(
avatar: const Icon(
Icons.brightness_5,
color: Colors.black54,
),
Expand Down Expand Up @@ -200,7 +200,7 @@ class _InputChipDemo extends StatelessWidget {
child: InputChip(
onPressed: () {},
onDeleted: () {},
avatar: Icon(
avatar: const Icon(
Icons.directions_bike,
size: 20,
color: Colors.black54,
Expand Down
19 changes: 10 additions & 9 deletions lib/demos/material/data_table_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ class _DataTableDemoState extends State<DataTableDemo> {
@override
void didChangeDependencies() {
super.didChangeDependencies();
if (_dessertsDataSource == null) {
_dessertsDataSource = _DessertDataSource(context);
}
_dessertsDataSource ??= _DessertDataSource(context);
}

void _sort<T>(
Comparable<T> getField(_Dessert d), int columnIndex, bool ascending) {
Comparable<T> Function(_Dessert d) getField,
int columnIndex,
bool ascending,
) {
_dessertsDataSource._sort<T>(getField, ascending);
setState(() {
_sortColumnIndex = columnIndex;
Expand Down Expand Up @@ -486,10 +487,10 @@ class _DessertDataSource extends DataTableSource {
final BuildContext context;
List<_Dessert> _desserts;

void _sort<T>(Comparable<T> getField(_Dessert d), bool ascending) {
void _sort<T>(Comparable<T> Function(_Dessert d) getField, bool ascending) {
_desserts.sort((a, b) {
final Comparable<T> aValue = getField(a);
final Comparable<T> bValue = getField(b);
final aValue = getField(a);
final bValue = getField(b);
return ascending
? Comparable.compare(aValue, bValue)
: Comparable.compare(bValue, aValue);
Expand All @@ -507,7 +508,7 @@ class _DessertDataSource extends DataTableSource {
);
assert(index >= 0);
if (index >= _desserts.length) return null;
final _Dessert dessert = _desserts[index];
final dessert = _desserts[index];
return DataRow.byIndex(
index: index,
selected: dessert.selected,
Expand Down Expand Up @@ -542,7 +543,7 @@ class _DessertDataSource extends DataTableSource {
int get selectedRowCount => _selectedCount;

void _selectAll(bool checked) {
for (final _Dessert dessert in _desserts) {
for (final dessert in _desserts) {
dessert.selected = checked;
}
_selectedCount = checked ? _desserts.length : 0;
Expand Down
14 changes: 7 additions & 7 deletions lib/demos/material/dialog_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class DialogDemo extends StatelessWidget {
child: child,
),
);
T value = await showDialog<T>(
final value = await showDialog<T>(
context: context,
builder: (context) => child,
);
Expand All @@ -58,8 +58,8 @@ class DialogDemo extends StatelessWidget {
}

void _showAlertDialog(BuildContext context) {
final ThemeData theme = Theme.of(context);
final TextStyle dialogTextStyle = theme.textTheme.subtitle1
final theme = Theme.of(context);
final dialogTextStyle = theme.textTheme.subtitle1
.copyWith(color: theme.textTheme.caption.color);
_showDemoDialog<String>(
context: context,
Expand All @@ -77,8 +77,8 @@ class DialogDemo extends StatelessWidget {
}

void _showAlertDialogWithTitle(BuildContext context) {
final ThemeData theme = Theme.of(context);
final TextStyle dialogTextStyle = theme.textTheme.subtitle1
final theme = Theme.of(context);
final dialogTextStyle = theme.textTheme.subtitle1
.copyWith(color: theme.textTheme.caption.color);
_showDemoDialog<String>(
context: context,
Expand All @@ -97,7 +97,7 @@ class DialogDemo extends StatelessWidget {
}

void _showSimpleDialog(BuildContext context) {
final ThemeData theme = Theme.of(context);
final theme = Theme.of(context);
_showDemoDialog<String>(
context: context,
child: SimpleDialog(
Expand Down Expand Up @@ -245,7 +245,7 @@ class _DialogDemoItem extends StatelessWidget {
class _FullScreenDialogDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
final theme = Theme.of(context);

// Remove the MediaQuery padding because the demo is rendered inside of a
// different page that already accounts for this padding.
Expand Down
8 changes: 4 additions & 4 deletions lib/demos/material/menu_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class _SectionedMenuDemo extends StatelessWidget {
PopupMenuItem<String>(
value: GalleryLocalizations.of(context).demoMenuPreview,
child: ListTile(
leading: Icon(Icons.visibility),
leading: const Icon(Icons.visibility),
title: Text(
GalleryLocalizations.of(context).demoMenuPreview,
),
Expand All @@ -159,7 +159,7 @@ class _SectionedMenuDemo extends StatelessWidget {
PopupMenuItem<String>(
value: GalleryLocalizations.of(context).demoMenuShare,
child: ListTile(
leading: Icon(Icons.person_add),
leading: const Icon(Icons.person_add),
title: Text(
GalleryLocalizations.of(context).demoMenuShare,
),
Expand All @@ -168,7 +168,7 @@ class _SectionedMenuDemo extends StatelessWidget {
PopupMenuItem<String>(
value: GalleryLocalizations.of(context).demoMenuGetLink,
child: ListTile(
leading: Icon(Icons.link),
leading: const Icon(Icons.link),
title: Text(
GalleryLocalizations.of(context).demoMenuGetLink,
),
Expand All @@ -178,7 +178,7 @@ class _SectionedMenuDemo extends StatelessWidget {
PopupMenuItem<String>(
value: GalleryLocalizations.of(context).demoMenuRemove,
child: ListTile(
leading: Icon(Icons.delete),
leading: const Icon(Icons.delete),
title: Text(
GalleryLocalizations.of(context).demoMenuRemove,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/demos/material/picker_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class _PickerDemoState extends State<PickerDemo> {
}

Future<void> _showTimePicker() async {
final TimeOfDay picked = await showTimePicker(
final picked = await showTimePicker(
context: context,
initialTime: _fromTime,
);
Expand Down
4 changes: 2 additions & 2 deletions lib/demos/material/sliders_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class _SlidersState extends State<_Sliders> {
child: TextField(
textAlign: TextAlign.center,
onSubmitted: (value) {
final double newValue = double.tryParse(value);
final newValue = double.tryParse(value);
if (newValue != null && newValue != _continuousValue) {
setState(() {
_continuousValue = newValue.clamp(0, 100) as double;
Expand Down Expand Up @@ -260,7 +260,7 @@ class _CustomSlidersState extends State<_CustomSliders> {
mainAxisSize: MainAxisSize.min,
children: [
SliderTheme(
data: SliderThemeData(
data: const SliderThemeData(
activeTrackColor: Colors.deepPurple,
inactiveTrackColor: Colors.black26,
activeTickMarkColor: Colors.white70,
Expand Down
4 changes: 2 additions & 2 deletions lib/demos/material/tabs_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TabsDemo extends StatelessWidget {
class _TabsScrollableDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
List<String> tabs = [
final tabs = [
GalleryLocalizations.of(context).colorsRed,
GalleryLocalizations.of(context).colorsOrange,
GalleryLocalizations.of(context).colorsGreen,
Expand Down Expand Up @@ -82,7 +82,7 @@ class _TabsScrollableDemo extends StatelessWidget {
class _TabsNonScrollableDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
List<String> tabs = [
final tabs = [
GalleryLocalizations.of(context).colorsRed,
GalleryLocalizations.of(context).colorsOrange,
GalleryLocalizations.of(context).colorsGreen,
Expand Down
10 changes: 5 additions & 5 deletions lib/demos/material/text_field_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
cursorColor: cursorColor,
decoration: InputDecoration(
filled: true,
icon: Icon(Icons.person),
icon: const Icon(Icons.person),
hintText: GalleryLocalizations.of(context)
.demoTextFieldWhatDoPeopleCallYou,
labelText:
Expand All @@ -206,7 +206,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
cursorColor: cursorColor,
decoration: InputDecoration(
filled: true,
icon: Icon(Icons.phone),
icon: const Icon(Icons.phone),
hintText: GalleryLocalizations.of(context)
.demoTextFieldWhereCanWeReachYou,
labelText: GalleryLocalizations.of(context)
Expand All @@ -232,7 +232,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
cursorColor: cursorColor,
decoration: InputDecoration(
filled: true,
icon: Icon(Icons.email),
icon: const Icon(Icons.email),
hintText: GalleryLocalizations.of(context)
.demoTextFieldYourEmailAddress,
labelText:
Expand Down Expand Up @@ -327,8 +327,8 @@ class _UsNumberTextInputFormatter extends TextInputFormatter {
) {
final newTextLength = newValue.text.length;
final newText = StringBuffer();
int selectionIndex = newValue.selection.end;
int usedSubstringIndex = 0;
var selectionIndex = newValue.selection.end;
var usedSubstringIndex = 0;
if (newTextLength >= 1) {
newText.write('(');
if (newValue.selection.end >= 1) selectionIndex++;
Expand Down
Loading

0 comments on commit 25561df

Please sign in to comment.