Skip to content

Commit ff718f2

Browse files
committed
chore(lint): enable additional dcm rules and update dependencies
- Enable shorthand preference rules that were previously disabled - Enable new metrics rules: avoid-missing-test-files, avoid-unassigned-local-variable, avoid-undisposed-instances, avoid-unnecessary-parentheses, prefer-non-nulls - Disable avoid-throw rule due to breaking change and use of maybe* methods - Update dart_code_metrics_presets to ^2.30.0 - Update test to ^1.31.0 - Update SDK constraint to ^3.11.3 - Fix RegExp instantiation to use shorthand syntax - Update example code to use maybeMapStatusCode with proper parameter handling
1 parent f48577f commit ff718f2

6 files changed

Lines changed: 33 additions & 23 deletions

File tree

analysis_options.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,12 @@ dart_code_metrics:
122122
min-occurrences: 4
123123

124124
# Disabled:
125-
# Shorthands:
126-
- prefer-returning-shorthands: false
127-
- prefer-shorthands-with-constructors: false
128-
- prefer-shorthands-with-enums: false
129-
- prefer-shorthands-with-static-fields: false
130-
# Other disabled:
131125
- arguments-ordering: false # This will be a breaking change.
132126
- avoid-continue: false # Just a matter of style.
133127
- avoid-deprecated-usage: false # Using default deprecated_member_use_from_same_package.
134128
- avoid-inferrable-type-arguments: false # Against prefer-explicit-type-arguments.
135129
- avoid-long-files: false # A lot of data and collections.
130+
- avoid-throw: false # Breaking change + we have maybe* methods.
136131
- no-magic-number: false # Packages contain a lot of numbers.
137132
- no-magic-string: false # Packages contain a lot of strings.
138133
- parameters-ordering: false # This will be a breaking change.
@@ -218,6 +213,7 @@ dart_code_metrics:
218213
- avoid-missing-completer-stack-trace: true
219214
- avoid-missing-enum-constant-in-map: true
220215
- avoid-missing-interpolation: true
216+
- avoid-missing-test-files: true
221217
- avoid-misused-set-literals: true
222218
- avoid-misused-test-matchers: true
223219
- avoid-misused-wildcard-pattern: true
@@ -276,9 +272,11 @@ dart_code_metrics:
276272
- avoid-type-casts: true
277273
- avoid-unassigned-fields: true
278274
- avoid-unassigned-late-fields: true
275+
- avoid-unassigned-local-variable: true
279276
- avoid-unassigned-stream-subscriptions: true
280277
- avoid-uncaught-future-errors: true
281278
- avoid-unconditional-break: true
279+
- avoid-undisposed-instances: true
282280
- avoid-unknown-pragma: true
283281
- avoid-unnecessary-block: true
284282
- avoid-unnecessary-call: true
@@ -304,6 +302,7 @@ dart_code_metrics:
304302
- avoid-unnecessary-nullable-parameters: true
305303
- avoid-unnecessary-nullable-return-type: true
306304
- avoid-unnecessary-overrides: true
305+
- avoid-unnecessary-parentheses: true
307306
- avoid-unnecessary-patterns: true
308307
- avoid-unnecessary-reassignment: true
309308
- avoid-unnecessary-return: true
@@ -401,6 +400,7 @@ dart_code_metrics:
401400
- prefer-match-file-name: true
402401
- prefer-moving-to-variable: true
403402
- prefer-named-boolean-parameters: true
403+
- prefer-non-nulls: true
404404
- prefer-null-aware-elements: true
405405
- prefer-null-aware-spread: true
406406
- prefer-overriding-parent-equality: true
@@ -413,6 +413,10 @@ dart_code_metrics:
413413
- prefer-return-await: true
414414
- prefer-returning-condition: true
415415
- prefer-returning-conditional-expressions: true
416+
- prefer-returning-shorthands: true
417+
- prefer-shorthands-with-constructors: true
418+
- prefer-shorthands-with-enums: true
419+
- prefer-shorthands-with-static-fields: true
416420
- prefer-simpler-boolean-expressions: true
417421
- prefer-simpler-patterns-null-check: true
418422
- prefer-single-declaration-per-file: true
@@ -658,4 +662,4 @@ linter:
658662
use_to_and_as_if_applicable: true
659663
use_truncating_division: true
660664
valid_regexps: true
661-
void_checks: true
665+
void_checks: true

