Skip to content

Commit fe25a29

Browse files
authored
Setup lint config (#13)
* main repo * rustc lints for all packages * More lints * adjust config
1 parent bc3045a commit fe25a29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+430
-325
lines changed

Cargo.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,24 @@ jsonrpcmsg = "0.1.2"
6262
# Testing
6363
expect-test = "1.5"
6464
tokio-test = "0.4"
65+
66+
[workspace.lints.rust]
67+
future_incompatible = { level = "warn", priority = -1 }
68+
let-underscore = "warn"
69+
missing_debug_implementations = "warn"
70+
# missing_docs = "warn"
71+
nonstandard_style = { level = "warn", priority = -1 }
72+
rust_2018_idioms = { level = "warn", priority = -1 }
73+
unused = { level = "warn", priority = -1 }
74+
75+
[workspace.lints.clippy]
76+
# cargo = { level = "warn", priority = -1 }
77+
pedantic = { level = "warn", priority = -1 }
78+
doc_markdown = "allow"
79+
missing_errors_doc = "allow"
80+
missing_panics_doc = "allow"
81+
needless_pass_by_value = "allow"
82+
similar_names = "allow"
83+
struct_field_names = "allow"
84+
too_many_lines = "allow"
85+
wildcard_imports = "allow"

rust-toolchain.toml

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/agent-client-protocol/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,6 @@ tokio = { version = "1", features = [
4545
"sync",
4646
] }
4747
tokio-util = { version = "0.7", features = ["compat"] }
48+
49+
[lints]
50+
workspace = true

src/agent-client-protocol/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub use stream_broadcast::{
2626
/// prompts, and managing the agent lifecycle.
2727
///
2828
/// See protocol docs: [Client](https://agentclientprotocol.com/protocol/overview#client)
29+
#[derive(Debug)]
2930
pub struct ClientSideConnection {
3031
conn: RpcConnection<ClientSide, AgentSide>,
3132
}
@@ -177,7 +178,7 @@ impl Agent for ClientSideConnection {
177178
/// are incoming vs outgoing from the client's perspective.
178179
///
179180
/// See protocol docs: [Communication Model](https://agentclientprotocol.com/protocol/overview#communication-model)
180-
#[derive(Clone)]
181+
#[derive(Clone, Debug)]
181182
pub struct ClientSide;
182183

183184
impl Side for ClientSide {
@@ -316,6 +317,7 @@ impl<T: Client> MessageHandler<ClientSide> for T {
316317
/// and sending session updates.
317318
///
318319
/// See protocol docs: [Agent](https://agentclientprotocol.com/protocol/overview#agent)
320+
#[derive(Debug)]
319321
pub struct AgentSideConnection {
320322
conn: RpcConnection<AgentSide, ClientSide>,
321323
}
@@ -482,7 +484,7 @@ impl Client for AgentSideConnection {
482484
/// are incoming vs outgoing from the agent's perspective.
483485
///
484486
/// See protocol docs: [Communication Model](https://agentclientprotocol.com/protocol/overview#communication-model)
485-
#[derive(Clone)]
487+
#[derive(Clone, Debug)]
486488
pub struct AgentSide;
487489

488490
impl Side for AgentSide {

src/agent-client-protocol/src/rpc.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ use serde_json::value::RawValue;
2828

2929
use super::stream_broadcast::{StreamBroadcast, StreamReceiver, StreamSender};
3030

31+
#[derive(Debug)]
3132
pub(crate) struct RpcConnection<Local: Side, Remote: Side> {
3233
outgoing_tx: UnboundedSender<OutgoingMessage<Local, Remote>>,
3334
pending_responses: Arc<Mutex<HashMap<RequestId, PendingResponse>>>,
3435
next_id: AtomicI64,
3536
broadcast: StreamBroadcast,
3637
}
3738

39+
#[derive(Debug)]
3840
struct PendingResponse {
3941
deserialize: fn(&serde_json::value::RawValue) -> Result<Box<dyn Any + Send>>,
4042
respond: oneshot::Sender<Result<Box<dyn Any + Send>>>,
@@ -182,7 +184,7 @@ where
182184
}
183185
log::trace!("recv: {}", &incoming_line);
184186

185-
match serde_json::from_str::<RawIncomingMessage>(&incoming_line) {
187+
match serde_json::from_str::<RawIncomingMessage<'_>>(&incoming_line) {
186188
Ok(message) => {
187189
if let Some(id) = message.id {
188190
if let Some(method) = message.method {
@@ -299,7 +301,7 @@ where
299301
}
300302
}
301303

302-
#[derive(Deserialize)]
304+
#[derive(Debug, Deserialize)]
303305
pub struct RawIncomingMessage<'a> {
304306
id: Option<RequestId>,
305307
method: Option<&'a str>,
@@ -308,6 +310,7 @@ pub struct RawIncomingMessage<'a> {
308310
error: Option<Error>,
309311
}
310312

313+
#[derive(Debug)]
311314
pub enum IncomingMessage<Local: Side> {
312315
Request {
313316
id: RequestId,

src/elizacp/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ sacp-tokio = { version = "1.0.0", path = "../sacp-tokio" }
3636

3737
[dev-dependencies]
3838
expect-test.workspace = true
39+
40+
[lints]
41+
workspace = true

src/elizacp/src/eliza.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct Pattern {
2020
}
2121

2222
/// The Eliza chatbot engine.
23+
#[derive(Debug)]
2324
pub struct Eliza {
2425
patterns: Vec<Pattern>,
2526
reflections: HashMap<String, String>,
@@ -29,11 +30,13 @@ pub struct Eliza {
2930
impl Eliza {
3031
/// Create a new Eliza instance with classic patterns.
3132
/// Uses a fixed seed for deterministic testing.
33+
#[must_use]
3234
pub fn new() -> Self {
3335
Self::with_seed(42)
3436
}
3537

3638
/// Create a new Eliza instance with a specific seed.
39+
#[must_use]
3740
pub fn with_seed(seed: u64) -> Self {
3841
let mut eliza = Self {
3942
patterns: Vec::new(),
@@ -210,7 +213,10 @@ impl Eliza {
210213
let regex = Regex::new(pattern).expect("Invalid regex pattern");
211214
self.patterns.push(Pattern {
212215
pattern: regex,
213-
responses: responses.into_iter().map(|s| s.to_string()).collect(),
216+
responses: responses
217+
.into_iter()
218+
.map(std::string::ToString::to_string)
219+
.collect(),
214220
priority,
215221
});
216222
}
@@ -225,7 +231,7 @@ impl Eliza {
225231
self.reflections
226232
.get(&lower)
227233
.cloned()
228-
.unwrap_or_else(|| word.to_string())
234+
.unwrap_or_else(|| (*word).to_string())
229235
})
230236
.collect();
231237
reflected.join(" ")
@@ -291,10 +297,10 @@ mod tests {
291297
let eliza = Eliza::new();
292298

293299
let reflected = eliza.reflect("I am happy");
294-
expect![[r#"you are happy"#]].assert_eq(&reflected);
300+
expect![[r"you are happy"]].assert_eq(&reflected);
295301

296302
let reflected = eliza.reflect("my mother");
297-
expect![[r#"your mother"#]].assert_eq(&reflected);
303+
expect![[r"your mother"]].assert_eq(&reflected);
298304
}
299305

300306
#[test]
@@ -334,8 +340,7 @@ mod tests {
334340
let response2 = eliza2.respond(input);
335341
assert_eq!(
336342
response1, response2,
337-
"Responses should be identical for input: {}",
338-
input
343+
"Responses should be identical for input: {input}"
339344
);
340345
}
341346

src/elizacp/src/lib.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl ElizaAgent {
4343
tracing::info!("Ended session: {}", session_id);
4444
}
4545

46-
async fn handle_new_session(
46+
fn handle_new_session(
4747
&self,
4848
request: NewSessionRequest,
4949
request_cx: sacp::JrRequestCx<NewSessionResponse>,
@@ -65,7 +65,7 @@ impl ElizaAgent {
6565
request_cx.respond(response)
6666
}
6767

68-
async fn handle_load_session(
68+
fn handle_load_session(
6969
&self,
7070
request: LoadSessionRequest,
7171
request_cx: sacp::JrRequestCx<LoadSessionResponse>,
@@ -85,7 +85,7 @@ impl ElizaAgent {
8585
request_cx.respond(response)
8686
}
8787

88-
async fn handle_prompt_request(
88+
fn handle_prompt_request(
8989
&self,
9090
request: PromptRequest,
9191
request_cx: sacp::JrRequestCx<PromptResponse>,
@@ -105,10 +105,7 @@ impl ElizaAgent {
105105
let response_text = self
106106
.get_response(session_id, &input_text)
107107
.unwrap_or_else(|| {
108-
format!(
109-
"Error: Session {} not found. Please start a new session.",
110-
session_id
111-
)
108+
format!("Error: Session {session_id} not found. Please start a new session.")
112109
});
113110

114111
tracing::debug!("Eliza response: {}", response_text);
@@ -159,34 +156,29 @@ pub async fn run_elizacp(transport: impl Component + 'static) -> Result<(), sacp
159156

160157
request_cx.respond(InitializeResponse {
161158
protocol_version: initialize.protocol_version,
162-
agent_capabilities: AgentCapabilities {
163-
load_session: Default::default(),
164-
prompt_capabilities: Default::default(),
165-
mcp_capabilities: Default::default(),
166-
meta: Default::default(),
167-
},
168-
auth_methods: Default::default(),
169-
agent_info: Default::default(),
170-
meta: Default::default(),
159+
agent_capabilities: AgentCapabilities::default(),
160+
auth_methods: Vec::default(),
161+
agent_info: Option::default(),
162+
meta: None,
171163
})
172164
}
173165
})
174166
.on_receive_request({
175167
let agent = agent.clone();
176168
async move |request: NewSessionRequest, request_cx| {
177-
agent.handle_new_session(request, request_cx).await
169+
agent.handle_new_session(request, request_cx)
178170
}
179171
})
180172
.on_receive_request({
181173
let agent = agent.clone();
182174
async move |request: LoadSessionRequest, request_cx| {
183-
agent.handle_load_session(request, request_cx).await
175+
agent.handle_load_session(request, request_cx)
184176
}
185177
})
186178
.on_receive_request({
187179
let agent = agent.clone();
188180
async move |request: PromptRequest, request_cx| {
189-
agent.handle_prompt_request(request, request_cx).await
181+
agent.handle_prompt_request(request, request_cx)
190182
}
191183
})
192184
.connect_to(transport)?

src/sacp-conductor/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ schemars.workspace = true
4141
sacp-rmcp = { path = "../sacp-rmcp" }
4242
sacp-test = { path = "../sacp-test" }
4343
sacp-tokio = { path = "../sacp-tokio" }
44+
45+
[lints]
46+
workspace = true

0 commit comments

Comments
 (0)