Skip to content

Commit 1e29b19

Browse files
committed
Apply pedantic analysis options to all examples and run it on CI
1 parent 70de05f commit 1e29b19

File tree

198 files changed

+1142
-1074
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+1142
-1074
lines changed

analysis_options.yaml

+51-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,56 @@
1-
analyzer:
2-
# exclude:
3-
# - path/to/excluded/files/**
1+
# Pedantic 1.9.0
2+
#
3+
# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
4+
# for details. All rights reserved. Use of this source code is governed by a
5+
# BSD-style license that can be found in the LICENSE file.
6+
#
7+
# Google internally enforced rules. See README.md for more information,
8+
# including a list of lints that are intentionally _not_ enforced.
49

5-
# Lint rules and documentation, see http://dart-lang.github.io/linter/lints
610
linter:
711
rules:
8-
- cancel_subscriptions
9-
- close_sinks
10-
- hash_and_equals
11-
- iterable_contains_unrelated_type
12-
- list_remove_unrelated_type
13-
- test_types_in_equals
12+
- always_declare_return_types
13+
- always_require_non_null_named_parameters
14+
- annotate_overrides
15+
- avoid_empty_else
16+
- avoid_init_to_null
17+
- avoid_null_checks_in_equality_operators
18+
- avoid_relative_lib_imports
19+
- avoid_return_types_on_setters
20+
- avoid_shadowing_type_parameters
21+
- avoid_types_as_parameter_names
22+
- camel_case_extensions
23+
- curly_braces_in_flow_control_structures
24+
- empty_catches
25+
- empty_constructor_bodies
26+
- library_names
27+
- library_prefixes
28+
- no_duplicate_case_values
29+
- null_closures
30+
- omit_local_variable_types
31+
- prefer_adjacent_string_concatenation
32+
- prefer_collection_literals
33+
- prefer_conditional_assignment
34+
- prefer_contains
35+
- prefer_equal_for_default_values
36+
- prefer_final_fields
37+
- prefer_for_elements_to_map_fromIterable
38+
- prefer_generic_function_type_aliases
39+
- prefer_if_null_operators
40+
- prefer_is_empty
41+
- prefer_is_not_empty
42+
- prefer_iterable_whereType
43+
- prefer_single_quotes
44+
- prefer_spread_collections
45+
- recursive_getters
46+
- slash_for_doc_comments
47+
- type_init_formals
48+
- unawaited_futures
49+
- unnecessary_const
50+
- unnecessary_new
51+
- unnecessary_null_in_if_null_operators
52+
- unnecessary_this
1453
- unrelated_type_equality_checks
54+
- use_function_type_syntax_for_parameters
55+
- use_rethrow_when_possible
1556
- valid_regexps

bloc_flutter/lib/localization.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class BlocLocalizations {
1111
return Localizations.of<BlocLocalizations>(context, BlocLocalizations);
1212
}
1313

14-
String get appTitle => "Bloc Example";
14+
String get appTitle => 'Bloc Example';
1515
}
1616

1717
class InheritedWidgetLocalizationsDelegate
@@ -25,5 +25,5 @@ class InheritedWidgetLocalizationsDelegate
2525

2626
@override
2727
bool isSupported(Locale locale) =>
28-
locale.languageCode.toLowerCase().contains("en");
28+
locale.languageCode.toLowerCase().contains('en');
2929
}

