Skip to content

Commit 1e21e2d

Browse files
authored
All public members have documentation, enforced by lint and dartfmt check on CI
* Add pedantic rules, enforce public_member_api_docs, fix examples * revert to last known working travis version * Ensure build fails if docs missing * Fix analyze step * Fail build if formatting errors are present * One more time * Fix analyzer issues!? * Add example pubspec * Check dartfmt fails builds * Fix formatting to verify everything works
1 parent 766416c commit 1e21e2d

27 files changed

+437
-501
lines changed

.gitlab-ci.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ sudo: false
44
before_script:
55
- git clone https://github.com/flutter/flutter.git -b stable --depth 1
66
- ./flutter/bin/flutter doctor
7+
- ./flutter/bin/flutter packages get
78
script:
9+
- ./flutter/bin/flutter analyze --no-current-package --dartdocs $TRAVIS_BUILD_DIR/lib
10+
- ./flutter/bin/cache/dart-sdk/bin/dartfmt -n ./lib --set-exit-if-changed
811
- ./flutter/bin/flutter test --coverage --coverage-path=lcov.info
912
after_success:
1013
- bash <(curl -s https://codecov.io/bash)
1114
cache:
1215
directories:
1316
- $HOME/.pub-cache
17+

analysis_options.yaml

Lines changed: 3 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,10 @@
1+
include: package:pedantic/analysis_options.yaml
2+
13
analyzer:
24
strong-mode:
35
implicit-casts: false
46
implicit-dynamic: false
7+
58
linter:
69
rules:
710
- public_member_api_docs
8-
- annotate_overrides
9-
- avoid_empty_else
10-
- avoid_function_literals_in_foreach_calls
11-
- avoid_init_to_null
12-
- avoid_null_checks_in_equality_operators
13-
- avoid_relative_lib_imports
14-
- avoid_renaming_method_parameters
15-
- avoid_return_types_on_setters
16-
- avoid_returning_null
17-
- avoid_types_as_parameter_names
18-
- avoid_unused_constructor_parameters
19-
- await_only_futures
20-
- camel_case_types
21-
- cancel_subscriptions
22-
- cascade_invocations
23-
- comment_references
24-
- constant_identifier_names
25-
- control_flow_in_finally
26-
- directives_ordering
27-
- empty_catches
28-
- empty_constructor_bodies
29-
- empty_statements
30-
- hash_and_equals
31-
- implementation_imports
32-
- invariant_booleans
33-
- iterable_contains_unrelated_type
34-
- library_names
35-
- library_prefixes
36-
- list_remove_unrelated_type
37-
- no_adjacent_strings_in_list
38-
- no_duplicate_case_values
39-
- non_constant_identifier_names
40-
- null_closures
41-
- omit_local_variable_types
42-
- only_throw_errors
43-
- overridden_fields
44-
- package_api_docs
45-
- package_names
46-
- package_prefixed_library_names
47-
- prefer_adjacent_string_concatenation
48-
- prefer_collection_literals
49-
- prefer_conditional_assignment
50-
- prefer_const_constructors
51-
- prefer_contains
52-
- prefer_equal_for_default_values
53-
- prefer_final_fields
54-
- prefer_initializing_formals
55-
- prefer_interpolation_to_compose_strings
56-
- prefer_is_empty
57-
- prefer_is_not_empty
58-
- prefer_single_quotes
59-
- prefer_typing_uninitialized_variables
60-
- recursive_getters
61-
- slash_for_doc_comments
62-
- super_goes_last
63-
- test_types_in_equals
64-
- throw_in_finally
65-
- type_init_formals
66-
- unawaited_futures
67-
- unnecessary_brace_in_string_interps
68-
- unnecessary_const
69-
- unnecessary_getters_setters
70-
- unnecessary_lambdas
71-
- unnecessary_new
72-
- unnecessary_null_aware_assignments
73-
- unnecessary_statements
74-
- unnecessary_this
75-
- unrelated_type_equality_checks
76-
- use_rethrow_when_possible
77-
- valid_regexps
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:pedantic/analysis_options.yaml

example/counter/lib/main.dart

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ int counterReducer(int state, dynamic action) {
1616
}
1717

1818
void main() {
19-
// Create your store as a final variable in a base Widget. This works better
20-
// with Hot Reload than creating it directly in the `build` function.
21-
final store = new Store<int>(counterReducer, initialState: 0);
19+
// Create your store as a final variable in the main function or inside a
20+
// State object. This works better with Hot Reload than creating it directly
21+
// in the `build` function.
22+
final store = Store<int>(counterReducer, initialState: 0);
2223

23-
runApp(new FlutterReduxApp(
24+
runApp(FlutterReduxApp(
2425
title: 'Flutter Redux Demo',
2526
store: store,
2627
));
@@ -36,22 +37,22 @@ class FlutterReduxApp extends StatelessWidget {
3637
Widget build(BuildContext context) {
3738
// The StoreProvider should wrap your MaterialApp or WidgetsApp. This will
3839
// ensure all routes have access to the store.
39-
return new StoreProvider<int>(
40+
return StoreProvider<int>(
4041
// Pass the store to the StoreProvider. Any ancestor `StoreConnector`
4142
// Widgets will find and use this value as the `Store`.
4243
store: store,
43-
child: new MaterialApp(
44-
theme: new ThemeData.dark(),
44+
child: MaterialApp(
45+
theme: ThemeData.dark(),
4546
title: title,
46-
home: new Scaffold(
47-
appBar: new AppBar(
48-
title: new Text(title),
47+
home: Scaffold(
48+
appBar: AppBar(
49+
title: Text(title),
4950
),
50-
body: new Center(
51-
child: new Column(
51+
body: Center(
52+
child: Column(
5253
mainAxisAlignment: MainAxisAlignment.center,
5354
children: [
54-
new Text(
55+
Text(
5556
'You have pushed the button this many times:',
5657
),
5758
// Connect the Store to a Text Widget that renders the current
@@ -67,10 +68,10 @@ class FlutterReduxApp extends StatelessWidget {
6768
// run through the reducer. After the reducer updates the state,
6869
// the Widget will be automatically rebuilt with the latest
6970
// count. No need to manually manage subscriptions or Streams!
70-
new StoreConnector<int, String>(
71+
StoreConnector<int, String>(
7172
converter: (store) => store.state.toString(),
7273
builder: (context, count) {
73-
return new Text(
74+
return Text(
7475
count,
7576
style: Theme.of(context).textTheme.display1,
7677
);
@@ -84,18 +85,18 @@ class FlutterReduxApp extends StatelessWidget {
8485
// Action.
8586
//
8687
// Then, we'll pass this callback to the button's `onPressed` handler.
87-
floatingActionButton: new StoreConnector<int, VoidCallback>(
88+
floatingActionButton: StoreConnector<int, VoidCallback>(
8889
converter: (store) {
8990
// Return a `VoidCallback`, which is a fancy name for a function
9091
// with no parameters. It only dispatches an Increment action.
9192
return () => store.dispatch(Actions.Increment);
9293
},
9394
builder: (context, callback) {
94-
return new FloatingActionButton(
95+
return FloatingActionButton(
9596
// Attach the `callback` to the `onPressed` attribute
9697
onPressed: callback,
9798
tooltip: 'asdasdasd',
98-
child: new Icon(Icons.add),
99+
child: Icon(Icons.add),
99100
);
100101
},
101102
),

example/counter/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dev_dependencies:
1010
path: ../../
1111
flutter_test:
1212
sdk: flutter
13+
pedantic: ^1.8.0+1
1314

1415
# For information on the generic Dart part of this file, see the
1516
# following page: https://www.dartlang.org/tools/pub/pubspec
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
analyzer:
1+
include: package:pedantic/analysis_options.yaml

example/github_search/lib/empty_result_widget.dart

Lines changed: 0 additions & 35 deletions
This file was deleted.

example/github_search/lib/github_search_api.dart renamed to example/github_search/lib/github_client.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ import 'dart:async';
22
import 'dart:convert';
33
import 'dart:io';
44

5-
class GithubApi {
5+
class GithubClient {
66
final String baseUrl;
77
final Map<String, SearchResult> cache;
88
final HttpClient client;
99

10-
GithubApi({
10+
GithubClient({
1111
HttpClient client,
1212
Map<String, SearchResult> cache,
1313
this.baseUrl = "https://api.github.com/search/repositories?q=",
14-
}) : this.client = client ?? new HttpClient(),
14+
}) : this.client = client ?? HttpClient(),
1515
this.cache = cache ?? <String, SearchResult>{};
1616

1717
/// Search Github for repositories using the given term
1818
Future<SearchResult> search(String term) async {
1919
if (term.isEmpty) {
20-
return new SearchResult.noTerm();
20+
return SearchResult.noTerm();
2121
} else if (cache.containsKey(term)) {
2222
return cache[term];
2323
} else {
@@ -30,11 +30,11 @@ class GithubApi {
3030
}
3131

3232
Future<SearchResult> _fetchResults(String term) async {
33-
final request = await new HttpClient().getUrl(Uri.parse("$baseUrl$term"));
33+
final request = await HttpClient().getUrl(Uri.parse("$baseUrl$term"));
3434
final response = await request.close();
3535
final results = json.decode(await response.transform(utf8.decoder).join());
3636

37-
return new SearchResult.fromJson(results['items']);
37+
return SearchResult.fromJson(results['items']);
3838
}
3939
}
4040

@@ -47,16 +47,16 @@ class SearchResult {
4747
SearchResult(this.kind, this.items);
4848

4949
factory SearchResult.noTerm() =>
50-
new SearchResult(SearchResultKind.noTerm, <SearchResultItem>[]);
50+
SearchResult(SearchResultKind.noTerm, <SearchResultItem>[]);
5151

5252
factory SearchResult.fromJson(dynamic json) {
5353
final items = (json as List)
5454
.cast<Map<String, Object>>()
5555
.map((Map<String, Object> item) {
56-
return new SearchResultItem.fromJson(item);
56+
return SearchResultItem.fromJson(item);
5757
}).toList();
5858

59-
return new SearchResult(
59+
return SearchResult(
6060
items.isEmpty ? SearchResultKind.empty : SearchResultKind.populated,
6161
items,
6262
);
@@ -77,7 +77,7 @@ class SearchResultItem {
7777
SearchResultItem(this.fullName, this.url, this.avatarUrl);
7878

7979
factory SearchResultItem.fromJson(Map<String, Object> json) {
80-
return new SearchResultItem(
80+
return SearchResultItem(
8181
json['full_name'] as String,
8282
json["html_url"] as String,
8383
(json["owner"] as Map<String, Object>)["avatar_url"] as String,

0 commit comments

Comments
 (0)