Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

update and fix lints, bump min SDK #74

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
update and fix lints, bump min SDK
  • Loading branch information
kevmoo committed Nov 7, 2022
commit 5110e5377a1c68d4acdeedc985e372f74cb67518
2 changes: 1 addition & 1 deletion .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
sdk: [2.12.0, dev]
sdk: [2.17.0, dev]
steps:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d
Expand Down
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.1.3-dev

- Require Dart 2.17.

# 2.1.2

- Add markdown badges to the readme.
Expand All @@ -16,10 +20,6 @@
# 2.0.0

- Stable null safety release.

# 2.0.0-nullsafety.0

- Migrate to null safety.
- `Version.primary` now throws `StateError` if the `versions` argument is empty.

# 1.4.4
Expand Down
51 changes: 24 additions & 27 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,58 +1,55 @@
# https://dart.dev/guides/language/analysis-options
include: package:lints/recommended.yaml

analyzer:
language:
strict-casts: true
strict-inference: true
strict-raw-types: true

linter:
rules:
- always_declare_return_types
- avoid_bool_literals_in_conditional_expressions
- avoid_catching_errors
- avoid_classes_with_only_static_members
- avoid_function_literals_in_foreach_calls
- avoid_renaming_method_parameters
- avoid_dynamic_calls
- avoid_private_typedef_functions
- avoid_redundant_argument_values
- avoid_returning_null
- avoid_returning_null_for_future
- avoid_returning_null_for_void
- avoid_returning_this
- avoid_single_cascade_in_expression_statements
- avoid_unused_constructor_parameters
- await_only_futures
- camel_case_types
- avoid_void_async
- cancel_subscriptions
- cascade_invocations
- comment_references
- constant_identifier_names
- control_flow_in_finally
- directives_ordering
- empty_statements
- file_names
- hash_and_equals
- implementation_imports
- iterable_contains_unrelated_type
- join_return_with_assignment
- list_remove_unrelated_type
- lines_longer_than_80_chars
- literal_only_boolean_expressions
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
- non_constant_identifier_names
- no_runtimeType_toString
- omit_local_variable_types
- only_throw_errors
- overridden_fields
- package_api_docs
- package_names
- package_prefixed_library_names
- prefer_asserts_in_initializer_lists
- prefer_const_constructors
#- prefer_final_locals
- prefer_initializing_formals
- prefer_interpolation_to_compose_strings
- prefer_null_aware_operators
- prefer_typing_uninitialized_variables
- prefer_const_declarations
- prefer_expression_function_bodies
- prefer_relative_imports
- prefer_single_quotes
- sort_pub_dependencies
- test_types_in_equals
- throw_in_finally
- type_annotate_public_apis
- unawaited_futures
- unnecessary_await_in_return
- unnecessary_brace_in_string_interps
- unnecessary_getters_setters
- unnecessary_lambdas
- unnecessary_null_aware_assignments
- unnecessary_parenthesis
- unnecessary_statements
- void_checks
- use_if_null_to_convert_nulls_to_bools
- use_raw_strings
- use_string_buffers
- use_super_parameters
23 changes: 12 additions & 11 deletions lib/src/version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'version_constraint.dart';
import 'version_range.dart';

/// The equality operator to use for comparing version components.
final _equality = const IterableEquality();
const _equality = IterableEquality();

