Skip to content

Commit 230c645

Browse files
committed
commands/lint: Extract duplicate name pass
1 parent 8676d47 commit 230c645

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/commands/lint.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,37 @@ where
188188

189189
info!("start");
190190

191-
let mut reader = fastq::fs::open(r1_src).map_err(|e| LintError::OpenFile(e, r1_src.into()))?;
191+
let (record_counter, duplicate_name_failure_count) = validate_duplicate_names(
192+
r1_src,
193+
record_definition_separator,
194+
lint_mode,
195+
duplicate_name_validator,
196+
)?;
197+
198+
failure_count += duplicate_name_failure_count;
199+
200+
info!(record_count = record_counter, "end");
201+
202+
Ok(failure_count)
203+
}
204+
205+
fn validate_duplicate_names<P>(
206+
src: P,
207+
record_definition_separator: Option<u8>,
208+
lint_mode: LintMode,
209+
mut duplicate_name_validator: DuplicateNameValidator,
210+
) -> Result<(usize, usize), LintError>
211+
where
212+
P: AsRef<Path>,
213+
{
214+
let src = src.as_ref();
215+
216+
let mut reader = fastq::fs::open(src).map_err(|e| LintError::OpenFile(e, src.into()))?;
192217

193218
let mut record = Record::default();
219+
194220
let mut record_counter = 0;
221+
let mut failure_count = 0;
195222

196223
while reader.read_record(&mut record)? != 0 {
197224
record.reset(record_definition_separator);
@@ -200,15 +227,13 @@ where
200227
.validate(&record)
201228
.unwrap_or_else(|e| {
202229
failure_count += 1;
203-
handle_validation_error(lint_mode, e, r1_src, record_counter);
230+
handle_validation_error(lint_mode, e, src, record_counter);
204231
});
205232

206233
record_counter += 1;
207234
}
208235

209-
info!(record_count = record_counter, "end");
210-
211-
Ok(failure_count)
236+
Ok((record_counter, failure_count))
212237
}
213238

214239
pub fn lint(args: LintArgs) -> Result<(), LintError> {

0 commit comments

Comments
 (0)