Skip to content

Commit 69a1bdd

Browse files
authored
Enforce pedantic clippy lints (#134)
1 parent 93f4af7 commit 69a1bdd

29 files changed

Lines changed: 265 additions & 248 deletions

‎Cargo.toml‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@ edition = "2024"
99
repository = "https://github.com/sameer/svg2gcode"
1010
license = "MIT"
1111

12+
[workspace.lints.clippy]
13+
pedantic = { level = "warn", priority = -1 }
14+
15+
similar_names = "allow"
16+
doc_markdown = "allow"
17+
must_use_candidate = "allow"
18+
too_many_lines = "allow"
19+
cast_possible_truncation = "allow"
20+
cast_possible_wrap = "allow"
21+
cast_precision_loss = "allow"
22+
cast_sign_loss = "allow"
23+
struct_excessive_bools = "allow"
24+
return_self_not_must_use = "allow"
25+
missing_errors_doc = "allow"
26+
missing_panics_doc = "allow"
27+
items_after_statements = "allow"
28+
1229
[workspace.dependencies]
1330
codespan-reporting = "0.13"
1431
g-code = "0.6.0"

‎cli/Cargo.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ edition.workspace = true
77
repository.workspace = true
88
license.workspace = true
99

10+
[lints]
11+
workspace = true
12+
1013
[dependencies]
1114
svg2gcode = { path = "../g_code", version = "0.4.0", features = ["serde"] }
1215
env_logger = "0.11"

‎cli/src/main.rs‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ fn main() -> io::Result<()> {
236236
let config_json_bytes = serde_json::to_vec_pretty(&settings)?;
237237
if export_path.to_string_lossy() == "-" {
238238
return io::stdout().write_all(&config_json_bytes);
239-
} else {
240-
return File::create(export_path)?.write_all(&config_json_bytes);
241239
}
240+
241+
return File::create(export_path)?.write_all(&config_json_bytes);
242242
}
243243

244244
let options = {
@@ -266,20 +266,17 @@ fn main() -> io::Result<()> {
266266
ConversionOptions { dimensions }
267267
};
268268

269-
let input = match opt.file {
270-
Some(filename) => {
271-
let mut f = File::open(filename)?;
272-
let len = f.metadata()?.len();
273-
let mut input = String::with_capacity(len as usize + 1);
274-
f.read_to_string(&mut input)?;
275-
input
276-
}
277-
None => {
278-
info!("Reading from standard input");
279-
let mut input = String::new();
280-
io::stdin().read_to_string(&mut input)?;
281-
input
282-
}
269+
let input = if let Some(filename) = opt.file {
270+
let mut f = File::open(filename)?;
271+
let len = f.metadata()?.len();
272+
let mut input = String::with_capacity(len as usize + 1);
273+
f.read_to_string(&mut input)?;
274+
input
275+
} else {
276+
info!("Reading from standard input");
277+
let mut input = String::new();
278+
io::stdin().read_to_string(&mut input)?;
279+
input
283280
};
284281

285282
let snippets = [

‎g_code/Cargo.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ edition.workspace = true
77
repository.workspace = true
88
license.workspace = true
99

10+
[lints]
11+
workspace = true
12+
1013
[features]
1114
default = ["image"]
1215
serde = ["dep:serde", "g-code/serde", "svg2star/serde"]

‎g_code/src/config/mod.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pub struct GCodeConfig {
124124
impl Default for GCodeConfig {
125125
fn default() -> Self {
126126
Self {
127-
inner: Default::default(),
127+
inner: ConversionConfig::default(),
128128
tolerance: 0.002,
129129
feedrate: 300.0,
130130
}
@@ -146,11 +146,11 @@ pub struct SupportedFunctionality {
146146
#[derive(Debug, Default, Clone, PartialEq)]
147147
/// Operations performed after G-Code generation.
148148
pub struct PostprocessConfig {
149-
/// Convenience field for [g_code::emit::FormatOptions] field
149+
/// Convenience field for [`g_code::emit::FormatOptions`] field
150150
pub checksums: bool,
151-
/// Convenience field for [g_code::emit::FormatOptions] field
151+
/// Convenience field for [`g_code::emit::FormatOptions`] field
152152
pub line_numbers: bool,
153-
/// Convenience field for [g_code::emit::FormatOptions] field
153+
/// Convenience field for [`g_code::emit::FormatOptions`] field
154154
pub newline_before_comment: bool,
155155
}
156156

‎g_code/src/machine.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ impl<'input> Machine<'input> {
5151
program_begin_sequence: program_begin_sequence.unwrap_or_else(|| empty_snippet.clone()),
5252
program_end_sequence: program_end_sequence.unwrap_or_else(|| empty_snippet.clone()),
5353
empty_snippet,
54-
tool_state: Default::default(),
55-
distance_mode: Default::default(),
54+
tool_state: None,
55+
distance_mode: None,
5656
}
5757
}
5858

‎g_code/src/tests.rs‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn get_actual(
1616
circular_interpolation: bool,
1717
dimensions: [Option<Length>; 2],
1818
) -> Vec<Token<'_>> {
19-
let gcode_config = Default::default();
19+
let gcode_config = GCodeConfig::default();
2020
let options = ConversionOptions { dimensions };
2121
let document = roxmltree::Document::parse_with_options(
2222
input,
@@ -115,7 +115,7 @@ fn square_transformed_produces_expected_gcode() {
115115
.collect::<Vec<_>>();
116116
let actual = get_actual(square_transformed, false, [None; 2]);
117117

118-
assert_close(actual, expected)
118+
assert_close(actual, expected);
119119
}
120120

121121
#[test]
@@ -128,7 +128,7 @@ fn square_transformed_nested_produces_expected_gcode() {
128128
.collect::<Vec<_>>();
129129
let actual = get_actual(square_transformed, false, [None; 2]);
130130

131-
assert_close(actual, expected)
131+
assert_close(actual, expected);
132132
}
133133

134134
#[test]
@@ -153,7 +153,7 @@ fn circular_interpolation_produces_expected_gcode() {
153153
.collect::<Vec<_>>();
154154
let actual = get_actual(circular_interpolation, true, [None; 2]);
155155

156-
assert_close(actual, expected)
156+
assert_close(actual, expected);
157157
}
158158

159159
#[test]
@@ -191,7 +191,7 @@ fn shapes_produces_expected_gcode() {
191191
.collect::<Vec<_>>();
192192
let actual = get_actual(shapes, false, [None; 2]);
193193

194-
assert_close(actual, expected)
194+
assert_close(actual, expected);
195195
}
196196

197197
#[test]
@@ -203,7 +203,7 @@ fn use_defs_produces_expected_gcode() {
203203
.collect::<Vec<_>>();
204204
let actual = get_actual(svg, false, [None; 2]);
205205

206-
assert_close(actual, expected)
206+
assert_close(actual, expected);
207207
}
208208

209209
#[test]
@@ -215,7 +215,7 @@ fn use_xlink_href_produces_expected_gcode() {
215215
.collect::<Vec<_>>();
216216
let actual = get_actual(svg, false, [None; 2]);
217217

218-
assert_close(actual, expected)
218+
assert_close(actual, expected);
219219
}
220220

221221
#[test]
@@ -238,7 +238,7 @@ fn transform_origin_produces_expected_gcode() {
238238
.iter_emit_tokens()
239239
.collect::<Vec<_>>();
240240
let actual = get_actual(svg, false, [None; 2]);
241-
assert_close(actual, expected)
241+
assert_close(actual, expected);
242242
}
243243

244244
/// `transform-origin="5 5"` with `rotate(90)` should be identical to the
@@ -255,10 +255,10 @@ fn transform_origin_matches_manual_equivalent() {
255255
false,
256256
[None; 2],
257257
);
258-
assert_close(with_origin, manual)
258+
assert_close(with_origin, manual);
259259
}
260260

261-
/// Regression test for https://github.com/sameer/svg2gcode/issues/105
261+
/// Regression test for <https://github.com/sameer/svg2gcode/issues/105>
262262
#[test]
263263
fn issue_105_optimize_path_order_does_not_shrink_output() {
264264
let svg = include_str!("../tests/square.svg");
@@ -281,7 +281,7 @@ fn issue_105_optimize_path_order_does_not_shrink_output() {
281281
);
282282
let normal = svg_to_gcode(
283283
&document,
284-
&Default::default(),
284+
&GCodeConfig::default(),
285285
ConversionOptions::default(),
286286
machine.clone(),
287287
);

‎g_code/src/turtle.rs‎

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<'input> GCodeTurtle<'input> {
123123
}
124124
}
125125

126-
impl<'input> Turtle for GCodeTurtle<'input> {
126+
impl Turtle for GCodeTurtle<'_> {
127127
fn begin(&mut self) {
128128
self.program
129129
.append(&mut command!(UnitsMillimeters {}).into_token_vec());
@@ -181,67 +181,72 @@ impl<'input> Turtle for GCodeTurtle<'input> {
181181
.supported_functionality()
182182
.circular_interpolation
183183
{
184-
FlattenWithArcs::flattened(&svg_arc, self.arc_flattening_tolerance())
185-
.into_iter()
186-
.for_each(|segment| match segment {
184+
for segment in
185+
FlattenWithArcs::flattened(&svg_arc, self.arc_flattening_tolerance())
186+
{
187+
match segment {
187188
ArcOrLineSegment::Arc(arc) => {
188-
self.program.append(&mut self.circular_interpolation(arc))
189+
self.program.append(&mut self.circular_interpolation(arc));
189190
}
190191
ArcOrLineSegment::Line(line) => {
191192
self.line_to(line.to);
192193
}
193-
});
194+
}
195+
}
194196
} else {
195-
svg_arc
196-
.to_arc()
197-
.flattened(self.flattening_tolerance())
198-
.for_each(|point| self.program.append(&mut self.line_to(point)));
199-
};
197+
for point in svg_arc.to_arc().flattened(self.flattening_tolerance()) {
198+
self.program.append(&mut self.line_to(point));
199+
}
200+
}
200201
}
201202
DrawCommand::CubicBezier(cbs) => {
202203
if self
203204
.machine
204205
.supported_functionality()
205206
.circular_interpolation
206207
{
207-
FlattenWithArcs::<f64>::flattened(&cbs, self.arc_flattening_tolerance())
208-
.into_iter()
209-
.for_each(|segment| match segment {
208+
for segment in
209+
FlattenWithArcs::<f64>::flattened(&cbs, self.arc_flattening_tolerance())
210+
{
211+
match segment {
210212
ArcOrLineSegment::Arc(arc) => {
211-
self.program.append(&mut self.circular_interpolation(arc))
213+
self.program.append(&mut self.circular_interpolation(arc));
212214
}
213215
ArcOrLineSegment::Line(line) => {
214-
self.program.append(&mut self.line_to(line.to))
216+
self.program.append(&mut self.line_to(line.to));
215217
}
216-
});
218+
}
219+
}
217220
} else {
218-
cbs.flattened(self.flattening_tolerance())
219-
.for_each(|point| self.program.append(&mut self.line_to(point)));
220-
};
221+
for point in cbs.flattened(self.flattening_tolerance()) {
222+
self.program.append(&mut self.line_to(point));
223+
}
224+
}
221225
}
222226
DrawCommand::QuadraticBezier(qbs) => {
223227
if self
224228
.machine
225229
.supported_functionality()
226230
.circular_interpolation
227231
{
228-
FlattenWithArcs::<f64>::flattened(
232+
for segment in FlattenWithArcs::<f64>::flattened(
229233
&qbs.to_cubic(),
230234
self.arc_flattening_tolerance(),
231-
)
232-
.into_iter()
233-
.for_each(|segment| match segment {
234-
ArcOrLineSegment::Arc(arc) => {
235-
self.program.append(&mut self.circular_interpolation(arc))
236-
}
237-
ArcOrLineSegment::Line(line) => {
238-
self.program.append(&mut self.line_to(line.to))
235+
) {
236+
match segment {
237+
ArcOrLineSegment::Arc(arc) => {
238+
self.program.append(&mut self.circular_interpolation(arc));
239+
}
240+
ArcOrLineSegment::Line(line) => {
241+
self.program.append(&mut self.line_to(line.to));
242+
}
239243
}
240-
});
244+
}
241245
} else {
242-
qbs.flattened(self.flattening_tolerance())
243-
.for_each(|point| self.program.append(&mut self.line_to(point)));
244-
};
246+
for point in qbs.flattened(self.flattening_tolerance()) {
247+
self.program.append(&mut self.line_to(point));
248+
}
249+
}
245250
}
246251
DrawCommand::Comment(comment) => {
247252
self.program.push(Token::Comment {

‎star/Cargo.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ edition.workspace = true
77
repository.workspace = true
88
license.workspace = true
99

10+
[lints]
11+
workspace = true
12+
1013
[features]
1114
serde = ["dep:serde"]
1215
image = ["dep:image", "dep:base64"]

‎star/src/lower/length_serde.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Makes it possible to serialize an array of two optional [`svgtypes::Length`]s,
2-
//! used for [super::ConversionOptions::dimensions]
2+
//! used for [`super::ConversionOptions::dimensions`]
33
44
use serde::{
55
Deserialize, Deserializer, Serialize, Serializer,

0 commit comments

Comments
 (0)