Skip to content

Commit

Permalink
Merge pull request #12 from tech-andgar/feature/fix_typo_upgrade
Browse files Browse the repository at this point in the history
Feature/fix typo upgrade
  • Loading branch information
tech-andgar authored May 3, 2024
2 parents 464d546 + e8faa79 commit 4791bcf
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# 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

- 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
Expand Down
68 changes: 67 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 # conflict 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:
Expand Down
34 changes: 34 additions & 0 deletions lib/src/http_status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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_}
Expand Down
51 changes: 46 additions & 5 deletions lib/src/utils/int_http_status_code_extension.dart
Original file line number Diff line number Diff line change
@@ -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);
}
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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.2
repository: https://github.com/DartForge/http_status
issue_tracker: https://github.com/DartForge/http_status/issues
homepage: https://github.com/DartForge/http_status
Expand All @@ -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
10 changes: 5 additions & 5 deletions test/src/http_status_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down Expand Up @@ -2209,7 +2209,7 @@ void main() {
() => HttpStatus.fromCode(600),
throwsA(
isA<ArgumentError>().having(
(e) => e.message,
(ArgumentError e) => e.message,
'message',
contains(
'Unrecognized status code. Use the HttpStatus constructor for custom codes',
Expand Down

0 comments on commit 4791bcf

Please sign in to comment.