example/analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include: ../analysis_options.yaml
1+
include: ../analysis_options.yaml

example/lib/main.dart

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,13 @@ Future<int?> _realClient(List<String> arguments, [http.Client? client]) async {
8585

8686
// If the status code is a success status code, check if it is a 201
8787
// (Created) or 200 (OK) code.
88-
return response.statusCode.maybeWhenStatusCode(
89-
isSuccess: () {
88+
return response.statusCode.maybeMapStatusCode(
89+
isSuccess: (successStatus) {
9090
// If the status code is success one, convert it to a registered
9191
// status code object.
92-
final registeredCode = response.statusCode.toRegisteredStatusCode();
92+
final registeredCode = successStatus.toRegisteredStatusCode();
9393

94-
// Use the [StatusCode] type to determine the specific status code
95-
// type.
94+
// Use the [StatusCode] type to determine the specific status code type.
9695
return registeredCode?.maybeMap(
9796
createdHttp201: (status) {
9897
print('Response has registered success status but not 200 code');
@@ -114,17 +113,24 @@ Future<int?> _realClient(List<String> arguments, [http.Client? client]) async {
114113
print('Response has success status but not 200 code');
115114

116115
// Return the status code.
117-
return response.statusCode;
116+
return successStatus;
118117
},
119118
) ??
120119
// If the status code is not a registered status code, return the
121120
// status code.
122-
response.statusCode;
121+
successStatus;
123122
},
124-
orElse: () {
123+
isClientError: (errorStatus) {
124+
if (errorStatus.isOneOf(const [StatusCode.tooManyRequestsHttp429])) {
125+
print('Response has too many requests status :(');
126+
}
127+
128+
return errorStatus; // Return the status code.
129+
},
130+
orElse: (otherStatus) {
125131
// If the status code is not a success status code, print an error
126132
// message and return the status code.
127-
print('Request failed with status: ${response.statusCode}!');
133+
print('Request failed with status: $otherStatus!');
128134

129135
return response.statusCode;
130136
},

example/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ description: A simple one and modified http package example with use of function
33
publish_to: none
44

55
environment:
6-
sdk: ^3.11.1
6+
sdk: ^3.11.3
77

88
dependencies:
99
functional_status_codes:
1010
path: ../
1111
http: any # ignore: avoid-any-version, it's exampe app.
1212

1313
dev_dependencies:
14-
dart_code_metrics_presets: ^2.29.0 # DCM.
14+
dart_code_metrics_presets: ^2.30.0 # DCM.
1515
lints: ^6.1.0 # From Google.
16-
test: ^1.30.0 # From Google.
16+
test: ^1.31.0 # From Google.

lib/src/status_code.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ extension type const StatusCode._(int _code) implements int {
734734
/// See also:
735735
/// - [pattern], the raw regular expression string this getter utilizes.
736736
/// - [StatusCode], which contains standard HTTP status codes.
737-
static RegExp get regExp => RegExp(pattern, caseSensitive: false);
737+
static RegExp get regExp => .new(pattern, caseSensitive: false);
738738

739739
/// Returns the [StatusCode] type value for the given status code, if it
740740
/// exists. Otherwise, returns `null`.

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ environment:
2020

2121
dev_dependencies:
2222
coverage: ^1.15.0 # From Google.
23-
dart_code_metrics_presets: ^2.29.0 # DCM.
23+
dart_code_metrics_presets: ^2.30.0 # DCM.
2424
lints: ^6.1.0 # From Google.
25-
test: ^1.30.0 # From Google.
25+
test: ^1.31.0 # From Google.

0 commit comments

Comments
 (0)