bloc_flutter/lib/widgets/stats_counter.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class StatsCounterState extends State<StatsCounter> {
6666
stream: bloc.numActive,
6767
builder: (context, snapshot) {
6868
return Text(
69-
"${snapshot.data ?? 0}",
69+
'${snapshot.data ?? 0}',
7070
key: ArchSampleKeys.statsNumActive,
7171
style: Theme.of(context).textTheme.subhead,
7272
);

bloc_flutter/test_driver/todo_app_test.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by the MIT license that can be found
33
// in the LICENSE file.
44

5-
import 'package:integration_tests/integration_tests.dart' as integrationTests;
5+
import 'package:integration_tests/integration_tests.dart' as integration_tests;
66

7-
main() {
8-
integrationTests.main();
7+
void main() {
8+
integration_tests.main();
99
}

bloc_library/lib/blocs/stats/stats_bloc.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class StatsBloc extends Bloc<StatsEvent, StatsState> {
2121
@override
2222
Stream<StatsState> mapEventToState(StatsEvent event) async* {
2323
if (event is UpdateStats) {
24-
int numActive =
24+
var numActive =
2525
event.todos.where((todo) => !todo.complete).toList().length;
26-
int numCompleted =
26+
var numCompleted =
2727
event.todos.where((todo) => todo.complete).toList().length;
2828
yield StatsLoaded(numActive, numCompleted);
2929
}

bloc_library/lib/blocs/todos/todos_bloc.dart

+10-10
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class TodosBloc extends Bloc<TodosEvent, TodosState> {
3737

3838
Stream<TodosState> _mapLoadTodosToState() async* {
3939
try {
40-
final todos = await this.todosRepository.loadTodos();
40+
final todos = await todosRepository.loadTodos();
4141
yield TodosLoaded(
4242
todos.map(Todo.fromEntity).toList(),
4343
);
@@ -48,20 +48,20 @@ class TodosBloc extends Bloc<TodosEvent, TodosState> {
4848

4949
Stream<TodosState> _mapAddTodoToState(AddTodo event) async* {
5050
if (state is TodosLoaded) {
51-
final List<Todo> updatedTodos = List.from((state as TodosLoaded).todos)
51+
final updatedTodos = List<Todo>.from((state as TodosLoaded).todos)
5252
..add(event.todo);
5353
yield TodosLoaded(updatedTodos);
54-
_saveTodos(updatedTodos);
54+
await _saveTodos(updatedTodos);
5555
}
5656
}
5757

5858
Stream<TodosState> _mapUpdateTodoToState(UpdateTodo event) async* {
5959
if (state is TodosLoaded) {
60-
final List<Todo> updatedTodos = (state as TodosLoaded).todos.map((todo) {
60+
final updatedTodos = (state as TodosLoaded).todos.map((todo) {
6161
return todo.id == event.updatedTodo.id ? event.updatedTodo : todo;
6262
}).toList();
6363
yield TodosLoaded(updatedTodos);
64-
_saveTodos(updatedTodos);
64+
await _saveTodos(updatedTodos);
6565
}
6666
}
6767

@@ -72,29 +72,29 @@ class TodosBloc extends Bloc<TodosEvent, TodosState> {
7272
.where((todo) => todo.id != event.todo.id)
7373
.toList();
7474
yield TodosLoaded(updatedTodos);
75-
_saveTodos(updatedTodos);
75+
await _saveTodos(updatedTodos);
7676
}
7777
}
7878

7979
Stream<TodosState> _mapToggleAllToState() async* {
8080
if (state is TodosLoaded) {
8181
final allComplete =
8282
(state as TodosLoaded).todos.every((todo) => todo.complete);
83-
final List<Todo> updatedTodos = (state as TodosLoaded)
83+
final updatedTodos = (state as TodosLoaded)
8484
.todos
8585
.map((todo) => todo.copyWith(complete: !allComplete))
8686
.toList();
8787
yield TodosLoaded(updatedTodos);
88-
_saveTodos(updatedTodos);
88+
await _saveTodos(updatedTodos);
8989
}
9090
}
9191

9292
Stream<TodosState> _mapClearCompletedToState() async* {
9393
if (state is TodosLoaded) {
94-
final List<Todo> updatedTodos =
94+
final updatedTodos =
9595
(state as TodosLoaded).todos.where((todo) => !todo.complete).toList();
9696
yield TodosLoaded(updatedTodos);
97-
_saveTodos(updatedTodos);
97+
await _saveTodos(updatedTodos);
9898
}
9999
}
100100

bloc_library/lib/localization.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class FlutterBlocLocalizations {
1414
);
1515
}
1616

17-
String get appTitle => "Bloc Library Example";
17+
String get appTitle => 'Bloc Library Example';
1818
}
1919

2020
class FlutterBlocLocalizationsDelegate
@@ -28,5 +28,5 @@ class FlutterBlocLocalizationsDelegate
2828

2929
@override
3030
bool isSupported(Locale locale) =>
31-
locale.languageCode.toLowerCase().contains("en");
31+
locale.languageCode.toLowerCase().contains('en');
3232
}

bloc_library/lib/main.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void main() {
2323
create: (context) {
2424
return TodosBloc(
2525
todosRepository: const TodosRepositoryFlutter(
26-
fileStorage: const FileStorage(
26+
fileStorage: FileStorage(
2727
'__flutter_bloc_app__',
2828
getApplicationDocumentsDirectory,
2929
),

bloc_library/lib/models/todo.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class Todo {
1414
final String task;
1515

1616
Todo(this.task, {this.complete = false, String note = '', String id})
17-
: this.note = note ?? '',
18-
this.id = id ?? Uuid().generateV4();
17+
: note = note ?? '',
18+
id = id ?? Uuid().generateV4();
1919

2020
Todo copyWith({bool complete, String id, String note, String task}) {
2121
return Todo(

bloc_library/lib/screens/add_edit_screen.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:flutter/material.dart';
77
import 'package:todos_app_core/todos_app_core.dart';
88
import 'package:bloc_library/models/models.dart';
99

10-
typedef OnSaveCallback = Function(String task, String note);
10+
typedef OnSaveCallback = void Function(String task, String note);
1111

1212
class AddEditScreen extends StatefulWidget {
1313
final bool isEditing;

bloc_library/lib/widgets/extra_actions.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ExtraActions extends StatelessWidget {
2121
bloc: todosBloc,
2222
builder: (BuildContext context, TodosState state) {
2323
if (state is TodosLoaded) {
24-
bool allComplete = (todosBloc.state as TodosLoaded)
24+
final allComplete = (todosBloc.state as TodosLoaded)
2525
.todos
2626
.every((todo) => todo.complete);
2727
return PopupMenuButton<ExtraAction>(

bloc_library/lib/widgets/filter_button.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ class FilterButton extends StatelessWidget {
2020
.textTheme
2121
.body1
2222
.copyWith(color: Theme.of(context).accentColor);
23-
final FilteredTodosBloc filteredTodosBloc =
24-
BlocProvider.of<FilteredTodosBloc>(context);
23+
final filteredTodosBloc = BlocProvider.of<FilteredTodosBloc>(context);
2524
return BlocBuilder(
2625
bloc: filteredTodosBloc,
2726
builder: (BuildContext context, FilteredTodosState state) {

bloc_library/lib/widgets/stats.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Stats extends StatelessWidget {
1616

1717
@override
1818
Widget build(BuildContext context) {
19-
final StatsBloc statsBloc = BlocProvider.of<StatsBloc>(context);
19+
final statsBloc = BlocProvider.of<StatsBloc>(context);
2020
return BlocBuilder(
2121
bloc: statsBloc,
2222
builder: (BuildContext context, StatsState state) {
@@ -52,7 +52,7 @@ class Stats extends StatelessWidget {
5252
Padding(
5353
padding: EdgeInsets.only(bottom: 24.0),
5454
child: Text(
55-
"${state.numActive}",
55+
'${state.numActive}',
5656
key: ArchSampleKeys.statsNumActive,
5757
style: Theme.of(context).textTheme.subhead,
5858
),

bloc_library/test/all_tests.dart

+50-50
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
1-
// Copyright 2018 The Flutter Architecture Sample Authors. All rights reserved.
2-
// Use of this source code is governed by the MIT license that can be found
3-
// in the LICENSE file.
4-
5-
import './blocs/filtered_todos_bloc_test.dart' as filteredTodosBloc;
6-
import './blocs/filtered_todos_event_test.dart' as filteredTodosEvent;
7-
import './blocs/simple_bloc_delegate_test.dart' as simpleBlocDelegate;
8-
import './blocs/tab_bloc_test.dart' as tabBloc;
9-
import './blocs/tab_event_test.dart' as tabEvent;
10-
import './blocs/todos_bloc_test.dart' as todosBloc;
11-
import './blocs/todos_event_test.dart' as todosEvent;
12-
import './blocs/todos_state_test.dart' as todosState;
1+
// _copyright 2018 _the _flutter _architecture _sample _authors. _all rights reserved.
2+
// _use of this source code is governed by the _m_i_t license that can be found
3+
// in the _l_i_c_e_n_s_e file.
4+
5+
import './blocs/filtered_todos_bloc_test.dart' as filtered_todos_bloc;
6+
import './blocs/filtered_todos_event_test.dart' as filtered_todos_event;
7+
import './blocs/simple_bloc_delegate_test.dart' as simple_bloc_delegate;
8+
import './blocs/tab_bloc_test.dart' as tab_bloc;
9+
import './blocs/tab_event_test.dart' as tab_event;
10+
import './blocs/todos_bloc_test.dart' as todos_bloc;
11+
import './blocs/todos_event_test.dart' as todos_event;
12+
import './blocs/todos_state_test.dart' as todos_state;
1313

1414
import './models/todo_test.dart' as todo;
1515

16-
import './screens//add_edit_screen_test.dart' as addEditScreen;
17-
import './screens/details_screen_test.dart' as detailsScreen;
18-
import './screens/home_screen_test.dart' as homeScreen;
16+
import './screens//add_edit_screen_test.dart' as add_edit_screen;
17+
import './screens/details_screen_test.dart' as details_screen;
18+
import './screens/home_screen_test.dart' as home_screen;
1919

20-
import './widgets/delete_todo_snack_bar_test.dart' as deleteTodoSnackbar;
21-
import './widgets/extra_actions_test.dart' as extraActions;
22-
import './widgets/filter_button_test.dart' as filterButton;
23-
import './widgets/filtered_todos_test.dart' as filteredTodos;
24-
import './widgets/loading_indicator_test.dart' as loadingIndicator;
25-
import './widgets/stats_tab_test.dart' as statsTab;
26-
import './widgets/tab_selector_test.dart' as tabSelector;
27-
import './widgets/todo_item_test.dart' as todoItem;
20+
import './widgets/delete_todo_snack_bar_test.dart' as delete_todo_snackbar;
21+
import './widgets/extra_actions_test.dart' as extra_actions;
22+
import './widgets/filter_button_test.dart' as filter_button;
23+
import './widgets/filtered_todos_test.dart' as filtered_todos;
24+
import './widgets/loading_indicator_test.dart' as loading_indicator;
25+
import './widgets/stats_tab_test.dart' as stats_tab;
26+
import './widgets/tab_selector_test.dart' as tab_selector;
27+
import './widgets/todo_item_test.dart' as todo_item;
2828

2929
import './localization_test.dart' as localization;
3030

3131
void main() {
32-
// Blocs
33-
filteredTodosBloc.main();
34-
filteredTodosEvent.main();
35-
simpleBlocDelegate.main();
36-
tabBloc.main();
37-
tabEvent.main();
38-
todosBloc.main();
39-
todosEvent.main();
40-
todosState.main();
41-
42-
// Models
32+
// _blocs
33+
filtered_todos_bloc.main();
34+
filtered_todos_event.main();
35+
simple_bloc_delegate.main();
36+
tab_bloc.main();
37+
tab_event.main();
38+
todos_bloc.main();
39+
todos_event.main();
40+
todos_state.main();
41+
42+
// _models
4343
todo.main();
4444

45-
// Screens
46-
addEditScreen.main();
47-
detailsScreen.main();
48-
homeScreen.main();
49-
50-
// Widgets
51-
deleteTodoSnackbar.main();
52-
extraActions.main();
53-
filterButton.main();
54-
filteredTodos.main();
55-
loadingIndicator.main();
56-
statsTab.main();
57-
tabSelector.main();
58-
todoItem.main();
59-
60-
// Localization
45+
// _screens
46+
add_edit_screen.main();
47+
details_screen.main();
48+
home_screen.main();
49+
50+
// _widgets
51+
delete_todo_snackbar.main();
52+
extra_actions.main();
53+
filter_button.main();
54+
filtered_todos.main();
55+
loading_indicator.main();
56+
stats_tab.main();
57+
tab_selector.main();
58+
todo_item.main();
59+
60+
// _localization
6161
localization.main();
6262
}

bloc_library/test/blocs/simple_bloc_delegate_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void main() {
5151
});
5252
}
5353

54-
dynamic overridePrint(dynamic testFn()) => () {
54+
dynamic overridePrint(dynamic Function() testFn) => () {
5555
var spec = ZoneSpecification(print: (_, __, ___, String msg) {
5656
// Add to log instead of printing to stdout
5757
printLog.add(msg);

bloc_library/test/blocs/stats_bloc_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class MockTodosBloc extends MockBloc<TodosEvent, TodosState>
1515

1616
void main() {
1717
group('StatsBloc', () {
18-
final todo1 = Todo("Hallo");
19-
final todo2 = Todo("Hallo2", complete: true);
18+
final todo1 = Todo('Hallo');
19+
final todo2 = Todo('Hallo2', complete: true);
2020
TodosBloc todosBloc;
2121
StatsBloc statsBloc;
2222

0 commit comments

Comments
 (0)