Skip to content

Commit 7760911

Browse files
committed
chore: Apply more lints
1 parent f9f5605 commit 7760911

File tree

8 files changed

+83
-57
lines changed

8 files changed

+83
-57
lines changed

bindings/python/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
unused_qualifications,
2222
variant_size_differences,
2323
rust_2018_idioms,
24-
rust_2018_compatibility
24+
rust_2018_compatibility,
25+
rust_2021_compatibility
2526
)]
27+
#[allow(clippy::module_name_repetitions)]
2628
use ::css_inline as rust_inline;
2729
use pyo3::{create_exception, exceptions, prelude::*, types::PyList, wrap_pyfunction};
2830
use rayon::prelude::*;

bindings/ruby/ext/css_inline/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
missing_debug_implementations,
1717
trivial_casts,
1818
trivial_numeric_casts,
19+
unreachable_pub,
1920
unused_extern_crates,
2021
unused_import_braces,
2122
unused_qualifications,
2223
variant_size_differences,
2324
rust_2018_idioms,
24-
rust_2018_compatibility
25+
rust_2018_compatibility,
26+
rust_2021_compatibility
2527
)]
28+
#[allow(clippy::module_name_repetitions)]
2629
use css_inline as rust_inline;
2730
use magnus::{
2831
class, define_module, function, method,

bindings/wasm/src/lib.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@
1313
clippy::map_unwrap_or,
1414
clippy::trivially_copy_pass_by_ref,
1515
clippy::needless_pass_by_value,
16-
missing_docs,
1716
missing_debug_implementations,
1817
trivial_casts,
1918
trivial_numeric_casts,
19+
unreachable_pub,
2020
unused_extern_crates,
2121
unused_import_braces,
2222
unused_qualifications,
2323
variant_size_differences,
2424
rust_2018_idioms,
25-
rust_2018_compatibility
25+
rust_2018_compatibility,
26+
rust_2021_compatibility
2627
)]
28+
#[allow(clippy::module_name_repetitions)]
2729
use css_inline as rust_inline;
2830
use std::{
2931
borrow::Cow,
@@ -138,8 +140,15 @@ pub mod tests {
138140

139141
#[wasm_bindgen_test]
140142
fn default_config() {
141-
let result = inline("<html><head><style>h1 { color:red; }</style></head><body><h1>Test</h1></body></html>", JsValue::undefined()).expect("Inlines correctly");
142-
assert_eq!(result, "<html><head></head><body><h1 style=\"color:red;\">Test</h1></body></html>");
143+
let result = inline(
144+
"<html><head><style>h1 { color:red; }</style></head><body><h1>Test</h1></body></html>",
145+
JsValue::undefined(),
146+
)
147+
.expect("Inlines correctly");
148+
assert_eq!(
149+
result,
150+
"<html><head></head><body><h1 style=\"color:red;\">Test</h1></body></html>"
151+
);
143152
}
144153

145154
#[wasm_bindgen_test]
@@ -149,7 +158,11 @@ pub mod tests {
149158
..Options::default()
150159
};
151160
let options = serde_wasm_bindgen::to_value(&options).expect("Valid value");
152-
let result = inline("<html><head><style>h1 { color:red; }</style></head><body><h1>Test</h1></body></html>", options).expect("Inlines correctly");
161+
let result = inline(
162+
"<html><head><style>h1 { color:red; }</style></head><body><h1>Test</h1></body></html>",
163+
options,
164+
)
165+
.expect("Inlines correctly");
153166
assert_eq!(result, "<html><head><style>h1 { color:red; }</style></head><body><h1 style=\"color:red;\">Test</h1></body></html>");
154167
}
155168
}

