From a866367b461af65b36d1f1c89f84b67f2696a45a Mon Sep 17 00:00:00 2001 From: "Andres Garcia (TECH-ANDGAR)" Date: Sat, 24 Feb 2024 00:31:58 -0500 Subject: [PATCH 1/4] docs: updated docs --- lib/src/http_status.dart | 34 +++++++++++++ .../utils/int_http_status_code_extension.dart | 51 +++++++++++++++++-- 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/lib/src/http_status.dart b/lib/src/http_status.dart index 1c7ae37..b5e04d7 100644 --- a/lib/src/http_status.dart +++ b/lib/src/http_status.dart @@ -78,6 +78,17 @@ import 'utils/int_http_status_code_extension.dart'; /// @immutable class HttpStatus { + /// Creates a new instance of [HttpStatus] with the provided + /// [code], [name], and [description]. + /// The constructor validates the status code to ensure it is within + /// the acceptable range of 0 to 999, inclusive. + /// If the given code falls outside this range, it throws an `ArgumentError`. + /// + /// ```dart + /// + /// final HttpStatus successStatus = + /// HttpStatus(code: 200, name: 'OK', description: 'Request succeeded.'); + /// ``` HttpStatus({ required this.code, required this.name, @@ -92,12 +103,30 @@ class HttpStatus { } } + /// A private named constructor used internally to instantiate + /// `HttpStatus` without validation. + /// This can be useful for defining constants or internal uses where + /// validation is managed externally. const HttpStatus._({ required this.code, required this.name, required this.description, }); + /// Constructs an instance of `HttpStatus` based on a predefined list of + /// status codes. + /// + /// If the given code is not found within the predefined list, + /// it throws an `ArgumentError`, suggesting the use of + /// the main constructor to define custom codes. + /// + /// ```dart + /// try { + /// var myStatus = HttpStatus.fromCode(450); + /// } catch (e) { + /// print(e); // Unrecognized status code. Use the HttpStatus constructor for custom codes + /// } + /// ``` factory HttpStatus.fromCode(int code) { if (!_httpStatusCodes.containsKey(code)) { throw ArgumentError.value( @@ -110,8 +139,13 @@ class HttpStatus { return _httpStatusCodes[code]!; } + /// The numeric HTTP status code (e.g., 200, 404). final int code; + + /// A more detailed description of what the status code means. final String description; + + /// A string name for quick identification of the status (e.g., "OK", "Not Found"). final String name; /// {@template http_status_100_continue_} diff --git a/lib/src/utils/int_http_status_code_extension.dart b/lib/src/utils/int_http_status_code_extension.dart index e0cf2c8..11cd273 100644 --- a/lib/src/utils/int_http_status_code_extension.dart +++ b/lib/src/utils/int_http_status_code_extension.dart @@ -1,21 +1,62 @@ // Copyright (c) 2024, TECH-ANDGAR. // All rights reserved. Use of this source code // is governed by a BSD-style license that can be found in the LICENSE file. + +/// Extension `IntHttpStatusCodeExtension` on [int] +/// +/// This extension provides additional functionality to integer values, +/// allowing them to be easily checked against common HTTP status code ranges. +/// HTTP status codes are divided into five distinct classes, each representing +/// a type of response the server will send in answer to a client's request. +/// +/// Usage of this extension simplifies checking the category of an HTTP status code +/// without needing to remember the specific ranges for each category. It extends +/// the built-in [int] type with simple, readable properties. +/// +/// Examples: +/// ```dart +/// int statusCode = 200; +/// bool isSuccess = statusCode.isSuccessfulHttpStatusCode; // true +/// +/// statusCode = 404; +/// bool isClientError = statusCode.isClientErrorHttpStatusCode; // true +/// ``` +/// +/// This makes your code cleaner and more expressive when handling HTTP responses. extension IntHttpStatusCodeExtension on int { + /// A utility method to check if the current integer is within a specified range. + /// + /// Takes [lower] as the lower bound and [upper] as the upper bound. + /// Returns `true` if the current integer is within the bounds, inclusive. bool isBetween(int lower, int upper) => this >= lower && this <= upper; - /// Returns true if this ranges between 100 and 199 + /// Checks if the integer represents an informational HTTP status code. + /// + /// An informational HTTP status code ranges from 100 to 199. + /// Returns `true` if the current integer is within this range. bool get isInformationHttpStatusCode => isBetween(100, 199); - /// Returns true if code ranges between 200 and 299 + /// Checks if the integer represents a successful HTTP status code. + /// + /// A successful HTTP status code ranges from 200 to 299. + /// Returns `true` if the current integer is within this range. bool get isSuccessfulHttpStatusCode => isBetween(200, 299); - /// Returns true if this ranges between 300 and 399 + /// Checks if the integer represents a redirection HTTP status code. + /// + /// A redirection HTTP status code ranges from 300 to 399. + /// Returns `true` if the current integer is within this range. bool get isRedirectHttpStatusCode => isBetween(300, 399); - /// Returns true if this ranges between 400 and 499 + /// Checks if the integer represents a client error HTTP status code. + /// + /// A client error HTTP status code ranges from 400 to 499. + /// Returns `true` if the current integer is within this range. bool get isClientErrorHttpStatusCode => isBetween(400, 499); - /// Returns true if code ranges between 500 and 599 + /// Checks if the integer represents a server error HTTP status code. + /// + /// A server error HTTP status code ranges from 500 to 599. + /// Returns `true` if the current integer is within this range. bool get isServerErrorHttpStatusCode => isBetween(500, 599); } From ca38eb5d1ba4d7f9fba5bfd9683b83d4bed9f4fa Mon Sep 17 00:00:00 2001 From: "Andres Garcia (TECH-ANDGAR)" Date: Sat, 24 Feb 2024 00:32:48 -0500 Subject: [PATCH 2/4] feat(analyzer): Enhance linting rules and type specification Expanded the list of linting rules in analysis_options.yaml for better code quality control. Added more specific error and style rules. Also, improved type specification in http_status_test.dart for clarity and consistency. --- analysis_options.yaml | 68 +++++++++++++++++++++++++++++++++- test/src/http_status_test.dart | 10 ++--- 2 files changed, 72 insertions(+), 6 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 28d1f43..d6c84fc 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -8,11 +8,77 @@ analyzer: strict-inference: true strict-raw-types: true + strong-mode: + implicit-casts: false + implicit-dynamic: true + # Lint rules and documentation, see http://dart-lang.github.io/linter/lints linter: rules: - - collection_methods_unrelated_type +# Error Rules + - avoid_slow_async_io + - cancel_subscriptions + - close_sinks + - comment_references + - literal_only_boolean_expressions + - no_adjacent_strings_in_list + - test_types_in_equals + - throw_in_finally + - unnecessary_statements + +# Style Rules + - always_declare_return_types + - always_put_control_body_on_new_line # works against dartfmt + - always_put_required_named_parameters_first + - always_specify_types # More disbuting + - avoid_annotating_with_dynamic + - avoid_bool_literals_in_conditional_expressions + - avoid_catches_without_on_clauses + - avoid_catching_errors + - avoid_classes_with_only_static_members + - avoid_double_and_int_checks + - avoid_field_initializers_in_const_classes + - avoid_function_literals_in_foreach_calls + - avoid_init_to_null + - avoid_js_rounded_ints + - avoid_positional_boolean_parameters + - avoid_private_typedef_functions + - avoid_returning_this + - avoid_setters_without_getters + # - avoid_types_on_closure_parameters # confilict always_specify_types + - avoid_unused_constructor_parameters + - avoid_void_async + - cascade_invocations + - directives_ordering + - join_return_with_assignment + - library_prefixes + # - lines_longer_than_80_chars + # - omit_local_variable_types # confilict always_specify_types + - one_member_abstracts + - only_throw_errors + - package_api_docs + - parameter_assignments + - prefer_asserts_in_initializer_lists + - prefer_const_constructors + - prefer_const_constructors_in_immutables + - prefer_const_declarations + - prefer_const_literals_to_create_immutables + - prefer_constructors_over_static_methods + - prefer_expression_function_bodies + - prefer_final_locals + - prefer_foreach + - prefer_single_quotes + - public_member_api_docs - require_trailing_commas + - sort_constructors_first + - sort_unnamed_constructors_first + - type_annotate_public_apis + - unawaited_futures + - unnecessary_lambdas + - unnecessary_parenthesis + - use_setters_to_change_properties + - use_string_buffers + - use_to_and_as_if_applicable dart_code_linter: extends: diff --git a/test/src/http_status_test.dart b/test/src/http_status_test.dart index 8a05844..77a411b 100644 --- a/test/src/http_status_test.dart +++ b/test/src/http_status_test.dart @@ -2084,22 +2084,22 @@ void main() { }); test('== and hashCode', () { - final a = HttpStatus( + final HttpStatus a = HttpStatus( code: 999, name: 'Status Code', description: '', ); - final b = HttpStatus( + final HttpStatus b = HttpStatus( code: 999, name: 'Status Code', description: '', ); - final c = HttpStatus( + final HttpStatus c = HttpStatus( code: 999, name: 'Status Code', description: '', ); - final d = HttpStatus( + final HttpStatus d = HttpStatus( code: 998, name: 'Status', description: '', @@ -2209,7 +2209,7 @@ void main() { () => HttpStatus.fromCode(600), throwsA( isA().having( - (e) => e.message, + (ArgumentError e) => e.message, 'message', contains( 'Unrecognized status code. Use the HttpStatus constructor for custom codes', From 3a97ee5504f9232359ab18e9b01cd6507ca0f2e8 Mon Sep 17 00:00:00 2001 From: "Andres Garcia (TECH-ANDGAR)" Date: Sat, 24 Feb 2024 00:36:07 -0500 Subject: [PATCH 3/4] build(http_status): Update to version 3.3.1 --- CHANGELOG.md | 6 ++++++ pubspec.yaml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2f2c07..7e158d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [3.3.1] - 2024-02-26 + +### Fixed - 3.3.1 + +- Enhanced linting rules and improved type specification in `http_status_test.dart` for better code quality control and updated documentation. + ## [3.3.0] - 2024-02-24 ### Added - 3.3.0 diff --git a/pubspec.yaml b/pubspec.yaml index cd589b9..e84d6fd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: http_status description: Constants enumerating the HTTP status codes in Dart. All status codes defined in RFC1945 (HTTP/1.0, RFC2616 (HTTP/1.1), and RFC2518 (WebDAV) are supported. -version: 3.3.0 +version: 3.3.1 repository: https://github.com/DartForge/http_status issue_tracker: https://github.com/DartForge/http_status/issues homepage: https://github.com/DartForge/http_status From e8faa796598fe5abff3be3ae6bf8dc2a27da4501 Mon Sep 17 00:00:00 2001 From: "Andres Garcia (TECH-ANDGAR)" Date: Thu, 2 May 2024 23:27:33 -0500 Subject: [PATCH 4/4] fix(workflows): Update Dart setup version and package dependencies Updated the Dart setup version in workflows to v1.6.4 and dev dependencies versions for dart_code_linter to v1.1.3 and test to v1.25.4, also fixed some typos --- .github/workflows/build.yml | 4 ++-- CHANGELOG.md | 6 ++++++ analysis_options.yaml | 2 +- pubspec.yaml | 6 +++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 58a9fe1..338de42 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: dart-lang/setup-dart@v1.6.2 + - uses: dart-lang/setup-dart@v1.6.4 with: sdk: ${{ matrix.channel }} @@ -36,7 +36,7 @@ jobs: # --set-exit-if-changed stops execution if the any code is not well formatted # --output=none prints files which needs to be formatted - # Checks for Symantic errors. Can be configured using analysis_options.yaml + # Checks for Semantic errors. Can be configured using analysis_options.yaml - name: Analyze project source run: dart analyze --fatal-infos # optionally use --fatal-warnings to stop execution if any warnings are found diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e158d2..c0b9d40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [3.3.2] - 2024-05-03 + +### Fixed - 3.3.2 + +- Updated the Dart setup version in workflow to v1.6.4 and dev dependencies versions for dart_code_linter to v1.1.3 and test to v1.25.4, also fixed a typo. + ## [3.3.1] - 2024-02-26 ### Fixed - 3.3.1 diff --git a/analysis_options.yaml b/analysis_options.yaml index d6c84fc..13314e8 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -53,7 +53,7 @@ linter: - join_return_with_assignment - library_prefixes # - lines_longer_than_80_chars - # - omit_local_variable_types # confilict always_specify_types + # - omit_local_variable_types # conflict always_specify_types - one_member_abstracts - only_throw_errors - package_api_docs diff --git a/pubspec.yaml b/pubspec.yaml index e84d6fd..648fdb6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: http_status description: Constants enumerating the HTTP status codes in Dart. All status codes defined in RFC1945 (HTTP/1.0, RFC2616 (HTTP/1.1), and RFC2518 (WebDAV) are supported. -version: 3.3.1 +version: 3.3.2 repository: https://github.com/DartForge/http_status issue_tracker: https://github.com/DartForge/http_status/issues homepage: https://github.com/DartForge/http_status @@ -18,6 +18,6 @@ dependencies: dev_dependencies: coverage: ^1.7.2 - dart_code_linter: ^1.1.2 + dart_code_linter: ^1.1.3 lints: ^3.0.0 - test: ^1.25.2 + test: ^1.25.4