Skip to content
This repository was archived by the owner on Jul 25, 2022. It is now read-only.

Commit d49393e

Browse files
authored
Merge pull request #4 from LukasPoque/add_linter_analysis
Add linter analysis to S3I-Flutter
2 parents 4327d58 + aebb5ce commit d49393e

Some content is hidden

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

45 files changed

+2064
-906
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 0.3.0
2+
3+
Add linting rules and fulfill them.
4+
- add documentation to all public members, classes and methods
5+
- restructure some of the exceptions and add every thrown exception to the documentation of the method
6+
- improve tests
7+
18
## 0.2.1
29

310
Add web support and fix formatting + README.

README.md

+1-9
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,7 @@ For further information see the [KWH Glossar](https://www.kwh40.de/glossar/) and
3838

3939
## Installing
4040

41-
Add it to your `pubspec.yaml` file:
42-
```yaml
43-
dependencies:
44-
s3i_flutter: ^0.2.1
45-
```
46-
Install packages from the command line
47-
```
48-
flutter packages get
49-
```
41+
Please see [Pub.dev](https://pub.dev/packages/s3i_flutter/install) for instructions how to install this package to your flutter app.
5042

5143
If you like this package, consider supporting it by giving a star on [GitHub](https://github.com/LukasPoque/s3i_flutter) and
5244
a like on [pub.dev](https://pub.dev/packages/s3i_flutter) :heart:

analysis_options.yaml

+206
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
# From the official flutter repo: https://github.com/flutter/flutter/blob/master/analysis_options.yaml
2+
# partly customized for S3I Flutter
3+
# see https://dart.dev/guides/language/analysis-options for more information
4+
5+
analyzer:
6+
strong-mode:
7+
implicit-casts: false
8+
implicit-dynamic: false
9+
errors:
10+
# treat missing required parameters as a error (not a hint)
11+
missing_required_param: error
12+
# treat missing returns as a error (not a hint)
13+
missing_return: error
14+
# allow having TODOs in the code
15+
todo: ignore
16+
# allow self-reference to deprecated members
17+
deprecated_member_use_from_same_package: info
18+
unnecessary_null_comparison: warning
19+
exclude:
20+
- "bin/cache/**"
21+
- "dev/conductor/lib/proto/*"
22+
- "example/**"
23+
24+
linter:
25+
rules:
26+
- always_declare_return_types
27+
# - always_put_control_body_on_new_line
28+
# - always_put_required_named_parameters_first # prefer having parameters in the same order as fields
29+
- always_require_non_null_named_parameters
30+
- always_specify_types
31+
- always_use_package_imports
32+
- annotate_overrides
33+
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
34+
- avoid_bool_literals_in_conditional_expressions
35+
# - avoid_catches_without_on_clauses # sometimes necessary to convert them to s3i errors
36+
# - avoid_catching_errors # see avoid_catches_without_on_clauses
37+
- avoid_classes_with_only_static_members
38+
- avoid_double_and_int_checks
39+
- avoid_dynamic_calls
40+
- avoid_empty_else
41+
# - avoid_equals_and_hash_code_on_mutable_classes # currently used for the data classes, maybe we should change this later
42+
- avoid_escaping_inner_quotes
43+
- avoid_field_initializers_in_const_classes
44+
- avoid_function_literals_in_foreach_calls
45+
- avoid_implementing_value_types
46+
- avoid_init_to_null
47+
- avoid_js_rounded_ints
48+
- avoid_null_checks_in_equality_operators
49+
- avoid_positional_boolean_parameters
50+
- avoid_print
51+
# - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
52+
# - avoid_redundant_argument_values # we could do declare arguments with values that match the defaults to highlight this value
53+
- avoid_relative_lib_imports
54+
- avoid_renaming_method_parameters
55+
- avoid_return_types_on_setters
56+
# - avoid_returning_null # there are plenty of valid reasons to return null
57+
- avoid_returning_null_for_future
58+
- avoid_returning_null_for_void
59+
# - avoid_returning_this # there are plenty of valid reasons to return this
60+
- avoid_setters_without_getters
61+
- avoid_shadowing_type_parameters
62+
- avoid_single_cascade_in_expression_statements
63+
- avoid_slow_async_io
64+
- avoid_type_to_string
65+
- avoid_types_as_parameter_names
66+
# - avoid_types_on_closure_parameters # conflicts with always_specify_types
67+
- avoid_unnecessary_containers
68+
- avoid_unused_constructor_parameters
69+
- avoid_void_async
70+
# - avoid_web_libraries_in_flutter # unsure what to do
71+
- await_only_futures
72+
- camel_case_extensions
73+
- camel_case_types
74+
- cancel_subscriptions
75+
- cascade_invocations
76+
- cast_nullable_to_non_nullable
77+
# - close_sinks # not reliable enough
78+
# - comment_references # blocked on https://github.com/dart-lang/linter/issues/1142
79+
# - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
80+
- control_flow_in_finally
81+
# - curly_braces_in_flow_control_structures # not required by flutter style
82+
- deprecated_consistency
83+
# - diagnostic_describe_all_properties
84+
- directives_ordering
85+
# - do_not_use_environment # we do this commonly
86+
- empty_catches
87+
- empty_constructor_bodies
88+
- empty_statements
89+
- exhaustive_cases
90+
- file_names
91+
- flutter_style_todos
92+
- hash_and_equals
93+
- implementation_imports
94+
# - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811
95+
- iterable_contains_unrelated_type
96+
# - join_return_with_assignment # not required by flutter style
97+
- leading_newlines_in_multiline_strings
98+
- library_names
99+
- library_prefixes
100+
- lines_longer_than_80_chars
101+
- list_remove_unrelated_type
102+
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
103+
- missing_whitespace_between_adjacent_strings
104+
- no_adjacent_strings_in_list
105+
# - no_default_cases # too many false positives
106+
- no_duplicate_case_values
107+
- no_logic_in_create_state
108+
- no_runtimeType_toString
109+
- non_constant_identifier_names
110+
- null_check_on_nullable_type_parameter
111+
- null_closures
112+
# - omit_local_variable_types # opposite of always_specify_types
113+
# - one_member_abstracts # too many false positives
114+
- only_throw_errors
115+
- overridden_fields
116+
- package_api_docs
117+
- package_names
118+
- package_prefixed_library_names
119+
- parameter_assignments
120+
- prefer_adjacent_string_concatenation
121+
- prefer_asserts_in_initializer_lists
122+
# - prefer_asserts_with_message # not required by flutter style
123+
- prefer_collection_literals
124+
- prefer_conditional_assignment
125+
- prefer_const_constructors
126+
- prefer_const_constructors_in_immutables
127+
- prefer_const_declarations
128+
- prefer_const_literals_to_create_immutables
129+
# - prefer_constructors_over_static_methods # far too many false positives
130+
- prefer_contains
131+
# - prefer_double_quotes
132+
- prefer_equal_for_default_values
133+
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
134+
- prefer_final_fields
135+
- prefer_final_in_for_each
136+
- prefer_final_locals
137+
- prefer_for_elements_to_map_fromIterable
138+
- prefer_foreach
139+
- prefer_function_declarations_over_variables
140+
- prefer_generic_function_type_aliases
141+
- prefer_if_elements_to_conditional_expressions
142+
- prefer_if_null_operators
143+
- prefer_initializing_formals
144+
- prefer_inlined_adds
145+
# - prefer_int_literals # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#use-double-literals-for-double-constants
146+
- prefer_interpolation_to_compose_strings
147+
- prefer_is_empty
148+
- prefer_is_not_empty
149+
- prefer_is_not_operator
150+
- prefer_iterable_whereType
151+
# - prefer_mixin # https://github.com/dart-lang/language/issues/32
152+
- prefer_null_aware_operators
153+
# - prefer_relative_imports # incompatible with sub-package imports
154+
- prefer_single_quotes
155+
- prefer_spread_collections
156+
- prefer_typing_uninitialized_variables
157+
- prefer_void_to_null
158+
- provide_deprecation_message
159+
- public_member_api_docs
160+
- recursive_getters
161+
- sized_box_for_whitespace
162+
- slash_for_doc_comments
163+
- sort_child_properties_last
164+
- sort_constructors_first
165+
- sort_pub_dependencies
166+
- sort_unnamed_constructors_first
167+
- test_types_in_equals
168+
- throw_in_finally
169+
- tighten_type_of_initializing_formals
170+
# - type_annotate_public_apis # subset of always_specify_types
171+
- type_init_formals
172+
# - unawaited_futures # too many false positives
173+
- unnecessary_await_in_return
174+
- unnecessary_brace_in_string_interps
175+
- unnecessary_const
176+
# - unnecessary_final # conflicts with prefer_final_locals
177+
- unnecessary_getters_setters
178+
# - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
179+
- unnecessary_new
180+
- unnecessary_null_aware_assignments
181+
- unnecessary_null_checks
182+
- unnecessary_null_in_if_null_operators
183+
- unnecessary_nullable_for_final_variable_declarations
184+
- unnecessary_overrides
185+
- unnecessary_parenthesis
186+
- unnecessary_raw_strings
187+
- unnecessary_statements
188+
- unnecessary_string_escapes
189+
- unnecessary_string_interpolations
190+
- unnecessary_this
191+
- unrelated_type_equality_checks
192+
- unsafe_html
193+
- use_full_hex_values_for_flutter_colors
194+
- use_function_type_syntax_for_parameters
195+
- use_if_null_to_convert_nulls_to_bools
196+
- use_is_even_rather_than_modulo
197+
- use_key_in_widget_constructors
198+
- use_late_for_private_fields_and_variables
199+
- use_named_constants
200+
- use_raw_strings
201+
- use_rethrow_when_possible
202+
- use_setters_to_change_properties
203+
# - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
204+
# - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
205+
- valid_regexps
206+
- void_checks

example/lib/main.dart

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import 'package:s3i_flutter/s3i_flutter.dart';
33
import 'package:url_launcher/url_launcher.dart';
44

55
//TODO: replace with your own client data
6-
// the client used here has no permissions in the s3i unless your personal account grants some
7-
final clientIdentity = ClientIdentity(
8-
"s3i-flutter-example-client", "a3d4752b-396d-4bc8-a337-e54fb2c1706d");
6+
// the client used here has no permissions in the s3i unless your personal
7+
// account grants some
8+
final clientIdentity = ClientIdentity("s3i-flutter-example-client",
9+
secret: "a3d4752b-396d-4bc8-a337-e54fb2c1706d");
910

1011
void main() {
1112
runApp(MyApp());
@@ -107,7 +108,7 @@ class _MyHomePageState extends State<MyHomePage> {
107108
SelectableText(accessToken != null ? accessToken!.originalToken : ""),
108109
SizedBox(height: 8),
109110
SelectableText(
110-
accessToken != null ? accessToken!.decodedToken.toString() : ""),
111+
accessToken != null ? accessToken!.decodedPayload.toString() : ""),
111112
],
112113
),
113114
);

example/pubspec.lock

+1-8
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,6 @@ packages:
8686
url: "https://pub.dartlang.org"
8787
source: hosted
8888
version: "0.6.3"
89-
jwt_decoder:
90-
dependency: transitive
91-
description:
92-
name: jwt_decoder
93-
url: "https://pub.dartlang.org"
94-
source: hosted
95-
version: "2.0.1"
9689
matcher:
9790
dependency: transitive
9891
description:
@@ -134,7 +127,7 @@ packages:
134127
path: ".."
135128
relative: true
136129
source: path
137-
version: "0.2.0"
130+
version: "0.2.1"
138131
sky_engine:
139132
dependency: transitive
140133
description: flutter

lib/s3i_flutter.dart

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
library s3i_flutter;
22

3-
export 'src/s3i_core.dart';
3+
//auth
4+
export 'src/auth/authentication_manager.dart';
5+
export 'src/auth/client_identity.dart';
6+
export 'src/auth/oauth_proxy_flow.dart';
7+
export 'src/auth/tokens.dart';
48

59
//directory
6-
export 'src/directory/thing.dart';
710
export 'src/directory/dir_object.dart';
811
export 'src/directory/endpoint.dart';
912
export 'src/directory/link.dart';
1013
export 'src/directory/location.dart';
14+
export 'src/directory/thing.dart';
1115
export 'src/directory/value.dart';
1216

13-
//exceptions
14-
export 'src/exceptions/s3i_exception.dart';
17+
//exception
1518
export 'src/exceptions/invalid_json_schema_exception.dart';
1619
export 'src/exceptions/json_missing_key_exception.dart';
17-
export 'src/exceptions/parse_exception.dart';
1820
export 'src/exceptions/max_retry_exception.dart';
1921
export 'src/exceptions/network_response_exception.dart';
22+
export 'src/exceptions/parse_exception.dart';
23+
export 'src/exceptions/s3i_exception.dart';
2024

2125
//policy
2226
export 'src/policy/policy_entry.dart';
@@ -25,14 +29,11 @@ export 'src/policy/policy_resource.dart';
2529
export 'src/policy/policy_subject.dart';
2630

2731
//query
28-
export 'src/query/query_assembler.dart';
2932
export 'src/query/field_query.dart';
3033
export 'src/query/namespace_query.dart';
3134
export 'src/query/option_query.dart';
35+
export 'src/query/query_assembler.dart';
3236
export 'src/query/rql_query.dart';
3337

34-
//auth
35-
export 'src/auth/tokens.dart';
36-
export 'src/auth/client_identity.dart';
37-
export 'src/auth/authentication_manager.dart';
38-
export 'src/auth/oauth_proxy_flow.dart';
38+
//core
39+
export 'src/s3i_core.dart';
+18-5
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
11
import 'package:s3i_flutter/src/auth/client_identity.dart';
22
import 'package:s3i_flutter/src/auth/tokens.dart';
33

4-
/// Base class for the different login approaches
4+
/// Base class for the different authentication approaches to
5+
/// the S3I-IdentityProvider.
56
abstract class AuthenticationManager {
7+
/// Creates an [AuthenticationManager] with the given [clientIdentity] and
8+
/// the given [scopes] (with an empty list as default).
9+
AuthenticationManager(this.clientIdentity, {this.scopes = const <String>[]});
10+
11+
/// The identity used to issue tokens at the IdP.
612
final ClientIdentity clientIdentity;
13+
14+
/// All scopes which are added to the auth request.
15+
///
16+
/// Is an empty map as default.
717
List<String> scopes;
8-
//TODO: use discovery endpoint
918

10-
AuthenticationManager(this.clientIdentity, {this.scopes = const []});
19+
// TODO(poq): save/use discovery endpoint (information)
1120

1221
/// Returns a valid [AccessToken] for the [clientIdentity]
1322
/// which is at least valid for the time specified in [tokenValidBuffer].
23+
///
24+
/// The default value for [tokenValidBuffer] is 10 seconds.
1425
Future<AccessToken> getAccessToken({int tokenValidBuffer = 10});
1526

27+
/// Deletes old tokens and invalidates the token session at the IdP.
1628
Future<bool> logout();
1729

1830
/// Sets the [scopes] which are used for issuing a new token.
19-
/// If [newScopes] is NOT equals [scopes] both tokens are invalidated (doesn't mind the order of the scopes).
31+
/// If [newScopes] is NOT equals [scopes] both tokens are invalidated
32+
/// (doesn't mind the order of the scopes).
2033
void setScopes(List<String> newScopes);
2134

2235
@override
2336
String toString() {
24-
return "AuthenticationManager($clientIdentity)";
37+
return 'AuthenticationManager($clientIdentity, $scopes)';
2538
}
2639
}

0 commit comments

Comments
 (0)