css-inline/src/hasher.rs

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,38 @@ impl Hasher for NoHashHasher {
99
fn finish(&self) -> u64 {
1010
self.0
1111
}
12-
1312
fn write(&mut self, _: &[u8]) {
14-
panic!("Should not happen")
13+
unreachable!("Should not be used")
1514
}
16-
fn write_u8(&mut self, n: u8) {
17-
self.0 = u64::from(n)
15+
fn write_u8(&mut self, _: u8) {
16+
unreachable!("Should not be used")
1817
}
19-
fn write_u16(&mut self, n: u16) {
20-
self.0 = u64::from(n)
18+
fn write_u16(&mut self, _: u16) {
19+
unreachable!("Should not be used")
2120
}
22-
fn write_u32(&mut self, n: u32) {
23-
self.0 = u64::from(n)
21+
fn write_u32(&mut self, _: u32) {
22+
unreachable!("Should not be used")
2423
}
25-
fn write_u64(&mut self, n: u64) {
26-
self.0 = n
24+
fn write_u64(&mut self, _: u64) {
25+
unreachable!("Should not be used")
2726
}
28-
2927
fn write_usize(&mut self, n: usize) {
30-
self.0 = n as u64
28+
self.0 = n as u64;
3129
}
32-
fn write_i8(&mut self, n: i8) {
33-
self.0 = n as u64
30+
fn write_i8(&mut self, _: i8) {
31+
unreachable!("Should not be used")
3432
}
35-
fn write_i16(&mut self, n: i16) {
36-
self.0 = n as u64
33+
fn write_i16(&mut self, _: i16) {
34+
unreachable!("Should not be used")
3735
}
38-
fn write_i32(&mut self, n: i32) {
39-
self.0 = n as u64
36+
fn write_i32(&mut self, _: i32) {
37+
unreachable!("Should not be used")
4038
}
41-
fn write_i64(&mut self, n: i64) {
42-
self.0 = n as u64
39+
fn write_i64(&mut self, _: i64) {
40+
unreachable!("Should not be used")
4341
}
44-
45-
fn write_isize(&mut self, n: isize) {
46-
self.0 = n as u64
42+
fn write_isize(&mut self, _: isize) {
43+
unreachable!("Should not be used")
4744
}
4845
}
4946

@@ -52,34 +49,29 @@ mod tests {
5249
use super::NoHashHasher;
5350
use std::hash::Hasher;
5451

55-
#[test]
56-
fn hasher() {
57-
let mut hasher = NoHashHasher::default();
58-
hasher.write_u8(42);
59-
assert_eq!(hasher.0, 42);
60-
hasher.write_u16(42);
61-
assert_eq!(hasher.0, 42);
62-
hasher.write_u32(42);
63-
assert_eq!(hasher.0, 42);
64-
hasher.write_u64(42);
65-
assert_eq!(hasher.0, 42);
66-
hasher.write_usize(42);
67-
assert_eq!(hasher.0, 42);
68-
hasher.write_i8(42);
69-
assert_eq!(hasher.0, 42);
70-
hasher.write_i16(42);
71-
assert_eq!(hasher.0, 42);
72-
hasher.write_i32(42);
73-
assert_eq!(hasher.0, 42);
74-
hasher.write_i64(42);
75-
assert_eq!(hasher.0, 42);
76-
hasher.write_isize(42);
77-
assert_eq!(hasher.0, 42);
52+
macro_rules! test_panic {
53+
($($method:ident),+ $(,)?) => {
54+
$(
55+
mod $method {
56+
use super::NoHashHasher;
57+
use std::hash::Hasher;
58+
59+
#[test]
60+
#[should_panic]
61+
fn test_panic() {
62+
let mut hasher = NoHashHasher::default();
63+
hasher.$method(42);
64+
}
65+
}
66+
)+
67+
};
7868
}
7969

70+
test_panic!(write_u8, write_u16, write_u32, write_u64, write_i8, write_i16, write_i32, write_i64, write_isize);
71+
8072
#[test]
8173
#[should_panic]
82-
fn test_panic() {
74+
fn test_panic_write() {
8375
let mut hasher = NoHashHasher::default();
8476
hasher.write(b"a");
8577
}

css-inline/src/html/element.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,22 @@ impl<'a> Element<'a> {
3636
}
3737
}
3838
/// Qualified name of the element.
39+
#[inline]
3940
pub(crate) fn name(&self) -> &QualName {
4041
&self.data.name
4142
}
4243
/// Attributes of the element.
44+
#[inline]
4345
pub(crate) fn attributes(&self) -> &Attributes {
4446
&self.data.attributes
4547
}
4648
/// A reference to the element data.
49+
#[inline]
4750
pub(crate) fn data(&self) -> &'a ElementData {
4851
self.data
4952
}
5053
/// ID of the parent node of the element, if it exists.
54+
#[inline]
5155
pub(crate) fn parent(&self) -> Option<NodeId> {
5256
self.document[self.node_id].parent
5357
}
@@ -162,6 +166,7 @@ impl<'a> selectors::Element for Element<'a> {
162166
}
163167
}
164168

169+
#[allow(clippy::enum_glob_use)]
165170
fn match_non_ts_pseudo_class<F>(
166171
&self,
167172
pseudo: &PseudoClass,

css-inline/src/html/node.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub(crate) struct Node {
1515
}
1616

1717
impl Node {
18+
#[inline]
1819
pub(crate) fn new(data: NodeData) -> Node {
1920
Node {
2021
parent: None,
@@ -25,18 +26,21 @@ impl Node {
2526
data,
2627
}
2728
}
29+
#[inline]
2830
pub(crate) fn as_element(&self) -> Option<&ElementData> {
2931
match &self.data {
3032
NodeData::Element { element: data, .. } => Some(data),
3133
_ => None,
3234
}
3335
}
36+
#[inline]
3437
pub(crate) fn as_element_mut(&mut self) -> Option<&mut ElementData> {
3538
match &mut self.data {
3639
NodeData::Element { element: data, .. } => Some(data),
3740
_ => None,
3841
}
3942
}
43+
#[inline]
4044
pub(crate) fn as_not_ignored_element_mut(&mut self) -> Option<&mut ElementData> {
4145
match &mut self.data {
4246
NodeData::Element {
@@ -46,6 +50,7 @@ impl Node {
4650
_ => None,
4751
}
4852
}
53+
#[inline]
4954
pub(crate) fn as_text(&self) -> Option<&str> {
5055
match &self.data {
5156
NodeData::Text { text } => Some(&**text),
@@ -59,9 +64,11 @@ impl Node {
5964
pub(crate) struct NodeId(NonZeroUsize);
6065

6166
impl NodeId {
67+
#[inline]
6268
pub(super) fn new(value: usize) -> NodeId {
6369
NodeId(NonZeroUsize::new(value).expect("Value is zero"))
6470
}
71+
#[inline]
6572
pub(super) fn document_id() -> NodeId {
6673
NodeId::new(1)
6774
}
@@ -103,6 +110,7 @@ pub(crate) struct ElementData {
103110
}
104111

105112
impl ElementData {
113+
#[inline]
106114
pub(crate) fn new(name: QualName, attributes: Vec<html5ever::Attribute>) -> ElementData {
107115
ElementData {
108116
name,

css-inline/src/html/selectors/parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ impl<'i> Parser<'i> for SelectorParser {
99
type Impl = InlinerSelectors;
1010
type Error = SelectorParseErrorKind<'i>;
1111

12+
#[allow(clippy::enum_glob_use)]
1213
fn parse_non_ts_pseudo_class(
1314
&self,
1415
location: SourceLocation,

css-inline/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![doc = include_str!("../README.md")]
22
#![warn(
3+
clippy::pedantic,
34
clippy::doc_markdown,
45
clippy::redundant_closure,
56
clippy::explicit_iter_loop,
@@ -22,9 +23,10 @@
2223
unused_qualifications,
2324
variant_size_differences,
2425
rust_2018_idioms,
25-
rust_2018_compatibility
26+
rust_2018_compatibility,
27+
rust_2021_compatibility
2628
)]
27-
29+
#[allow(clippy::module_name_repetitions)]
2830
pub mod error;
2931
mod hasher;
3032
mod html;
@@ -468,7 +470,7 @@ fn merge_styles(
468470
let mut first = true;
469471
for style in &final_styles {
470472
if first {
471-
first = false
473+
first = false;
472474
} else {
473475
existing_style.push_char(';');
474476
}

0 commit comments

Comments
 (0)