Visitar URL original
[use] flutter_lints · austinstoker/packages@080d387 · GitHub
Skip to content

Commit 080d387

Browse files
committed
[use] flutter_lints
- closes flutter#334
1 parent 359ace1 commit 080d387

20 files changed

Lines changed: 127 additions & 146 deletions

‎README.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<a href="https://codecov.io/gh/slovnicki/beamer">
88
<img src="https://codecov.io/gh/slovnicki/beamer/branch/master/graph/badge.svg?token=TO09CQU09C"/>
99
</a>
10-
<a href="https://github.com/google/pedantic"><img src="https://dart-lang.github.io/linter/lints/style-pedantic.svg" alt="style"></a>
1110
</p>
1211

1312
<p align="center">

‎package/README.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<a href="https://codecov.io/gh/slovnicki/beamer">
88
<img src="https://codecov.io/gh/slovnicki/beamer/branch/master/graph/badge.svg?token=TO09CQU09C"/>
99
</a>
10-
<a href="https://github.com/google/pedantic"><img src="https://dart-lang.github.io/linter/lints/style-pedantic.svg" alt="style"></a>
1110
</p>
1211

1312
<p align="center">

‎package/analysis_options.yaml‎

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,28 @@
1-
# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2-
# for details. All rights reserved. Use of this source code is governed by a
3-
# BSD-style license that can be found in the LICENSE file.
1+
# This file configures the analyzer, which statically analyzes Dart code to
2+
# check for errors, warnings, and lints.
43
#
5-
# Google internally enforced rules. See README.md for more information,
6-
# including a list of lints that are intentionally _not_ enforced.
7-
#
8-
# https://github.com/google/pedantic
4+
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5+
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6+
# invoked from the command line by running `flutter analyze`.
7+
8+
# The following line activates a set of recommended lints for Flutter apps,
9+
# packages, and plugins designed to encourage good coding practices.
10+
include: package:flutter_lints/flutter.yaml
911

1012
linter:
13+
# The lint rules applied to this project can be customized in the
14+
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
15+
# included above or to enable additional rules. A list of all available lints
16+
# and their documentation is published at
17+
# https://dart-lang.github.io/linter/lints/index.html.
18+
#
19+
# Instead of disabling a lint rule for the entire project in the
20+
# section below, it can also be suppressed for a single line of code
21+
# or a specific dart file by using the `// ignore: name_of_lint` and
22+
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
23+
# producing the lint.
1124
rules:
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
53-
- unrelated_type_equality_checks
54-
- use_function_type_syntax_for_parameters
55-
- use_rethrow_when_possible
56-
- valid_regexps
25+
# avoid_print: false # Uncomment to disable the `avoid_print` rule
26+
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
27+
# Additional information about this file can be found at
28+
# https://dart.dev/guides/language/analysis-options