/// A parsed semantic version number.
@sealed
Expand Down Expand Up @@ -70,14 +70,14 @@ class Version implements VersionConstraint, VersionRange {
/// This is split into a list of components, each of which may be either a
/// string or a non-negative integer. It may also be empty, indicating that
/// this version has no pre-release identifier.
final List preRelease;
final List<Object> preRelease;

/// The build identifier: "foo" in "1.2.3+foo".
///
/// This is split into a list of components, each of which may be either a
/// string or a non-negative integer. It may also be empty, indicating that
/// this version has no build identifier.
final List build;
final List<Object> build;

/// The original string representation of the version number.
///
Expand All @@ -96,7 +96,7 @@ class Version implements VersionConstraint, VersionRange {

Version._(this.major, this.minor, this.patch, String? preRelease,
String? build, this._text)
: preRelease = preRelease == null ? [] : _splitParts(preRelease),
: preRelease = preRelease == null ? <Object>[] : _splitParts(preRelease),
build = build == null ? [] : _splitParts(build) {
if (major < 0) throw ArgumentError('Major version must be non-negative.');
if (minor < 0) throw ArgumentError('Minor version must be non-negative.');
Expand Down Expand Up @@ -154,12 +154,13 @@ class Version implements VersionConstraint, VersionRange {
/// Splits a string of dot-delimited identifiers into their component parts.
///
/// Identifiers that are numeric are converted to numbers.
static List _splitParts(String text) {
return text.split('.').map((part) {
// Return an integer part if possible, otherwise return the string as-is
return int.tryParse(part) ?? part;
}).toList();
}
static List<Object> _splitParts(String text) => text
.split('.')
.map((part) =>
// Return an integer part if possible, otherwise return the string
// as-is
int.tryParse(part) ?? part)
.toList();

@override
bool operator ==(Object other) =>
Expand Down Expand Up @@ -354,7 +355,7 @@ class Version implements VersionConstraint, VersionRange {
///
/// This is used for the pre-release and build version parts. This follows
/// Rule 12 of the Semantic Versioning spec (v2.0.0-rc.1).
int _compareLists(List a, List b) {
int _compareLists(List<Object> a, List<Object> b) {
for (var i = 0; i < math.max(a.length, b.length); i++) {
var aPart = (i < a.length) ? a[i] : null;
var bPart = (i < b.length) ? b[i] : null;
Expand Down
7 changes: 2 additions & 5 deletions lib/src/version_constraint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,11 @@ abstract class VersionConstraint {
case '<=':
return VersionRange(max: version, includeMax: true);
case '<':
return VersionRange(
max: version,
includeMax: false,
alwaysIncludeMaxPreRelease: true);
return VersionRange(max: version, alwaysIncludeMaxPreRelease: true);
case '>=':
return VersionRange(min: version, includeMin: true);
case '>':
return VersionRange(min: version, includeMin: false);
return VersionRange(min: version);
}
throw UnsupportedError(op!);
}
Expand Down
6 changes: 1 addition & 5 deletions lib/src/version_range.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class VersionRange implements Comparable<VersionRange>, VersionConstraint {
VersionRange._(this.min, this.max, this.includeMin, this.includeMax);

@override
bool operator ==(other) {
bool operator ==(Object other) {
if (other is! VersionRange) return false;

return min == other.min &&
Expand Down Expand Up @@ -294,7 +294,6 @@ class VersionRange implements Comparable<VersionRange>, VersionConstraint {
return VersionRange(
min: min,
max: max,
includeMin: false,
includeMax: includeMax,
alwaysIncludeMaxPreRelease: true);
}
Expand All @@ -305,7 +304,6 @@ class VersionRange implements Comparable<VersionRange>, VersionConstraint {
min: min,
max: max,
includeMin: includeMin,
includeMax: false,
alwaysIncludeMaxPreRelease: true);
}

Expand All @@ -314,12 +312,10 @@ class VersionRange implements Comparable<VersionRange>, VersionConstraint {
min: min,
max: other,
includeMin: includeMin,
includeMax: false,
alwaysIncludeMaxPreRelease: true),
VersionRange(
min: other,
max: max,
includeMin: false,
includeMax: includeMax,
alwaysIncludeMaxPreRelease: true)
]);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/version_union.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class VersionUnion implements VersionConstraint {
///
/// It's up to the caller to ensure that the invariants described in [ranges]
/// are maintained. They are not verified by this constructor. To
/// automatically ensure that they're maintained, use [new
/// VersionConstraint.unionOf] instead.
/// automatically ensure that they're maintained, use
/// [VersionConstraint.unionOf] instead.
VersionUnion.fromRanges(this.ranges);

@override
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: pub_semver
version: 2.1.2
version: 2.1.3-dev
description: >-
Versions and version constraints implementing pub's versioning policy. This
is very similar to vanilla semver, with a few corner cases.
repository: https://github.com/dart-lang/pub_semver

environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=2.17.0 <3.0.0'

dependencies:
collection: ^1.15.0
meta: ^1.3.0

dev_dependencies:
lints: ^1.0.0
lints: ^2.0.0
test: ^1.16.0
6 changes: 3 additions & 3 deletions test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class _VersionConstraintMatcher implements Matcher {
_VersionConstraintMatcher(this._expected, this._allow);

@override
bool matches(item, Map matchState) =>
bool matches(dynamic item, Map<dynamic, dynamic> matchState) =>
(item is VersionConstraint) &&
_expected.every((version) => item.allows(version) == _allow);

Expand All @@ -46,8 +46,8 @@ class _VersionConstraintMatcher implements Matcher {
}

@override
Description describeMismatch(
item, Description mismatchDescription, Map matchState, bool verbose) {
Description describeMismatch(dynamic item, Description mismatchDescription,
Map<dynamic, dynamic> matchState, bool verbose) {
if (item is! VersionConstraint) {
mismatchDescription.add('was not a VersionConstraint');
return mismatchDescription;
Expand Down
5 changes: 2 additions & 3 deletions test/version_range_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -961,12 +961,11 @@ void main() {
test('includeMin comes before !includeMin', () {
_expectComparesSmaller(
VersionRange(min: v003, max: v080, includeMin: true),
VersionRange(min: v003, max: v080, includeMin: false));
VersionRange(min: v003, max: v080));
});

test('includeMax comes after !includeMax', () {
_expectComparesSmaller(
VersionRange(min: v003, max: v080, includeMax: false),
_expectComparesSmaller(VersionRange(min: v003, max: v080),
VersionRange(min: v003, max: v080, includeMax: true));
});

Expand Down
2 changes: 1 addition & 1 deletion test/version_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,4 @@ void main() {
}

Version _primary(List<String> input) =>
Version.primary(input.map((e) => Version.parse(e)).toList());
Version.primary(input.map(Version.parse).toList());