Skip to content

Commit a5de8f7

Browse files
authored
Merge pull request #2 from redbadger/clippy
chore: update CI and fix clippy etc
2 parents 63d49f0 + cb1a99d commit a5de8f7

File tree

7 files changed

+88
-60
lines changed

7 files changed

+88
-60
lines changed

.github/workflows/ci.yaml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
on: [push, pull_request]
2-
31
name: CI
42

3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
59
jobs:
610
build:
711
name: Tests
@@ -11,17 +15,22 @@ jobs:
1115
- name: Checkout
1216
uses: actions/checkout@v2
1317

14-
- name: Test
15-
run: cargo test --workspace
18+
- uses: dtolnay/rust-toolchain@stable
19+
with:
20+
components: clippy, rustfmt
1621

17-
- name: Test with serde
18-
run: cargo test --workspace --features serde
22+
- name: Format check
23+
shell: bash
24+
run: cargo fmt --all --check
1925

20-
- name: Test with features
21-
run: cargo test --workspace --features uuid,chrono,visitor
26+
- name: Clippy (pedantic)
27+
shell: bash
28+
run: cargo clippy -- --no-deps -Dclippy::pedantic -Dwarnings
2229

23-
- name: Test with myers diff algo
24-
run: cargo test --workspace --no-default-features --features vec_diff_myers
30+
- uses: taiki-e/install-action@cargo-hack
31+
32+
- name: Test
33+
run: cargo hack --each-feature test --workspace
2534

2635
- name: Run example
2736
run: cargo run --example visitor --features visitor

Cargo.lock

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

Cargo.toml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,23 @@ thiserror = "1.0"
2121
uuid = { version = "1.11", optional = true }
2222

2323
[features]
24-
chrono = ["dep:chrono"] # impl Diffable on `chrono::DateTime`
25-
uuid = ["dep:uuid"] # impl Diffable on `uuid::Uuid`
26-
serde = ["dep:serde", "difficient-macros/serde_impl"] # add serde derives to derived structs
27-
visitor = ["serde", "difficient-macros/visitor_impl"] # add AcceptVisitor impl
24+
# impl Diffable on `chrono::DateTime`
25+
chrono = ["dep:chrono"]
2826

29-
# choose your vec diff algo
30-
vec_diff_myers = [] # is generally more efficient
31-
vec_diff_lcs = [] # can result in smaller diffs in certain circumstances
27+
# impl Diffable on `uuid::Uuid`
28+
uuid = ["dep:uuid"]
29+
30+
# add serde derives to derived structs
31+
serde = ["dep:serde", "difficient-macros/serde_impl"]
32+
33+
# add AcceptVisitor impl
34+
visitor = ["serde", "difficient-macros/visitor_impl"]
35+
36+
# choose your vec diff algorithm:
37+
# the default is lcs, which can result in smaller diffs in certain circumstances,
38+
# but you can choose myers instead, which may be more efficient
39+
vec_diff_myers = []
3240

33-
default = ["vec_diff_lcs"]
3441

3542
[dev-dependencies]
3643
pretty_assertions = "1.4.0"

difficient-macros/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ version = "0.1.0"
77
edition = "2024"
88

99
[dependencies]
10-
darling = "0.20.10"
10+
darling = "0.21.0"
1111
heck = "0.5.0"
12-
proc-macro2 = "1.0.86"
13-
quote = "1.0.36"
14-
syn = "2.0.72"
12+
proc-macro2 = "1.0.95"
13+
quote = "1.0.40"
14+
syn = "2.0.104"
1515

1616
[features]
1717
serde_impl = []
1818
visitor_impl = ["serde_impl"]
1919

2020
[dev-dependencies]
21-
pretty_assertions = "1.4.0"
22-
prettyplease = "0.2.20"
21+
pretty_assertions = "1.4.1"
22+
prettyplease = "0.2.36"

