Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(clippy): Apply more clippy lints #70

Merged
merged 2 commits into from
Jul 13, 2024

Conversation

sorairolake
Copy link
Contributor

@sorairolake sorairolake commented Jul 12, 2024

I applied clippy::cargo, clippy::nursery and clippy::pedantic. I also applied these automatically apply lint suggestions and fixed as many parts as possible that could be fixed manually. Also, functions which can be converted to const fn are converted to const fn.

Additionally, the following rustfmt options were applied:

This should not cause any breaking changes to the API.

src/bits.rs Outdated
Comment on lines 136 to 143
0b010__110__10, // 90
0b1__001_1010, // 154
0b1100__1011, // 203
0b0110_1101, // 109
0b01_1001_00, // 100
0b01__111_001, // 121
0b0_1110_001, // 113
0b1__0000000, // 128
0b0101_1010, // 90
0b1001_1010, // 154
0b1100_1011, // 203
0b0110_1101, // 109
0b0110_0100, // 100
0b0111_1001, // 121
0b0111_0001, // 113
0b1000_0000, // 128
Copy link
Owner

@kennytm kennytm Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert these and #[rustfmt::skip] or #[allow] them (whichever tool that tells you to make that change), these are intentionally separated like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted these. #[rustfmt::skip] or #[allow] are not added.

src/bits.rs Outdated
Comment on lines 289 to 303
assert_eq!(bits.into_bytes(), vec![0b0111_0000, 0b1001_0000]);
}

#[test]
fn test_899() {
let mut bits = Bits::new(Version::Normal(1));
assert_eq!(bits.push_eci_designator(899), Ok(()));
assert_eq!(bits.into_bytes(), vec![0b0111__10_00, 0b00111000, 0b0011__0000]);
assert_eq!(bits.into_bytes(), vec![0b0111_1000, 0b0011_1000, 0b0011_0000]);
}

#[test]
fn test_999999() {
let mut bits = Bits::new(Version::Normal(1));
assert_eq!(bits.push_eci_designator(999999), Ok(()));
assert_eq!(bits.into_bytes(), vec![0b0111__110_0, 0b11110100, 0b00100011, 0b1111__0000]);
assert_eq!(bits.push_eci_designator(999_999), Ok(()));
assert_eq!(bits.into_bytes(), vec![0b0111_1100, 0b1111_0100, 0b0010_0011, 0b1111_0000]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto for the binary literals

src/bits.rs Outdated
@@ -357,7 +358,7 @@ mod numeric_tests {
assert_eq!(bits.push_numeric_data(b"01234567"), Ok(()));
assert_eq!(
bits.into_bytes(),
vec![0b0001_0000, 0b001000_00, 0b00001100, 0b01010110, 0b01_100001, 0b1__0000000]
vec![0b0001_0000, 0b0010_0000, 0b0000_1100, 0b0101_0110, 0b0110_0001, 0b1000_0000]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

src/bits.rs Outdated
Comment on lines 372 to 380
0b0001_0000,
0b010000_00,
0b00001100,
0b01010110,
0b01_101010,
0b0100_0000,
0b0000_1100,
0b0101_0110,
0b0110_1010,
0b0110_1110,
0b000101_00,
0b11101010,
0b0101__0000,
0b0001_0100,
0b1110_1010,
0b0101_0000,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

src/bits.rs Outdated
0b0011_0111,
0b0000_1010,
0b0111_0101,
0b0010_1000,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

src/bits.rs Outdated
@@ -522,7 +523,7 @@ mod byte_tests {
0b1010_1011,
0b1100_1101,
0b1110_1111,
0b0000__0000,
0b0000_0000,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

src/bits.rs Outdated
@@ -577,7 +578,7 @@ mod kanji_tests {
fn test_iso_18004_example() {
let mut bits = Bits::new(Version::Normal(1));
assert_eq!(bits.push_kanji_data(b"\x93\x5f\xe4\xaa"), Ok(()));
assert_eq!(bits.into_bytes(), vec![0b1000_0000, 0b0010_0110, 0b11001111, 0b1_1101010, 0b101010__00]);
assert_eq!(bits.into_bytes(), vec![0b1000_0000, 0b0010_0110, 0b1100_1111, 0b1110_1010, 0b1010_1000]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

src/bits.rs Outdated
Comment on lines 800 to 824
assert_eq!(bits.into_bytes(), vec![0b1011_1111, 0b0011_1110, 0b0011_0000]);
}

#[test]
fn test_no_padding() {
let mut bits = Bits::new(Version::Micro(1));
assert_eq!(bits.push_numeric_data(b"9999"), Ok(()));
assert_eq!(bits.push_terminator(EcLevel::L), Ok(()));
assert_eq!(bits.into_bytes(), vec![0b100_11111, 0b00111_100, 0b1_000__0000]);
assert_eq!(bits.into_bytes(), vec![0b1001_1111, 0b0011_1100, 0b1000_0000]);
}

#[test]
fn test_micro_version_1_half_byte_padding() {
let mut bits = Bits::new(Version::Micro(1));
assert_eq!(bits.push_numeric_data(b"999"), Ok(()));
assert_eq!(bits.push_terminator(EcLevel::L), Ok(()));
assert_eq!(bits.into_bytes(), vec![0b011_11111, 0b00111_000, 0b0000__0000]);
assert_eq!(bits.into_bytes(), vec![0b0111_1111, 0b0011_1000, 0b0000_0000]);
}

#[test]
fn test_micro_version_1_full_byte_padding() {
let mut bits = Bits::new(Version::Micro(1));
assert_eq!(bits.push_numeric_data(b""), Ok(()));
assert_eq!(bits.push_terminator(EcLevel::L), Ok(()));
assert_eq!(bits.into_bytes(), vec![0b000_000_00, 0b11101100, 0]);
assert_eq!(bits.into_bytes(), vec![0b0000_0000, 0b1110_1100, 0]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

src/bits.rs Outdated
])
);
}

#[test]
fn test_auto_mode_switch() {
let res = encode(b"123A", Version::Micro(2), EcLevel::L);
assert_eq!(res, Ok(vec![0b0_0011_000, 0b1111011_1, 0b001_00101, 0b0_00000__00, 0b11101100]));
assert_eq!(res, Ok(vec![0b0001_1000, 0b1111_0111, 0b0010_0101, 0b0000_0000, 0b1110_1100]));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

src/types.rs Outdated
Comment on lines 305 to 313
assert!(!(Numeric < Kanji));
assert!(!(Numeric >= Kanji));
assert!(matches!(Numeric.partial_cmp(&Kanji), None | Some(Ordering::Equal | Ordering::Greater)));
assert!(matches!(Numeric.partial_cmp(&Kanji), None | Some(Ordering::Less)));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??????

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sorairolake sorairolake requested a review from kennytm July 12, 2024 19:50
@sorairolake
Copy link
Contributor Author

@kennytm kennytm merged commit 0d1a336 into kennytm:master Jul 13, 2024
5 checks passed
@sorairolake sorairolake deleted the apply-more-clippy-lints branch July 13, 2024 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants