Skip to content

Commit 4119591

Browse files
committed
better license; formatter; remove old svelte stuff
1 parent 362c704 commit 4119591

File tree

186 files changed

+661
-1615
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+661
-1615
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ wasm:
22
cd data-wasm && make
33

44
data:
5-
cd data && make
5+
cd data && make -B
66

77
format:
88
cd data && make format

data-lib/src/common.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::hash::Hash;
2-
31
use hashbrown::HashMap;
42
use serde::{Deserialize, Serialize};
53
use tsify::Tsify;

data-lib/src/license.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ pub struct Licenses {
3737
pub conditions: Vec<String>,
3838
pub limitations: Vec<String>,
3939
pub descriptions: LicenseDescriptionNested,
40-
}
40+
}

data-lib/src/plugin/data_array.rs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@ use wasm_bindgen::prelude::wasm_bindgen;
44

55
use crate::{
66
common::{
7-
CountMonthlyDataPoint, DownloadDataPoint, HallOfFameDataPoint,
8-
InactivityByReleaseDataPoint, IndividualDownloadDataPoint, OverviewDataPoint,
9-
RemovedByReleaseDataPoint, increment_named_data_points, to_percentage,
7+
increment_named_data_points, to_percentage, CountMonthlyDataPoint, DownloadDataPoint, HallOfFameDataPoint, InactivityByReleaseDataPoint, IndividualDownloadDataPoint, OverviewDataPoint, RemovedByReleaseDataPoint
108
},
119
date::Date,
1210
license::Licenses,
1311
plugin::{
14-
NamedDataPoint, PluginData, PluginExtraData, PluginLicenseDataPoints, PluginRepoDataPoints,
15-
full::FullPluginData,
12+
full::FullPluginData, LicenseInfo, NamedDataPoint, PluginData, PluginExtraData, PluginLicenseDataPoints, PluginRepoDataPoints
1613
},
1714
};
1815

@@ -513,22 +510,32 @@ impl PluginDataArrayView {
513510
return;
514511
};
515512