examples/visitor.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ impl difficient::Visitor for ChangeEmitter {
1616
self.location.pop().unwrap();
1717
}
1818
fn replaced<T: serde::Serialize>(&mut self, val: T) {
19-
use Enter::*;
2019
let mut path = String::new();
2120
for (ix, loc) in self.location.iter().enumerate() {
2221
match loc {
23-
NamedField { name, .. } => path.push_str(name),
24-
PositionalField(p) => path.push_str(&p.to_string()),
25-
Variant { name, .. } => path.push_str(name),
26-
MapKey(key) => path.push_str(&key),
27-
Index(key) => path.push_str(&key.to_string()),
22+
Enter::NamedField { name, .. } | Enter::Variant { name, .. } => path.push_str(name),
23+
Enter::PositionalField(p) => path.push_str(&p.to_string()),
24+
Enter::MapKey(key) => path.push_str(key),
25+
Enter::Index(key) => path.push_str(&key.to_string()),
2826
}
2927
if ix != self.location.len() - 1 {
3028
path.push('.');
@@ -83,6 +81,6 @@ fn main() {
8381

8482
println!("Changed paths:");
8583
for (path, val) in emitter.changes {
86-
println!("{path}: {val}")
84+
println!("{path}: {val}");
8785
}
8886
}

src/serde_visit.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ tuple_impl!(A 0);
162162

163163
macro_rules! kv_map_impl {
164164
($typ: ident, $bounds: ident) => {
165+
#[allow(
166+
clippy::implicit_hasher,
167+
reason = "Implementation is shared among HashMap and BTreeMap"
168+
)]
165169
impl<'a, K, V, U> AcceptVisitor for $typ<K, KvDiff<'a, V, U>>
166170
where
167171
K: $bounds + ToString + 'a,
@@ -200,7 +204,7 @@ pub mod tests {
200204
use serde::Serialize;
201205

202206
use super::*;
203-
use crate::{Diffable, Replace, tests::*};
207+
use crate::{tests::*, Diffable, Replace};
204208

205209
impl AcceptVisitor for ParentDiff<'_> {
206210
fn accept<V: Visitor>(&self, visitor: &mut V) {
@@ -337,7 +341,7 @@ pub mod tests {
337341
let loc = self.location.join(".");
338342
if let Ok(val) = serde_json::to_string(&val) {
339343
self.replaced_locs.push((loc, val));
340-
};
344+
}
341345
}
342346

343347
fn splice<T: serde::Serialize>(&mut self, from_index: usize, replace: usize, values: &[T]) {
@@ -355,14 +359,15 @@ pub mod tests {
355359
values,
356360
},
357361
));
358-
};
362+
}
359363
}
360364

361365
fn enter(&mut self, val: Enter) {
362366
match val {
363-
Enter::NamedField { name, .. } => self.location.push(name.into()),
364367
Enter::PositionalField(p) => self.location.push(p.to_string()),
365-
Enter::Variant { name, .. } => self.location.push(name.into()),
368+
Enter::NamedField { name, .. } | Enter::Variant { name, .. } => {
369+
self.location.push(name.into());
370+
}
366371
Enter::MapKey(k) => self.location.push(k),
367372
Enter::Index(ix) => self.location.push(ix.to_string()),
368373
}

src/vec.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
#[cfg(feature = "vec_diff_lcs")]
2-
use similar::algorithms::lcs as diff_algo;
3-
4-
#[cfg(feature = "vec_diff_myers")]
5-
use similar::algorithms::lcs as diff_algo;
6-
71
use similar::algorithms::{Capture, Compact, Replace as SimilarReplace};
82

93
use crate::{Apply, ApplyError, Diffable, Replace};
@@ -75,7 +69,7 @@ mod visitor_impls {
7569
Self::Unchanged => {}
7670
Self::Changed { changes } => {
7771
for chg in changes {
78-
chg.accept(visitor)
72+
chg.accept(visitor);
7973
}
8074
}
8175
Self::Replaced(r) => visitor.replaced(r),
@@ -90,7 +84,7 @@ mod visitor_impls {
9084
fn accept<V: crate::Visitor>(&self, visitor: &mut V) {
9185
match self {
9286
VecChange::Remove { at_index, count } => {
93-
visitor.splice::<T>(*at_index, *count, &[])
87+
visitor.splice::<T>(*at_index, *count, &[]);
9488
}
9589
VecChange::Insert { at_index, values } => visitor.splice(*at_index, 0, values),
9690
VecChange::Splice {
@@ -188,6 +182,7 @@ where
188182
{
189183
type Diff = VecDiff<'a, T, T::Diff>;
190184

185+
#[allow(clippy::too_many_lines)]
191186
fn diff(&self, other: &'a Self) -> Self::Diff {
192187
if self.is_empty() && other.is_empty() {
193188
// short circuit
@@ -205,7 +200,21 @@ where
205200
)]
206201
let rkeys: Vec<_> = other.iter().map(|v| v.key()).collect();
207202
let mut d = Compact::new(SimilarReplace::new(Capture::new()), &lkeys, &rkeys);
208-
diff_algo::diff(&mut d, &lkeys, 0..lkeys.len(), &rkeys, 0..rkeys.len()).unwrap();
203+
204+
if cfg!(feature = "vec_diff_myers") {
205+
similar::algorithms::myers::diff(
206+
&mut d,
207+
&lkeys,
208+
0..lkeys.len(),
209+
&rkeys,
210+
0..rkeys.len(),
211+
)
212+
.unwrap();
213+
} else {
214+
similar::algorithms::lcs::diff(&mut d, &lkeys, 0..lkeys.len(), &rkeys, 0..rkeys.len())
215+
.unwrap();
216+
}
217+
209218
let ops = d.into_inner().into_inner().into_ops();
210219
let n_ops = ops.len();
211220
let mut offset = 0isize;

0 commit comments

Comments
 (0)