Skip to content

Commit

Permalink
Update (EmbarkStudios#26)
Browse files Browse the repository at this point in the history
* Add cargo deny check

* Update dependencies

* Fix clippy lints
  • Loading branch information
Jake-Shadle authored Oct 27, 2020
1 parent 42384ea commit d28fdca
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 20 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand All @@ -31,14 +31,21 @@ jobs:
command: clippy
args: --lib --tests -- -D warnings

deny-check:
name: cargo-deny check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: EmbarkStudios/cargo-deny-action@v1

test:
name: Test
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ include = [
]

[dependencies]
lazy_static = "1.4.0"
smallvec = "1.2.0"
lazy_static = "1.4"
smallvec = "1.4"

[dependencies.regex]
version = "1.3.4"
version = "1.4"
default-features = false
features = ["std"]

[dev-dependencies]
difference = "2.0.0"
difference = "2.0"
19 changes: 19 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[advisories]
unmaintained = "deny"
vulnerability = "deny"
unsound = "deny"
yanked = "deny"
ignore = [
]

[bans]
multiple-versions = "deny"

[licenses]
unlicensed = "deny"
# We want really high confidence when inferring licenses from text
confidence-threshold = 0.92
allow = [
"Apache-2.0",
"MIT",
]
73 changes: 59 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::{cmp, fmt};
/// && !bsd.is_copyleft()
/// );
/// ```
#[derive(Copy, Clone, Eq, Ord)]
#[derive(Copy, Clone, Eq)]
pub struct LicenseId {
/// The short identifier for the license
pub name: &'static str,
Expand All @@ -38,15 +38,22 @@ pub struct LicenseId {

impl PartialEq for LicenseId {
#[inline]
fn eq(&self, o: &LicenseId) -> bool {
fn eq(&self, o: &Self) -> bool {
self.index == o.index
}
}

impl Ord for LicenseId {
#[inline]
fn cmp(&self, o: &Self) -> cmp::Ordering {
self.index.cmp(&o.index)
}
}

impl PartialOrd for LicenseId {
#[inline]
fn partial_cmp(&self, o: &LicenseId) -> Option<cmp::Ordering> {
self.index.partial_cmp(&o.index)
fn partial_cmp(&self, o: &Self) -> Option<cmp::Ordering> {
Some(self.cmp(o))
}
}

Expand Down Expand Up @@ -115,7 +122,7 @@ impl fmt::Debug for LicenseId {
/// let exception_id = spdx::exception_id("LLVM-exception").unwrap();
/// assert!(!exception_id.is_deprecated());
/// ```
#[derive(Copy, Clone, Eq, Ord)]
#[derive(Copy, Clone, Eq)]
pub struct ExceptionId {
/// The short identifier for the exception
pub name: &'static str,
Expand All @@ -125,15 +132,22 @@ pub struct ExceptionId {

impl PartialEq for ExceptionId {
#[inline]
fn eq(&self, o: &ExceptionId) -> bool {
fn eq(&self, o: &Self) -> bool {
self.index == o.index
}
}

impl Ord for ExceptionId {
#[inline]
fn cmp(&self, o: &Self) -> cmp::Ordering {
self.index.cmp(&o.index)
}
}

impl PartialOrd for ExceptionId {
#[inline]
fn partial_cmp(&self, o: &ExceptionId) -> Option<cmp::Ordering> {
self.index.partial_cmp(&o.index)
fn partial_cmp(&self, o: &Self) -> Option<cmp::Ordering> {
Some(self.cmp(o))
}
}

Expand Down Expand Up @@ -215,7 +229,7 @@ impl fmt::Display for LicenseReq {
/// A single license term in a license expression, according to the SPDX spec.
/// This can be either an SPDX license, which is mapped to a LicenseId from
/// a valid SPDX short identifier, or else a document AND/OR license ref
#[derive(Debug, Clone, Eq, Ord)]
#[derive(Debug, Clone, Eq)]
pub enum LicenseItem {
/// A regular SPDX license id
SPDX {
Expand Down Expand Up @@ -247,6 +261,41 @@ impl LicenseItem {
}
}

impl Ord for LicenseItem {
fn cmp(&self, o: &Self) -> cmp::Ordering {
match (self, o) {
(
Self::SPDX {
id: a,
or_later: la,
},
Self::SPDX {
id: b,
or_later: lb,
},
) => match a.cmp(b) {
cmp::Ordering::Equal => la.cmp(lb),
o => o,
},
(
Self::Other {
doc_ref: ad,
lic_ref: al,
},
Self::Other {
doc_ref: bd,
lic_ref: bl,
},
) => match ad.cmp(bd) {
cmp::Ordering::Equal => al.cmp(bl),
o => o,
},
(Self::SPDX { .. }, Self::Other { .. }) => cmp::Ordering::Less,
(Self::Other { .. }, Self::SPDX { .. }) => cmp::Ordering::Greater,
}
}
}

impl PartialOrd for LicenseItem {
fn partial_cmp(&self, o: &Self) -> Option<cmp::Ordering> {
match (self, o) {
Expand All @@ -272,11 +321,7 @@ impl PartialOrd for LicenseItem {

impl PartialEq for LicenseItem {
fn eq(&self, o: &Self) -> bool {
if let Some(cmp::Ordering::Equal) = self.partial_cmp(o) {
true
} else {
false
}
matches!(self.partial_cmp(o), Some(cmp::Ordering::Equal))
}
}

Expand Down

0 comments on commit d28fdca

Please sign in to comment.