516-
let license_data = licenses
517-
.licenses
518-
.iter()
519-
.find(|l| l.spdx_id == repo_data.license_file);
513+
match &repo_data.file_license {
514+
LicenseInfo::Known(name) => {
515+
let license_data = licenses
516+
.licenses
517+
.iter()
518+
.find(|l| *name == l.spdx_id);
520519

521-
if let Some(license_data) = license_data {
522-
increment_named_data_points(&mut points.licenses, &license_data.spdx_id, 1.0);
520+
if let Some(license_data) = license_data {
521+
increment_named_data_points(&mut points.licenses, &license_data.spdx_id, 1.0);
523522

524-
for permission in &license_data.permissions {
525-
increment_named_data_points(&mut points.permissions, permission, 1.0);
526-
}
527-
for condition in &license_data.conditions {
528-
increment_named_data_points(&mut points.conditions, condition, 1.0);
523+
for permission in &license_data.permissions {
524+
increment_named_data_points(&mut points.permissions, permission, 1.0);
525+
}
526+
for condition in &license_data.conditions {
527+
increment_named_data_points(&mut points.conditions, condition, 1.0);
528+
}
529+
for limitation in &license_data.limitations {
530+
increment_named_data_points(&mut points.limitations, limitation, 1.0);
531+
}
532+
} else {
533+
// I think we should never hit this path, as we make sure that the license is known during data extraction.
534+
increment_named_data_points(&mut points.licenses, &LicenseInfo::Unrecognized.to_fancy_string(), 1.0);
535+
}
529536
}
530-
for limitation in &license_data.limitations {
531-
increment_named_data_points(&mut points.limitations, limitation, 1.0);
537+
other => {
538+
increment_named_data_points(&mut points.licenses, &other.to_fancy_string(), 1.0);
532539
}
533540
}
534541
});

data-lib/src/plugin/full.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use crate::{
55
common::{DownloadDataPoint, EntryChangeDataPoint, VersionDataPoint},
66
date::Date,
77
plugin::{
8-
FundingUrl, PluginData, PluginExtraData, PluginRepoData,
9-
warnings::{PluginWarning, get_plugin_warnings},
8+
warnings::{get_plugin_warnings, PluginWarning}, FundingUrl, LicenseInfo, PluginData, PluginExtraData, PluginRepoData
109
},
1110
};
1211

@@ -173,12 +172,12 @@ impl FullPluginData {
173172
.map(|v| v.initial_release_date.to_fancy_string())
174173
}
175174

176-
pub fn license_package_json(&self) -> Option<String> {
177-
self.repo_data().map(|r| r.package_json_license.clone())
175+
pub fn license_package_json(&self) -> String {
176+
LicenseInfo::from(self.repo_data().map(|r| &r.package_json_license)).to_fancy_string()
178177
}
179178

180-
pub fn license_file(&self) -> Option<String> {
181-
self.repo_data().map(|r| r.license_file.clone())
179+
pub fn license_file(&self) -> String {
180+
LicenseInfo::from(self.repo_data().map(|r| &r.file_license)).to_fancy_string()
182181
}
183182

184183
pub fn package_managers(&self) -> Option<Vec<String>> {

data-lib/src/plugin/mod.rs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ pub struct PluginRepoData {
7272
pub has_test_files: bool,
7373
pub has_beta_manifest: bool,
7474
pub file_type_counts: HashMap<String, usize>,
75-
pub package_json_license: String,
76-
pub license_file: String,
75+
/// The license identifier from the package.json file.
76+
pub package_json_license: LicenseInfo,
77+
/// The license identifier from the LICENSE file in the repository.
78+
pub file_license: LicenseInfo,
7779
pub manifest: PluginManifest,
7880
}
7981

@@ -109,3 +111,49 @@ pub struct PluginLicenseDataPoints {
109111
limitations: Vec<NamedDataPoint>,
110112
descriptions: LicenseDescriptionNested,
111113
}
114+
115+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
116+
pub enum LicenseInfo {
117+
Known(String),
118+
ExplicitlyUnlicensed,
119+
Unrecognized,
120+
NotFound,
121+
}
122+
123+
impl LicenseInfo {
124+
pub fn to_fancy_string(&self) -> String {
125+
match self {
126+
LicenseInfo::Known(name) => name.clone(),
127+
LicenseInfo::Unrecognized => "Unrecognized".to_string(),
128+
LicenseInfo::NotFound => "Not Found".to_string(),
129+
LicenseInfo::ExplicitlyUnlicensed => "Explicitly Unlicensed".to_string(),
130+
}
131+
}
132+
133+
pub fn matches(&self, other: &Self) -> bool {
134+
match (self, other) {
135+
(LicenseInfo::Known(name1), LicenseInfo::Known(name2)) => name1 == name2,
136+
_ => true, // Unrecognized and NotFound match anything
137+
}
138+
}
139+
140+
pub fn matches_identifier(&self, other: &str) -> bool {
141+
match self {
142+
LicenseInfo::Known(name1) => name1 == other,
143+
_ => false,
144+
}
145+
}
146+
}
147+
148+
impl From<Option<LicenseInfo>> for LicenseInfo {
149+
fn from(value: Option<LicenseInfo>) -> Self {
150+
value.unwrap_or(LicenseInfo::NotFound)
151+
}
152+
}
153+
154+
155+
impl From<Option<&LicenseInfo>> for LicenseInfo {
156+
fn from(value: Option<&LicenseInfo>) -> Self {
157+
value.cloned().unwrap_or(LicenseInfo::NotFound)
158+
}
159+
}

data-lib/src/plugin/warnings.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serde::Serialize;
22
use tsify::Tsify;
33

4-
use crate::{commit::StringCommit, date::Date, plugin::full::FullPluginData};
4+
use crate::{commit::StringCommit, date::Date, plugin::{full::FullPluginData, LicenseInfo}};
55

66
#[derive(Tsify, Debug, Clone, Serialize)]
77
#[tsify(into_wasm_abi)]
@@ -21,7 +21,7 @@ pub enum PluginWarning {
2121
Unlicensed(PluginWarningUnlicensed),
2222
NoLicense(PluginWarningNoLicense),
2323
MismatchedLicense(PluginWarningMismatchedLicense),
24-
MissingExtendedData(PLuginWarningMissingExtendedData),
24+
MissingExtendedData(PluginWarningMissingExtendedData),
2525
MissingRepoData(PluginWarningMissingRepoData),
2626
}
2727

@@ -78,7 +78,7 @@ pub struct PluginWarningMismatchedLicense {
7878

7979
#[derive(Tsify, Debug, Clone, Serialize)]
8080
#[tsify(into_wasm_abi)]
81-
pub struct PLuginWarningMissingExtendedData {
81+
pub struct PluginWarningMissingExtendedData {
8282
pub severity: PluginWarningSeverity,
8383
}
8484

@@ -202,27 +202,20 @@ fn get_license_warnings(data: &FullPluginData, warnings: &mut Vec<PluginWarning>
202202
return;
203203
};
204204

205-
if repo.license_file == "explicitly unlicensed" {
205+
if repo.file_license == LicenseInfo::Known("explicitly unlicensed".to_string()) {
206206
warnings.push(PluginWarning::Unlicensed(PluginWarningUnlicensed {
207207
severity: PluginWarningSeverity::CAUTION,
208208
}));
209-
} else if repo.license_file == "no license" {
209+
} else if repo.file_license == LicenseInfo::NotFound {
210210
warnings.push(PluginWarning::NoLicense(PluginWarningNoLicense {
211211
severity: PluginWarningSeverity::CAUTION,
212212
}));
213-
} else if repo.license_file != "unknown"
214-
&& repo.license_file != "not found"
215-
&& repo.package_json_license != "unknown"
216-
&& repo.package_json_license != "not found"
217-
&& repo.package_json_license != "no license"
218-
&& !repo.package_json_license.starts_with(&repo.license_file)
219-
&& !repo.license_file.starts_with(&repo.package_json_license)
220-
{
213+
} else if !repo.file_license.matches(&repo.package_json_license) {
221214
warnings.push(PluginWarning::MismatchedLicense(
222215
PluginWarningMismatchedLicense {
223216
severity: PluginWarningSeverity::CAUTION,
224-
license_file: repo.license_file.clone(),
225-
package_json_license: repo.package_json_license.clone(),
217+
license_file: repo.file_license.to_fancy_string(),
218+
package_json_license: repo.package_json_license.to_fancy_string(),
226219
},
227220
));
228221
}
@@ -231,7 +224,7 @@ fn get_license_warnings(data: &FullPluginData, warnings: &mut Vec<PluginWarning>
231224
fn get_missing_warnings(data: &FullPluginData, warnings: &mut Vec<PluginWarning>) {
232225
if data.extended.is_none() {
233226
warnings.push(PluginWarning::MissingExtendedData(
234-
PLuginWarningMissingExtendedData {
227+
PluginWarningMissingExtendedData {
235228
severity: PluginWarningSeverity::DANGER,
236229
},
237230
));

data-lib/src/release/data_array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use regex::Regex;
33
use wasm_bindgen::prelude::*;
44

55
use crate::{
6-
common::{StackedNamedDataPoint, increment_named_data_points},
6+
common::StackedNamedDataPoint,
77
iter_ext::{DedupExt, GroupByExt, SortExt},
88
release::{
99
ChangeLogChangeCategory, ChangelogChanges, ChangelogDataPoint, GithubReleaseInfo, OS,

data/out/licenses.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -985,26 +985,26 @@
985985
}
986986
],
987987
"permissions": [
988-
"commercial-use",
989988
"private-use",
990-
"modifications",
989+
"distribution",
991990
"patent-use",
992-
"distribution"
991+
"commercial-use",
992+
"modifications"
993993
],
994994
"conditions": [
995-
"network-use-disclose",
996-
"disclose-source",
997-
"include-copyright--source",
998-
"same-license--library",
999-
"same-license--file",
1000995
"document-changes",
996+
"same-license",
997+
"same-license--file",
998+
"include-copyright--source",
999+
"disclose-source",
10011000
"include-copyright",
1002-
"same-license"
1001+
"same-license--library",
1002+
"network-use-disclose"
10031003
],
10041004
"limitations": [
1005+
"patent-use",
10051006
"warranty",
10061007
"trademark-use",
1007-
"patent-use",
10081008
"liability"
10091009
],
10101010
"descriptions": {

data/out/plugin-data/chunk_0.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)