Skip to content

Commit 9cc51bf

Browse files
committed
Use Range (with start and end Position)
1 parent 690143e commit 9cc51bf

18 files changed

+360
-276
lines changed

lib/src/license.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'dart:io';
99
import 'package:meta/meta.dart';
1010
import 'package:path/path.dart' as p;
1111

12-
import 'license_detection/license_detector.dart' hide License;
12+
import 'license_detection/license_detector.dart' hide License, Range;
1313
import 'model.dart';
1414

1515
const _licenseFileNames = ['LICENSE'];
@@ -55,10 +55,12 @@ Future<List<License>> detectLicenseInContent(
5555
return License(
5656
path: relativePath,
5757
spdxIdentifier: e.identifier,
58-
start: Position(
59-
offset: e.start.offset, line: e.start.line, column: e.start.column),
60-
end: Position(
61-
offset: e.end.offset, line: e.end.line, column: e.end.column),
58+
range: Range(
59+
start: Position(
60+
offset: e.start.offset, line: e.start.line, column: e.start.column),
61+
end: Position(
62+
offset: e.end.offset, line: e.end.line, column: e.end.column),
63+
),
6264
);
6365
}).toList();
6466
}

lib/src/model.dart

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,21 +169,15 @@ class License {
169169
/// The SPDX identifier of the license.
170170
final String spdxIdentifier;
171171

172-
/// The start position of the recognized part.
172+
/// The range (start and end position) of the recognized part.
173173
///
174174
/// WARNING: this field is experimental, do not rely on it.
175-
final Position? start;
176-
177-
/// The end position of the recognized part.
178-
///
179-
/// WARNING: this field is experimental, do not rely on it.
180-
final Position? end;
175+
final Range? range;
181176

182177
License({
183178
required this.path,
184179
required this.spdxIdentifier,
185-
this.start,
186-
this.end,
180+
this.range,
187181
});
188182

189183
factory License.fromJson(Map<String, dynamic> json) =>
@@ -192,6 +186,24 @@ class License {
192186
Map<String, dynamic> toJson() => _$LicenseToJson(this);
193187
}
194188

189+
/// Describes a range in a source file.
190+
///
191+
/// WARNING: this class is experimental, do not rely on it.
192+
@JsonSerializable()
193+
class Range {
194+
final Position start;
195+
final Position end;
196+
197+
Range({
198+
required this.start,
199+
required this.end,
200+
});
201+
202+
factory Range.fromJson(Map<String, dynamic> json) => _$RangeFromJson(json);
203+
204+
Map<String, dynamic> toJson() => _$RangeToJson(this);
205+
}
206+
195207
/// Describes a position in a source file.
196208
///
197209
/// WARNING: this class is experimental, do not rely on it.

lib/src/model.g.dart

Lines changed: 13 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/goldens/end2end/_dummy_pkg-1.0.0-null-safety.1.json

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@
2424
{
2525
"path": "LICENSE",
2626
"spdxIdentifier": "BSD-3-Clause",
27-
"start": {
28-
"offset": 63,
29-
"line": 1,
30-
"column": 0
31-
},
32-
"end": {
33-
"offset": 1523,
34-
"line": 25,
35-
"column": 68
27+
"range": {
28+
"start": {
29+
"offset": 63,
30+
"line": 1,
31+
"column": 0
32+
},
33+
"end": {
34+
"offset": 1523,
35+
"line": 25,
36+
"column": 68
37+
}
3638
}
3739
}
3840
],
@@ -95,15 +97,17 @@
9597
{
9698
"path": "LICENSE",
9799
"spdxIdentifier": "BSD-3-Clause",
98-
"start": {
99-
"offset": 63,
100-
"line": 1,
101-
"column": 0
102-
},
103-
"end": {
104-
"offset": 1523,
105-
"line": 25,
106-
"column": 68
100+
"range": {
101+
"start": {
102+
"offset": 63,
103+
"line": 1,
104+
"column": 0
105+
},
106+
"end": {
107+
"offset": 1523,
108+
"line": 25,
109+
"column": 68
110+
}
107111
}
108112
}
109113
],

test/goldens/end2end/async-2.11.0.json

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,17 @@
3434
{
3535
"path": "LICENSE",
3636
"spdxIdentifier": "BSD-3-Clause",
37-
"start": {
38-
"offset": 44,
39-
"line": 2,
40-
"column": 0
41-
},
42-
"end": {
43-
"offset": 1503,
44-
"line": 26,
45-
"column": 68
37+
"range": {
38+
"start": {
39+
"offset": 44,
40+
"line": 2,
41+
"column": 0
42+
},
43+
"end": {
44+
"offset": 1503,
45+
"line": 26,
46+
"column": 68
47+
}
4648
}
4749
}
4850
],
@@ -133,15 +135,17 @@
133135
{
134136
"path": "LICENSE",
135137
"spdxIdentifier": "BSD-3-Clause",
136-
"start": {
137-
"offset": 44,
138-
"line": 2,
139-
"column": 0
140-
},
141-
"end": {
142-
"offset": 1503,
143-
"line": 26,
144-
"column": 68
138+
"range": {
139+
"start": {
140+
"offset": 44,
141+
"line": 2,
142+
"column": 0
143+
},
144+
"end": {
145+
"offset": 1503,
146+
"line": 26,
147+
"column": 68
148+
}
145149
}
146150
}
147151
],

test/goldens/end2end/audio_service-0.18.17.json

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,17 @@
7474
{
7575
"path": "LICENSE",
7676
"spdxIdentifier": "MIT",
77-
"start": {
78-
"offset": 14,
79-
"line": 3,
80-
"column": 0
81-
},
82-
"end": {
83-
"offset": 1036,
84-
"line": 19,
85-
"column": 9
77+
"range": {
78+
"start": {
79+
"offset": 14,
80+
"line": 3,
81+
"column": 0
82+
},
83+
"end": {
84+
"offset": 1036,
85+
"line": 19,
86+
"column": 9
87+
}
8688
}
8789
}
8890
],
@@ -213,15 +215,17 @@
213215
{
214216
"path": "LICENSE",
215217
"spdxIdentifier": "MIT",
216-
"start": {
217-
"offset": 14,
218-
"line": 3,
219-
"column": 0
220-
},
221-
"end": {
222-
"offset": 1036,
223-
"line": 19,
224-
"column": 9
218+
"range": {
219+
"start": {
220+
"offset": 14,
221+
"line": 3,
222+
"column": 0
223+
},
224+
"end": {
225+
"offset": 1036,
226+
"line": 19,
227+
"column": 9
228+
}
225229
}
226230
}
227231
],

test/goldens/end2end/bulma_min-0.7.4.json

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@
2525
{
2626
"path": "LICENSE",
2727
"spdxIdentifier": "MIT",
28-
"start": {
29-
"offset": 24,
30-
"line": 3,
31-
"column": 0
32-
},
33-
"end": {
34-
"offset": 1046,
35-
"line": 19,
36-
"column": 13
28+
"range": {
29+
"start": {
30+
"offset": 24,
31+
"line": 3,
32+
"column": 0
33+
},
34+
"end": {
35+
"offset": 1046,
36+
"line": 19,
37+
"column": 13
38+
}
3739
}
3840
}
3941
],
@@ -103,15 +105,17 @@
103105
{
104106
"path": "LICENSE",
105107
"spdxIdentifier": "MIT",
106-
"start": {
107-
"offset": 24,
108-
"line": 3,
109-
"column": 0
110-
},
111-
"end": {
112-
"offset": 1046,
113-
"line": 19,
114-
"column": 13
108+
"range": {
109+
"start": {
110+
"offset": 24,
111+
"line": 3,
112+
"column": 0
113+
},
114+
"end": {
115+
"offset": 1046,
116+
"line": 19,
117+
"column": 13
118+
}
115119
}
116120
}
117121
],

test/goldens/end2end/dnd-2.0.1.json

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@
3030
{
3131
"path": "LICENSE",
3232
"spdxIdentifier": "MIT",
33-
"start": {
34-
"offset": 59,
35-
"line": 4,
36-
"column": 0
37-
},
38-
"end": {
39-
"offset": 1097,
40-
"line": 20,
41-
"column": 9
33+
"range": {
34+
"start": {
35+
"offset": 59,
36+
"line": 4,
37+
"column": 0
38+
},
39+
"end": {
40+
"offset": 1097,
41+
"line": 20,
42+
"column": 9
43+
}
4244
}
4345
}
4446
],
@@ -64,8 +66,8 @@
6466
"title": "Follow Dart file conventions",
6567
"grantedPoints": 30,
6668
"maxPoints": 30,
67-
"status": "passed",
68-
"summary": "### [*] 10/10 points: Provide a valid `pubspec.yaml`\n\n### [*] 5/5 points: Provide a valid `README.md`\n\n### [*] 5/5 points: Provide a valid `CHANGELOG.md`\n\n### [*] 10/10 points: Use an OSI-approved license\n\nDetected license: `MIT`.\n"
69+
"status": "partial",
70+
"summary": "### [~] 10/10 points: Provide a valid `pubspec.yaml`\n\n<details>\n<summary>\nHomepage URL doesn't exist.\n</summary>\n\nAt the time of the analysis `https://code.makery.ch/library/dart-drag-and-drop/` was unreachable. Make sure that the website is reachable via [`HEAD`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD) requests.\n</details>\n\n### [*] 5/5 points: Provide a valid `README.md`\n\n### [*] 5/5 points: Provide a valid `CHANGELOG.md`\n\n### [*] 10/10 points: Use an OSI-approved license\n\nDetected license: `MIT`.\n"
6971
},
7072
{
7173
"id": "documentation",
@@ -117,15 +119,17 @@
117119
{
118120
"path": "LICENSE",
119121
"spdxIdentifier": "MIT",
120-
"start": {
121-
"offset": 59,
122-
"line": 4,
123-
"column": 0
124-
},
125-
"end": {
126-
"offset": 1097,
127-
"line": 20,
128-
"column": 9
122+
"range": {
123+
"start": {
124+
"offset": 59,
125+
"line": 4,
126+
"column": 0
127+
},
128+
"end": {
129+
"offset": 1097,
130+
"line": 20,
131+
"column": 9
132+
}
129133
}
130134
}
131135
],

0 commit comments

Comments
 (0)