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

Commit 8345b41

Browse files
committed
Add structural equality for dependencies
1 parent 016f506 commit 8345b41

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
## 1.2.4-wip
1+
## 1.3.4-wip
22

33
- Require Dart 3.0
44
- Added support for `ignored_advisories` field.
5+
- Added structural equality for `Dependency` subclasses and `HostedDetails`.
56

67
## 1.2.3
78

lib/src/dependency.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ class SdkDependency extends Dependency {
111111

112112
@override
113113
String get _info => sdk;
114+
115+
@override
116+
bool operator ==(Object other) =>
117+
other is SdkDependency && other.sdk == sdk && other.version == version;
118+
119+
@override
120+
int get hashCode => Object.hash(sdk, version);
114121
}
115122

116123
@JsonSerializable()
@@ -136,6 +143,16 @@ class GitDependency extends Dependency {
136143

137144
@override
138145
String get _info => 'url@$url';
146+
147+
@override
148+
bool operator ==(Object other) =>
149+
other is GitDependency &&
150+
other.url == url &&
151+
other.ref == ref &&
152+
other.path == path;
153+
154+
@override
155+
int get hashCode => Object.hash(url, ref, path);
139156
}
140157

141158
Uri? parseGitUriOrNull(String? value) =>
@@ -188,6 +205,13 @@ class PathDependency extends Dependency {
188205

189206
@override
190207
String get _info => 'path@$path';
208+
209+
@override
210+
bool operator ==(Object other) =>
211+
other is PathDependency && other.path == path;
212+
213+
@override
214+
int get hashCode => path.hashCode;
191215
}
192216

193217
@JsonSerializable(disallowUnrecognizedKeys: true)
@@ -204,6 +228,15 @@ class HostedDependency extends Dependency {
204228

205229
@override
206230
String get _info => version.toString();
231+
232+
@override
233+
bool operator ==(Object other) =>
234+
other is HostedDependency &&
235+
other.version == version &&
236+
other.hosted == hosted;
237+
238+
@override
239+
int get hashCode => Object.hash(version, hosted);
207240
}
208241

209242
@JsonSerializable(disallowUnrecognizedKeys: true)
@@ -240,6 +273,13 @@ class HostedDetails {
240273

241274
throw ArgumentError.value(data, 'hosted', 'Must be a Map or String.');
242275
}
276+
277+
@override
278+
bool operator ==(Object other) =>
279+
other is HostedDetails && other.name == name && other.url == url;
280+
281+
@override
282+
int get hashCode => Object.hash(name, url);
243283
}
244284

245285
VersionConstraint _constraintFromString(String? input) =>

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: pubspec_parse
2-
version: 1.2.4-wip
2+
version: 1.3.0-wip
33
description: >-
44
Simple package for parsing pubspec.yaml files with a type-safe API and rich
55
error reporting.

0 commit comments

Comments
 (0)