Skip to content

Commit 58595bf

Browse files
committed
chore: enable some pedantic clippy lints and satisfy all lints
1 parent 3450b4f commit 58595bf

12 files changed

Lines changed: 64 additions & 59 deletions

File tree

Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,15 @@ strip = true
3535
codegen-units = 1
3636
lto = "fat"
3737
opt-level = 3
38+
39+
[lints.clippy]
40+
pedantic = { level = "warn", priority = -1 }
41+
uninlined_format_args.level = "allow"
42+
trivially_copy_pass_by_ref.level = "deny"
43+
items_after_statements = "allow"
44+
missing_errors_doc = "allow"
45+
missing_panics_doc = "allow"
46+
needless_pass_by_value = "allow"
47+
too_many_lines = "allow"
48+
cast_possible_truncation = "allow"
49+
must_use_candidate = "allow"

src/agent.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ pub async fn request_confirmation(request: RequestConfirmation, agent: AuthAgent
7373
r = agent.rx_request_confirmation.recv() => {
7474
match r {
7575
Ok(v) => {
76-
match v {
77-
true => Ok(()),
78-
false => Err(ReqError::Rejected)
79-
}
76+
if v { Ok(()) } else { Err(ReqError::Rejected) }
8077
}
8178
Err(_) => {
8279
Err(ReqError::Canceled)

src/app.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,16 @@ impl App {
136136
pub fn reset_devices_state(&mut self) {
137137
if let Some(selected_controller) = self.controller_state.selected() {
138138
let controller = &self.controllers[selected_controller];
139-
if !controller.paired_devices.is_empty() {
140-
self.paired_devices_state.select(Some(0));
141-
} else {
139+
if controller.paired_devices.is_empty() {
142140
self.paired_devices_state.select(None);
141+
} else {
142+
self.paired_devices_state.select(Some(0));
143143
}
144144

145-
if !controller.new_devices.is_empty() {
146-
self.new_devices_state.select(Some(0));
147-
} else {
145+
if controller.new_devices.is_empty() {
148146
self.new_devices_state.select(None);
147+
} else {
148+
self.new_devices_state.select(Some(0));
149149
}
150150
}
151151
}
@@ -162,7 +162,7 @@ impl App {
162162
frame.area()
163163
}
164164
}
165-
_ => frame.area(),
165+
Width::Auto => frame.area(),
166166
}
167167
}
168168

@@ -300,8 +300,8 @@ impl App {
300300
.iter()
301301
.map(|controller| {
302302
Row::new(vec![
303-
controller.name.to_string(),
304-
controller.alias.to_string(),
303+
controller.name.clone(),
304+
controller.alias.clone(),
305305
{
306306
if controller.is_powered {
307307
"On".to_string()
@@ -412,7 +412,7 @@ impl App {
412412
if d.is_favorite {
413413
STAR_SYMBOL.to_string()
414414
} else {
415-
"".to_string()
415+
String::new()
416416
},
417417
format!("{} {}", &d.icon, &d.alias),
418418
d.is_trusted.to_string(),
@@ -757,7 +757,9 @@ impl App {
757757

758758
// Update selection after removal
759759
if adapter_removed {
760-
if !self.controllers.is_empty() {
760+
if self.controllers.is_empty() {
761+
self.controller_state.select(None);
762+
} else {
761763
let i = match self.controller_state.selected() {
762764
Some(i) => {
763765
if i > 0 {
@@ -769,8 +771,6 @@ impl App {
769771
None => 0,
770772
};
771773
self.controller_state.select(Some(i));
772-
} else {
773-
self.controller_state.select(None);
774774
}
775775
}
776776

src/bluetooth.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub struct Controller {
1919
pub new_devices: Vec<Device>,
2020
}
2121

22+
#[allow(clippy::struct_excessive_bools, clippy::struct_field_names)]
2223
#[derive(Debug, Clone)]
2324
pub struct Device {
2425
device: BTDevice,
@@ -119,24 +120,21 @@ impl Controller {
119120
let dev = Device {
120121
device,
121122
addr,
122-
alias,
123123
icon,
124+
alias,
124125
is_paired,
126+
is_favorite,
125127
is_trusted,
126128
is_connected,
127-
is_favorite,
128129
battery_percentage,
129130
};
130131

131132
if dev.is_paired {
132133
paired_devices.push(dev);
134+
} else if is_mac_addr(&dev.alias) {
135+
devices_without_aliases.push(dev);
133136
} else {
134-
match is_mac_addr(&dev.alias) {
135-
// most device names without aliases may default to their mac addresses, but we should not
136-
// assume that to be 100% the case
137-
true => devices_without_aliases.push(dev),
138-
false => new_devices.push(dev),
139-
}
137+
new_devices.push(dev);
140138
}
141139
}
142140

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub enum Width {
4040

4141
struct WidthVisitor;
4242

43-
impl<'de> Visitor<'de> for WidthVisitor {
43+
impl Visitor<'_> for WidthVisitor {
4444
type Value = Width;
4545

4646
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {

src/handler.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use tokio::sync::mpsc::UnboundedSender;
1212

1313
use tui_input::backend::crossterm::EventHandler;
1414

15-
async fn toggle_connect(app: &mut App, sender: UnboundedSender<Event>) {
15+
fn toggle_connect(app: &mut App, sender: UnboundedSender<Event>) {
1616
if let Some(selected_controller) = app.controller_state.selected() {
1717
let controller = &app.controllers[selected_controller];
1818
if let Some(index) = app.paired_devices_state.selected() {
@@ -24,7 +24,7 @@ async fn toggle_connect(app: &mut App, sender: UnboundedSender<Event>) {
2424
Ok(is_connected) => {
2525
if is_connected {
2626
match device.disconnect().await {
27-
Ok(_) => {
27+
Ok(()) => {
2828
let _ = Notification::send(
2929
"Device disconnected".into(),
3030
NotificationLevel::Info,
@@ -41,7 +41,7 @@ async fn toggle_connect(app: &mut App, sender: UnboundedSender<Event>) {
4141
}
4242
} else {
4343
match device.connect().await {
44-
Ok(_) => {
44+
Ok(()) => {
4545
let _ = Notification::send(
4646
"Device connected".into(),
4747
NotificationLevel::Info,
@@ -92,7 +92,7 @@ async fn pair(app: &mut App, sender: UnboundedSender<Event>) {
9292

9393
tokio::spawn(async move {
9494
match device.pair().await {
95-
Ok(_) => {
95+
Ok(()) => {
9696
let _ = Notification::send(
9797
"Device paired".into(),
9898
NotificationLevel::Info,
@@ -101,7 +101,7 @@ async fn pair(app: &mut App, sender: UnboundedSender<Event>) {
101101

102102
let _ = sender.send(Event::NewPairedDevice(device.address()));
103103
match device.set_trusted(true).await {
104-
Ok(_) => {
104+
Ok(()) => {
105105
let _ = Notification::send(
106106
"Device trusted".into(),
107107
NotificationLevel::Info,
@@ -115,9 +115,9 @@ async fn pair(app: &mut App, sender: UnboundedSender<Event>) {
115115
sender.clone(),
116116
);
117117
}
118-
};
118+
}
119119
match device.connect().await {
120-
Ok(_) => {
120+
Ok(()) => {
121121
let _ = Notification::send(
122122
"Device connected".into(),
123123
NotificationLevel::Info,
@@ -131,7 +131,7 @@ async fn pair(app: &mut App, sender: UnboundedSender<Event>) {
131131
sender.clone(),
132132
);
133133
}
134-
};
134+
}
135135
}
136136
Err(e) => {
137137
let _ = Notification::send(
@@ -171,7 +171,7 @@ pub async fn handle_key_events(
171171
if let Some(index) = app.paired_devices_state.selected() {
172172
let device = &controller.paired_devices[index];
173173
match device.set_alias(app.new_alias.value().into()).await {
174-
Ok(_) => {
174+
Ok(()) => {
175175
Notification::send(
176176
"Set New Alias".into(),
177177
NotificationLevel::Info,
@@ -506,7 +506,7 @@ pub async fn handle_key_events(
506506
if let Some(index) = app.paired_devices_state.selected() {
507507
let addr = controller.paired_devices[index].addr;
508508
match controller.adapter.remove_device(addr).await {
509-
Ok(_) => {
509+
Ok(()) => {
510510
let _ = Notification::send(
511511
"Device unpaired".into(),
512512
NotificationLevel::Info,
@@ -526,8 +526,7 @@ pub async fn handle_key_events(
526526
}
527527

528528
// Connect / Disconnect
529-
KeyCode::Enter => toggle_connect(app, sender).await,
530-
KeyCode::Char(' ') => toggle_connect(app, sender).await,
529+
KeyCode::Enter | KeyCode::Char(' ') => toggle_connect(app, sender),
531530

532531
// Trust / Untrust
533532
KeyCode::Char(c) if c == config.paired_device.toggle_trust => {
@@ -547,7 +546,7 @@ pub async fn handle_key_events(
547546
.set_trusted(false)
548547
.await
549548
{
550-
Ok(_) => {
549+
Ok(()) => {
551550
let _ = Notification::send(
552551
"Device untrusted"
553552
.into(),
@@ -568,7 +567,7 @@ pub async fn handle_key_events(
568567
.set_trusted(true)
569568
.await
570569
{
571-
Ok(_) => {
570+
Ok(()) => {
572571
let _ = Notification::send(
573572
"Device trusted"
574573
.into(),
@@ -646,7 +645,7 @@ pub async fn handle_key_events(
646645
if is_pairable {
647646
match adapter.set_pairable(false).await
648647
{
649-
Ok(_) => {
648+
Ok(()) => {
650649
let _ = Notification::send(
651650
"Adapter unpairable".into(),
652651
NotificationLevel::Info,
@@ -663,7 +662,7 @@ pub async fn handle_key_events(
663662
}
664663
} else {
665664
match adapter.set_pairable(true).await {
666-
Ok(_) => {
665+
Ok(()) => {
667666
let _ = Notification::send(
668667
"Adapter pairable".into(),
669668
NotificationLevel::Info,
@@ -706,7 +705,7 @@ pub async fn handle_key_events(
706705
Ok(is_powered) => {
707706
if is_powered {
708707
match adapter.set_powered(false).await {
709-
Ok(_) => {
708+
Ok(()) => {
710709
let _ = Notification::send(
711710
"Adapter powered off"
712711
.into(),
@@ -724,7 +723,7 @@ pub async fn handle_key_events(
724723
}
725724
} else {
726725
match adapter.set_powered(true).await {
727-
Ok(_) => {
726+
Ok(()) => {
728727
let _ = Notification::send(
729728
"Adapter powered on".into(),
730729
NotificationLevel::Info,
@@ -770,7 +769,7 @@ pub async fn handle_key_events(
770769
.set_discoverable(false)
771770
.await
772771
{
773-
Ok(_) => {
772+
Ok(()) => {
774773
let _ = Notification::send(
775774
"Adapter undiscoverable"
776775
.into(),
@@ -791,7 +790,7 @@ pub async fn handle_key_events(
791790
.set_discoverable(true)
792791
.await
793792
{
794-
Ok(_) => {
793+
Ok(()) => {
795794
let _ = Notification::send(
796795
"Adapter discoverable"
797796
.into(),
@@ -829,8 +828,7 @@ pub async fn handle_key_events(
829828
FocusedBlock::NewDevices => {
830829
// Pair new device
831830
match key_event.code {
832-
KeyCode::Enter => pair(app, sender).await,
833-
KeyCode::Char(' ') => pair(app, sender).await,
831+
KeyCode::Enter | KeyCode::Char(' ') => pair(app, sender).await,
834832
_ => {}
835833
}
836834
}

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async fn main() -> AppResult<()> {
1717

1818
let config_file_path = args.config_path.map(|config_path| {
1919
if config_path.exists() {
20-
config_path.to_owned()
20+
config_path.clone()
2121
} else {
2222
eprintln!("Config file not found");
2323
exit(1);
@@ -48,7 +48,7 @@ async fn main() -> AppResult<()> {
4848
tui.events.sender.clone(),
4949
config.clone(),
5050
)
51-
.await?
51+
.await?;
5252
}
5353
Event::Notification(notification) => {
5454
app.notifications.push(notification);

src/notification.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@ mod tests {
129129
}
130130

131131
#[rstest]
132-
#[should_panic]
132+
#[should_panic(expected = "File name too long")]
133133
fn render_bad(
134134
#[values(
135135
"extremely long WITHOUT newline Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed id mauris sit amet libero convallis fringilla quis non augue. In sollicitudin quam sed magna finibus, vitae malesuada magna porttitor. Pellentesque in dictum dui. Nullam nec mi venenatis, faucibus odio eget, molestie nisi. Fusce velit nibh, euismod vel lectus id, placerat.",
136-
r#"extremely long WITH newline Lorem ipsum dolor sit amet, consectetur
136+
r"extremely long WITH newline Lorem ipsum dolor sit amet, consectetur
137137
adipiscing elit. Sed id mauris sit amet libero convallis fringilla quis non
138138
augue. In sollicitudin quam sed magna finibus, vitae malesuada magna porttitor.
139139
Pellentesque in dictum dui. Nullam nec mi venenatis, faucibus odio eget, molestie
140-
nisi. Fusce velit nibh, euismod vel lectus id, placerat."#
140+
nisi. Fusce velit nibh, euismod vel lectus id, placerat."
141141
)]
142142
message_str: &'static str,
143143
#[values(

src/requests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl Requests {
3838
}
3939
}
4040

41-
fn pad_str<'a>(input: &'a str, length: usize) -> Cow<'a, str> {
41+
fn pad_str(input: &str, length: usize) -> Cow<'_, str> {
4242
let current_length = input.chars().count();
4343
if current_length >= length {
4444
Cow::Borrowed(input)

src/requests/enter_passkey.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl EnterPasskey {
110110
}
111111
}
112112

113-
_ => {
113+
FocusedSection::Input => {
114114
self.passkey
115115
.field
116116
.handle_event(&crossterm::event::Event::Key(key_event));

0 commit comments

Comments
 (0)