‎package/example/lib/main.dart‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,32 @@ const List<Map<String, String>> books = [
2222

2323
// SCREENS
2424
class HomeScreen extends StatelessWidget {
25+
const HomeScreen({Key? key}) : super(key: key);
26+
2527
@override
2628
Widget build(BuildContext context) {
2729
return Scaffold(
2830
appBar: AppBar(
29-
title: Text('Home Screen'),
31+
title: const Text('Home Screen'),
3032
),
3133
body: Center(
3234
child: ElevatedButton(
3335
onPressed: () => context.beamToNamed('/books'),
34-
child: Text('See books'),
36+
child: const Text('See books'),
3537
),
3638
),
3739
);
3840
}
3941
}
4042

4143
class BooksScreen extends StatelessWidget {
44+
const BooksScreen({Key? key}) : super(key: key);
45+
4246
@override
4347
Widget build(BuildContext context) {
4448
return Scaffold(
4549
appBar: AppBar(
46-
title: Text('Books'),
50+
title: const Text('Books'),
4751
),
4852
body: ListView(
4953
children: books
@@ -61,7 +65,9 @@ class BooksScreen extends StatelessWidget {
6165
}
6266

6367
class BookDetailsScreen extends StatelessWidget {
64-
const BookDetailsScreen(this.bookDetails);
68+
const BookDetailsScreen({Key? key, required this.bookDetails})
69+
: super(key: key);
70+
6571
final Map<String, String> bookDetails;
6672

6773
@override
@@ -87,20 +93,20 @@ class BooksLocation extends BeamLocation {
8793

8894
@override
8995
List<BeamPage> buildPages(BuildContext context, BeamState state) => [
90-
BeamPage(
96+
const BeamPage(
9197
key: ValueKey('home'),
9298
child: HomeScreen(),
9399
),
94100
if (state.uri.pathSegments.contains('books'))
95-
BeamPage(
101+
const BeamPage(
96102
key: ValueKey('books'),
97103
child: BooksScreen(),
98104
),
99105
if (state.pathParameters.containsKey('bookId'))
100106
BeamPage(
101107
key: ValueKey('book-${state.pathParameters['bookId']}'),
102108
child: BookDetailsScreen(
103-
books.firstWhere(
109+
bookDetails: books.firstWhere(
104110
(book) => book['id'] == state.pathParameters['bookId']!),
105111
),
106112
),
@@ -109,6 +115,8 @@ class BooksLocation extends BeamLocation {
109115

110116
// APP
111117
class MyApp extends StatelessWidget {
118+
MyApp({Key? key}) : super(key: key);
119+
112120
final routerDelegate = BeamerDelegate(
113121
locationBuilder: (state) => BooksLocation(state),
114122
);

‎package/example/pubspec.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies:
1717
cupertino_icons: ^1.0.2
1818

1919
dev_dependencies:
20+
flutter_lints: ^1.0.4
2021
flutter_test:
2122
sdk: flutter
2223

‎package/lib/src/beam_guard.dart‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import './beam_page.dart';
1010
/// If neither [beamTo], [beamToNamed] nor [showPage] is specified,
1111
/// the guard will just block navigation, i.e. nothing will happen.
1212
class BeamGuard {
13-
BeamGuard({
13+
const BeamGuard({
1414
required this.pathBlueprints,
1515
required this.check,
1616
this.onCheckFailed,
@@ -38,39 +38,40 @@ class BeamGuard {
3838
/// For example, `RegExp('/books/')` will match '/books/1', '/books/2/genres', etc.
3939
/// but will not match '/books'. To match '/books' and everything after it,
4040
/// use `RegExp('/books')`
41-
List<dynamic> pathBlueprints;
41+
final List<dynamic> pathBlueprints;
4242

4343
/// What check should be performed on a given [location],
4444
/// the one to which beaming has been requested.
4545
///
4646
/// [context] is also injected to fetch data up the tree if necessary.
47-
bool Function(BuildContext context, BeamLocation location) check;
47+
final bool Function(BuildContext context, BeamLocation location) check;
4848

4949
/// Arbitrary closure to execute when [check] fails.
5050
///
5151
/// This will run before and regardless of [beamTo], [beamToNamed], [showPage].
52-
void Function(BuildContext context, BeamLocation location)? onCheckFailed;
52+
final void Function(BuildContext context, BeamLocation location)?
53+
onCheckFailed;
5354

5455
/// If guard [check] returns `false`, build a [BeamLocation] to be beamed to.
5556
///
5657
/// [showPage] has precedence over this attribute.
57-
BeamLocation Function(BuildContext context)? beamTo;
58+
final BeamLocation Function(BuildContext context)? beamTo;
5859

5960
/// If guard [check] returns `false`, beam to this URI string.
6061
///
6162
/// [showPage] has precedence over this attribute.
62-
String? beamToNamed;
63+
final String? beamToNamed;
6364

6465
/// If guard [check] returns `false`, put this page onto navigation stack.
6566
///
6667
/// This has precedence over [beamTo] and [beamToNamed].
67-
BeamPage? showPage;
68+
final BeamPage? showPage;
6869

6970
/// Whether to [check] all the path blueprints defined in [pathBlueprints]
7071
/// or [check] all the paths that **are not** in [pathBlueprints].
7172
///
7273
/// `false` meaning former and `true` meaning latter.
73-
bool guardNonMatching;
74+
final bool guardNonMatching;
7475

7576
/// Whether or not to replace the current [BeamLocation]'s stack of pages.
7677
final bool replaceCurrentStack;

‎package/lib/src/beam_page.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ enum BeamPageType {
1717

1818
/// A wrapper for screens in a navigation stack.
1919
class BeamPage extends Page {
20-
BeamPage({
20+
const BeamPage({
2121
LocalKey? key,
2222
String? name,
2323
required this.child,
@@ -148,7 +148,7 @@ class BeamPage extends Page {
148148
pageBuilder: (_, __, ___) => child,
149149
transitionsBuilder: (_, animation, __, child) => SlideTransition(
150150
position: animation.drive(
151-
Tween(begin: Offset(0, 1), end: Offset(0, 0))
151+
Tween(begin: const Offset(0, 1), end: const Offset(0, 0))
152152
.chain(CurveTween(curve: Curves.ease))),
153153
child: child,
154154
),

‎package/lib/src/beamer.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'path_url_strategy_nonweb.dart'
1111

1212
/// A wrapper for [Router].
1313
class Beamer extends StatefulWidget {
14-
Beamer({
14+
const Beamer({
1515
Key? key,
1616
required this.routerDelegate,
1717
this.createBackButtonDispatcher = true,

‎package/lib/src/beamer_delegate.dart‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class BeamerDelegate<T extends BeamState> extends RouterDelegate<BeamState>
3131
this.updateFromParent = true,
3232
this.updateParent = true,
3333
}) {
34-
notFoundPage ??= BeamPage(
34+
notFoundPage ??= const BeamPage(
3535
title: 'Not found',
36-
child: Container(child: Center(child: Text('Not found'))),
36+
child: Scaffold(body: Center(child: Text('Not found'))),
3737
);
3838

3939
createState ??= (BeamState state) => BeamState.fromUri(
@@ -553,7 +553,7 @@ class BeamerDelegate<T extends BeamState> extends RouterDelegate<BeamState>
553553
if (notFoundRedirect == null && notFoundRedirectNamed == null) {
554554
// do nothing, pass on NotFound
555555
} else {
556-
var redirectBeamLocation;
556+
late BeamLocation redirectBeamLocation;
557557
if (notFoundRedirect != null) {
558558
redirectBeamLocation = notFoundRedirect!;
559559
} else if (notFoundRedirectNamed != null) {
@@ -646,20 +646,20 @@ class BeamerDelegate<T extends BeamState> extends RouterDelegate<BeamState>
646646
}
647647

648648
@override
649-
SynchronousFuture<void> setInitialRoutePath(BeamState beamState) {
649+
SynchronousFuture<void> setInitialRoutePath(BeamState configuration) {
650650
if (_currentBeamLocation is! EmptyBeamLocation) {
651-
beamState = _currentBeamLocation.state;
652-
} else if (beamState.uri.path == '/') {
653-
beamState = BeamState.fromUri(
654-
Uri(path: initialPath, queryParameters: beamState.queryParameters),
651+
configuration = _currentBeamLocation.state;
652+
} else if (configuration.uri.path == '/') {
653+
configuration = BeamState.fromUri(
654+
Uri(path: initialPath, queryParameters: configuration.queryParameters),
655655
);
656656
}
657-
return setNewRoutePath(beamState);
657+
return setNewRoutePath(configuration);
658658
}
659659

660660
@override
661-
SynchronousFuture<void> setNewRoutePath(BeamState beamState) {
662-
update(state: createState!(beamState));
661+
SynchronousFuture<void> setNewRoutePath(BeamState configuration) {
662+
update(state: createState!(configuration));
663663
return SynchronousFuture(null);
664664
}
665665

@@ -698,7 +698,7 @@ class BeamerDelegate<T extends BeamState> extends RouterDelegate<BeamState>
698698
return;
699699
}
700700

701-
var redirectLocation;
701+
late BeamLocation redirectLocation;
702702

703703
if (guard.beamTo == null && guard.beamToNamed == null) {
704704
final lastState = removeLastBeamState();

‎package/lib/src/beamer_location_builder.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ typedef LocationBuilder = BeamLocation Function(BeamState);
99
///
1010
/// Determines the appropriate [BeamLocation] from the list
1111
/// and populates it with configured state.
12-
class BeamerLocationBuilder implements Function {
12+
class BeamerLocationBuilder {
1313
BeamerLocationBuilder({required this.beamLocations});
1414

1515
/// List of all [BeamLocation]s that this builder handles.
@@ -24,7 +24,7 @@ class BeamerLocationBuilder implements Function {
2424
///
2525
/// Creates a single [BeamLocation]; [SimpleBeamLocation]
2626
/// and configures its [BeamLocation.buildPages] with appropriate [routes].
27-
class SimpleLocationBuilder implements Function {
27+
class SimpleLocationBuilder {
2828
SimpleLocationBuilder({required this.routes, this.builder});
2929

3030
/// List of all routes this builder handles.

0 commit comments

Comments
 (0)