Skip to content

Commit e9d5014

Browse files
committed
🔨 chore: clear pedantic clippy lint backlog across codebase
Resolve accumulated clippy pedantic warnings spanning 53 files: - Add #[must_use] to ~60 public functions returning values callers should not silently discard - Add `# Errors` doc sections to all fallible public functions describing specific failure conditions - Replace .expect() panics with proper error propagation via .context() and pattern matching in changelog parsing - Use clone_into()/clone_from() over direct clone assignment to avoid intermediate allocations - Simplify .map().unwrap_or() chains to .map_or() - Generalize HashMap parameters with BuildHasher trait bounds for hasher flexibility in provider helpers - Flatten Result<Option<T>> to Option<T> where errors were never meaningfully produced (resolve_remote_head_base) - Use struct literal initialization with ..Default in tests - Suppress pedantic doc lints in test utility modules where full documentation rigor is unnecessary
1 parent 882b245 commit e9d5014

Some content is hidden

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

53 files changed

+581
-47
lines changed

src/agents/context.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub enum TaskContext {
6060
impl TaskContext {
6161
/// Create context for the gen (commit message) command.
6262
/// Always uses staged changes only.
63+
#[must_use]
6364
pub fn for_gen() -> Self {
6465
Self::Staged {
6566
include_unstaged: false,
@@ -68,6 +69,7 @@ impl TaskContext {
6869

6970
/// Create context for amending the previous commit.
7071
/// The agent will see the combined diff from HEAD^1 to staged state.
72+
#[must_use]
7173
pub fn for_amend(original_message: String) -> Self {
7274
Self::Amend { original_message }
7375
}
@@ -79,6 +81,10 @@ impl TaskContext {
7981
/// - `--to` on its own compares `<fallback-base>..to`
8082
/// - `--commit` is mutually exclusive with `--from/--to`
8183
/// - `--include-unstaged` is incompatible with range comparisons
84+
///
85+
/// # Errors
86+
///
87+
/// Returns an error when the provided flag combination is invalid.
8288
pub fn for_review(
8389
commit: Option<String>,
8490
from: Option<String>,
@@ -93,6 +99,10 @@ impl TaskContext {
9399
/// CLI and Studio should prefer a repo-aware base from `GitRepo::get_default_base_ref()`.
94100
/// This lets branch comparisons follow the repository's actual primary branch
95101
/// instead of relying on the legacy `"main"` fallback.
102+
///
103+
/// # Errors
104+
///
105+
/// Returns an error when the provided flag combination is invalid.
96106
pub fn for_review_with_base(
97107
commit: Option<String>,
98108
from: Option<String>,
@@ -136,13 +146,15 @@ impl TaskContext {
136146
/// - `from` only: Compare `from..HEAD`
137147
/// - `to` only: Compare `<fallback-base>..to`
138148
/// - Neither: Compare `<fallback-base>..HEAD`
149+
#[must_use]
139150
pub fn for_pr(from: Option<String>, to: Option<String>) -> Self {
140151
Self::for_pr_with_base(from, to, "main")
141152
}
142153

143154
/// Create PR context with an explicit default comparison base.
144155
///
145156
/// CLI and Studio should prefer a repo-aware base from `GitRepo::get_default_base_ref()`.
157+
#[must_use]
146158
pub fn for_pr_with_base(from: Option<String>, to: Option<String>, default_base: &str) -> Self {
147159
match (from, to) {
148160
(Some(f), Some(t)) => Self::Range { from: f, to: t },
@@ -165,6 +177,7 @@ impl TaskContext {
165177
///
166178
/// These always require a `from` reference; `to` defaults to HEAD.
167179
/// Automatically sets today's date if not provided.
180+
#[must_use]
168181
pub fn for_changelog(
169182
from: String,
170183
to: Option<String>,
@@ -180,11 +193,13 @@ impl TaskContext {
180193
}
181194

182195
/// Generate a human-readable prompt context string for the agent.
196+
#[must_use]
183197
pub fn to_prompt_context(&self) -> String {
184198
serde_json::to_string_pretty(self).unwrap_or_else(|_| format!("{self:?}"))
185199
}
186200

187201
/// Generate a hint for which `git_diff` call the agent should make.
202+
#[must_use]
188203
pub fn diff_hint(&self) -> String {
189204
match self {
190205
Self::Staged { include_unstaged } => {
@@ -208,11 +223,13 @@ impl TaskContext {
208223
}
209224

210225
/// Check if this context represents a range comparison (vs staged/single commit)
226+
#[must_use]
211227
pub fn is_range(&self) -> bool {
212228
matches!(self, Self::Range { .. })
213229
}
214230

215231
/// Check if this context involves unstaged changes
232+
#[must_use]
216233
pub fn includes_unstaged(&self) -> bool {
217234
matches!(
218235
self,
@@ -223,11 +240,13 @@ impl TaskContext {
223240
}
224241

225242
/// Check if this is an amend operation
243+
#[must_use]
226244
pub fn is_amend(&self) -> bool {
227245
matches!(self, Self::Amend { .. })
228246
}
229247

230248
/// Get the original commit message if this is an amend context
249+
#[must_use]
231250
pub fn original_message(&self) -> Option<&str> {
232251
match self {
233252
Self::Amend { original_message } => Some(original_message),

src/agents/core.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub struct AgentBackend {
1616
}
1717

1818
impl AgentBackend {
19+
#[must_use]
1920
pub fn new(provider_name: String, model: String, fast_model: String) -> Self {
2021
Self {
2122
provider_name,
@@ -25,6 +26,10 @@ impl AgentBackend {
2526
}
2627

2728
/// Create backend from Git-Iris configuration
29+
///
30+
/// # Errors
31+
///
32+
/// Returns an error when the configured provider name is invalid or missing configuration.
2833
pub fn from_config(config: &Config) -> Result<Self> {
2934
let provider: crate::providers::Provider = config
3035
.default_provider
@@ -53,17 +58,20 @@ pub struct AgentContext {
5358
}
5459

5560
impl AgentContext {
61+
#[must_use]
5662
pub fn new(config: Config, git_repo: GitRepo) -> Self {
5763
Self {
5864
config,
5965
git_repo: Arc::new(git_repo),
6066
}
6167
}
6268

69+
#[must_use]
6370
pub fn repo(&self) -> &GitRepo {
6471
&self.git_repo
6572
}
6673

74+
#[must_use]
6775
pub fn config(&self) -> &Config {
6876
&self.config
6977
}
@@ -80,6 +88,7 @@ pub struct TaskResult {
8088
}
8189

8290
impl TaskResult {
91+
#[must_use]
8392
pub fn success(message: String) -> Self {
8493
Self {
8594
success: true,
@@ -90,6 +99,7 @@ impl TaskResult {
9099
}
91100
}
92101

102+
#[must_use]
93103
pub fn success_with_data(message: String, data: serde_json::Value) -> Self {
94104
Self {
95105
success: true,
@@ -100,6 +110,7 @@ impl TaskResult {
100110
}
101111
}
102112

113+
#[must_use]
103114
pub fn failure(message: String) -> Self {
104115
Self {
105116
success: false,
@@ -110,11 +121,13 @@ impl TaskResult {
110121
}
111122
}
112123

124+
#[must_use]
113125
pub fn with_confidence(mut self, confidence: f64) -> Self {
114126
self.confidence = confidence;
115127
self
116128
}
117129

130+
#[must_use]
118131
pub fn with_execution_time(mut self, duration: std::time::Duration) -> Self {
119132
self.execution_time = Some(duration);
120133
self

src/agents/debug.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ fn debug_artifacts_dir() -> io::Result<PathBuf> {
6262
}
6363

6464
/// Write debug artifact with restrictive permissions and return the file path.
65+
///
66+
/// # Errors
67+
///
68+
/// Returns an error when the artifact directory or file cannot be created.
6569
pub fn write_debug_artifact(filename: &str, contents: &str) -> io::Result<PathBuf> {
6670
let mut path = debug_artifacts_dir()?;
6771
path.push(filename);

src/agents/iris.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,10 @@ pub struct IrisAgent {
451451

452452
impl IrisAgent {
453453
/// Create a new Iris agent with the given provider and model
454+
///
455+
/// # Errors
456+
///
457+
/// Returns an error when the provider or model configuration is invalid.
454458
pub fn new(provider: &str, model: &str) -> Result<Self> {
455459
Ok(Self {
456460
provider: provider.to_string(),
@@ -892,6 +896,10 @@ Guidelines:
892896
/// Execute a task with the given capability and user prompt
893897
///
894898
/// This now automatically uses structured output based on the capability type
899+
///
900+
/// # Errors
901+
///
902+
/// Returns an error when capability loading, agent construction, or generation fails.
895903
pub async fn execute_task(
896904
&mut self,
897905
capability: &str,
@@ -990,6 +998,10 @@ Guidelines:
990998
/// The callback receives `(chunk, aggregated_text)` for each delta.
991999
///
9921000
/// Returns the final structured response after streaming completes.
1001+
///
1002+
/// # Errors
1003+
///
1004+
/// Returns an error when capability loading, agent construction, or streaming fails.
9931005
pub async fn execute_task_streaming<F>(
9941006
&mut self,
9951007
capability: &str,
@@ -1227,11 +1239,16 @@ Guidelines:
12271239
}
12281240

12291241
/// Get the current capability being executed
1242+
#[must_use]
12301243
pub fn current_capability(&self) -> Option<&str> {
12311244
self.current_capability.as_deref()
12321245
}
12331246

12341247
/// Simple single-turn execution for basic queries
1248+
///
1249+
/// # Errors
1250+
///
1251+
/// Returns an error when the provider request fails.
12351252
pub async fn chat(&self, message: &str) -> Result<String> {
12361253
let agent = self.build_agent()?;
12371254
let response = agent.prompt(message).await?;
@@ -1244,6 +1261,7 @@ Guidelines:
12441261
}
12451262

12461263
/// Get provider configuration
1264+
#[must_use]
12471265
pub fn provider_config(&self) -> &HashMap<String, String> {
12481266
&self.provider_config
12491267
}
@@ -1278,6 +1296,7 @@ pub struct IrisAgentBuilder {
12781296

12791297
impl IrisAgentBuilder {
12801298
/// Create a new builder
1299+
#[must_use]
12811300
pub fn new() -> Self {
12821301
Self {
12831302
provider: "openai".to_string(),
@@ -1305,6 +1324,10 @@ impl IrisAgentBuilder {
13051324
}
13061325

13071326
/// Build the `IrisAgent`
1327+
///
1328+
/// # Errors
1329+
///
1330+
/// Returns an error when the configured provider or model cannot build an agent.
13081331
pub fn build(self) -> Result<IrisAgent> {
13091332
let mut agent = IrisAgent::new(&self.provider, &self.model)?;
13101333

src/agents/output_validator.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ impl<T> ValidationResult<T> {
4141
}
4242

4343
/// Validate and parse JSON with schema validation and error recovery
44+
///
45+
/// # Errors
46+
///
47+
/// Returns an error when the JSON cannot be parsed even after recovery attempts.
4448
pub fn validate_and_parse<T>(json_str: &str) -> Result<ValidationResult<T>>
4549
where
4650
T: JsonSchema + DeserializeOwned,

0 commit comments

Comments
 (0)