Skip to content

Commit 04667d7

Browse files
authored
[pub_semver] Discourage modification of properties intended to be unmodifiable (#2020)
1 parent b23129b commit 04667d7

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

pkgs/pub_semver/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 2.1.6
2+
3+
- Clarify that the lists returned by
4+
the `preRelease` and `build` properties of `Version` and
5+
the `ranges` property of `VersionUnion` should not be modified.
6+
- Note that `VersionConstraint.any` and `VersionConstraint.empty` static fields
7+
shouldn't be reassigned and will be made `final` in a future release.
8+
19
## 2.1.5
210

311
- Require Dart `3.4.0`.

pkgs/pub_semver/lib/src/version.dart

+8-2
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,17 @@ class Version implements VersionConstraint, VersionRange {
7070
/// This is split into a list of components, each of which may be either a
7171
/// string or a non-negative integer. It may also be empty, indicating that
7272
/// this version has no pre-release identifier.
73+
///
74+
/// **Note:** The returned list shouldn't be modified.
7375
final List<Object> preRelease;
7476

7577
/// The build identifier: "foo" in "1.2.3+foo".
7678
///
7779
/// This is split into a list of components, each of which may be either a
7880
/// string or a non-negative integer. It may also be empty, indicating that
7981
/// this version has no build identifier.
82+
///
83+
/// **Note:** The returned list shouldn't be modified.
8084
final List<Object> build;
8185

8286
/// The original string representation of the version number.
@@ -96,8 +100,10 @@ class Version implements VersionConstraint, VersionRange {
96100

97101
Version._(this.major, this.minor, this.patch, String? preRelease,
98102
String? build, this._text)
99-
: preRelease = preRelease == null ? <Object>[] : _splitParts(preRelease),
100-
build = build == null ? [] : _splitParts(build) {
103+
: preRelease = preRelease == null || preRelease.isEmpty
104+
? []
105+
: _splitParts(preRelease),
106+
build = build == null || build.isEmpty ? [] : _splitParts(build) {
101107
if (major < 0) throw ArgumentError('Major version must be non-negative.');
102108
if (minor < 0) throw ArgumentError('Minor version must be non-negative.');
103109
if (patch < 0) throw ArgumentError('Patch version must be non-negative.');

pkgs/pub_semver/lib/src/version_constraint.dart

+6
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ import 'version_union.dart';
1616
/// version.
1717
abstract class VersionConstraint {
1818
/// A [VersionConstraint] that allows all versions.
19+
///
20+
/// **Note:** This property shouldn't be reassigned.
21+
/// It will be made `final` in a future release.
1922
static VersionConstraint any = VersionRange();
2023

2124
/// A [VersionConstraint] that allows no versions -- the empty set.
25+
///
26+
/// **Note:** This property shouldn't be reassigned.
27+
/// It will be made `final` in a future release.
2228
static VersionConstraint empty = const _EmptyVersion();
2329

2430
/// Parses a version constraint.

pkgs/pub_semver/lib/src/version_union.dart

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class VersionUnion implements VersionConstraint {
2323
/// * Its contents are disjoint and non-adjacent. In other words, for any two
2424
/// constraints next to each other in the list, there's some version between
2525
/// those constraints that they don't match.
26+
///
27+
/// **Note:** The returned list shouldn't be modified.
2628
final List<VersionRange> ranges;
2729

2830
@override

pkgs/pub_semver/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: pub_semver
2-
version: 2.1.5
2+
version: 2.1.6
33
description: >-
44
Versions and version constraints implementing pub's versioning policy. This
55
is very similar to vanilla semver, with a few corner cases.

0 commit comments

Comments
 (0)