Skip to content

Commit

Permalink
Further clippy fixes (#55)
Browse files Browse the repository at this point in the history
* clippy: Enable `doc_markdown` lint.

Using `clippy::doc_markdown` is useful for catching mistakes in
the documentation comments, but since `AutoCAD` and `PostScript`
look like identifiers, it warns about those needing backticks.

Using `clippy.toml`, we can suppress those warnings, making this
lint useful.

* clippy: Fix `redundant_closure` lints.

* clippy: Fix `needless_borrow` lint.

* clippy: Fix `redundant_guard` lint.

* clippy: Fix `useless_vec` lints.

* clippy: Fix `needless_borrows_for_generic_args` lints.

* clippy: Remove unneceesary `allow(clippy::all)` from generated code.

The lints have all been addressed, so this can be removed now.
  • Loading branch information
waywardmonkeys authored Feb 23, 2024
1 parent a3a8192 commit 6954d33
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 15 deletions.
1 change: 0 additions & 1 deletion build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut file = File::create(generated_dir.join("mod.rs")).ok().unwrap();
file.write_all("// The contents of this file are automatically generated and should not be modified directly. See the `build` directory.
#[allow(clippy::all)]
pub mod entities;
pub mod header;
pub mod objects;
Expand Down
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
doc-valid-idents = ["AutoCAD", "PostScript", ".."]
2 changes: 1 addition & 1 deletion spec/TableSpec.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
</Table>
<Table Collection="layers" TypeString="LAYER">
<TableItem Name="Layer" ClassName="AcDbLayerTableRecord">
<Field Name="color" Code="62" Type="Color" DefaultValue="Color::from_index(7)" ReadConverter="read_color_value(&amp;mut item, {})" WriteConverter="{}.writable_color_value(&amp;item)" />
<Field Name="color" Code="62" Type="Color" DefaultValue="Color::from_index(7)" ReadConverter="read_color_value(&amp;mut item, {})" WriteConverter="{}.writable_color_value(item)" />
<Field Name="line_type_name" Code="6" Type="String" DefaultValue='String::from("CONTINUOUS")' WriteConverter="&amp;{}" />
<Field Name="is_layer_plotted" Code="290" Type="bool" DefaultValue="true" MinVersion="R2000" />
<Field Name="line_weight" Code="370" Type="LineWeight" DefaultValue="LineWeight::default()" ReadConverter="LineWeight::from_raw_value({})" WriteConverter="LineWeight::raw_value(&amp;{})" MinVersion="R2000" />
Expand Down
2 changes: 1 addition & 1 deletion src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ mod tests {
}
}

/// Test case derived from https://ezdxf.readthedocs.io/en/stable/dxfinternals/block_management.html
/// Test case derived from <https://ezdxf.readthedocs.io/en/stable/dxfinternals/block_management.html>
#[test]
fn write_block_r12_compat() {
let mut drawing = Drawing::new();
Expand Down
2 changes: 1 addition & 1 deletion src/code_pair_put_back.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Iterator for CodePairPutBack {
loop {
let pair = self.iter.next();
match pair {
Some(Ok(CodePair { code, .. })) if code == 999 => (), // a 999 comment code, try again
Some(Ok(CodePair { code: 999, .. })) => (), // a 999 comment code, try again
_ => return pair,
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
//! (<https://web.archive.org/web/20130509144333/http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=12272454&linkID=10809853>)
//!

#![warn(clippy::doc_markdown)]

extern crate encoding_rs;

#[macro_use]
Expand Down
11 changes: 4 additions & 7 deletions src/misc_tests/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use self::image::{DynamicImage, GenericImageView};
#[test]
fn read_string_with_control_characters() {
let drawing = parse_drawing(
vec![
[
"0",
"SECTION",
"2",
Expand Down Expand Up @@ -68,7 +68,7 @@ fn unsupported_section() {

#[test]
fn read_lf_and_crlf() {
let code_pairs = vec![
let code_pairs = [
"0", "SECTION", "2", "HEADER", "9", "$ACADVER", "1", "AC1027", "0", "ENDSEC", "0", "EOF",
];

Expand Down Expand Up @@ -440,7 +440,7 @@ fn write_unicode_as_ascii() {
drawing.header.project_name = String::from("è");
assert_contains(
&drawing,
vec![" 9", "$PROJECTNAME", " 1", "\\U+00E8"].join("\r\n"),
[" 9", "$PROJECTNAME", " 1", "\\U+00E8"].join("\r\n"),
);
}

Expand All @@ -449,10 +449,7 @@ fn write_unicode_as_utf8() {
let mut drawing = Drawing::new();
drawing.header.version = AcadVersion::R2007;
drawing.header.project_name = String::from("è");
assert_contains(
&drawing,
vec![" 9", "$PROJECTNAME", " 1", "è"].join("\r\n"),
);
assert_contains(&drawing, [" 9", "$PROJECTNAME", " 1", "è"].join("\r\n"));
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/misc_tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Oda {
pub fn convert_drawing(&self, drawing: &mut Drawing, version: AcadVersion) -> Drawing {
drawing.header.version = version;
drawing
.save_file(&format!("{}/drawing.dxf", self.input_path))
.save_file(format!("{}/drawing.dxf", self.input_path))
.unwrap();
// e.g.,
// ODAFileConverter.exe input_dir output_dir ACAD2000 DXF 0 1
Expand Down Expand Up @@ -151,7 +151,7 @@ impl AutoCAD {
pub fn convert_drawing(&self, drawing: &mut Drawing, version: AcadVersion) -> Drawing {
drawing.header.version = version;
drawing
.save_file(&format!("{}/input.dxf", self.temp_path))
.save_file(format!("{}/input.dxf", self.temp_path))
.unwrap();
// e.g.,
// accoreconsole.exe /i /path/to/input.dxf /b script.scr
Expand Down
4 changes: 2 additions & 2 deletions src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@ impl Object {
));
}
let code = if dict.is_hard_owner { 360 } else { 350 };
for key in dict.value_handles.keys().sorted_by(|a, b| Ord::cmp(a, b)) {
for key in dict.value_handles.keys().sorted_by(Ord::cmp) {
if let Some(value) = dict.value_handles.get(key) {
pairs.push(CodePair::new_string(3, key));
pairs.push(CodePair::new_string(code, &value.as_string()));
Expand All @@ -1569,7 +1569,7 @@ impl Object {
));
}
pairs.push(CodePair::new_string(340, &dict.default_handle.as_string()));
for key in dict.value_handles.keys().sorted_by(|a, b| Ord::cmp(a, b)) {
for key in dict.value_handles.keys().sorted_by(Ord::cmp) {
if let Some(value) = dict.value_handles.get(key) {
pairs.push(CodePair::new_string(3, key));
pairs.push(CodePair::new_string(350, &value.as_string()));
Expand Down

0 comments on commit 6954d33

Please sign in to comment.