Skip to content

Commit 5d6f0ea

Browse files
committed
commands/lint: Support the duplicate name validator for single inputs
Closes #47.
1 parent 230c645 commit 5d6f0ea

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
the names validator (P001). If P001 is disabled, it will now get
3333
re-enabled.
3434

35+
* commands/lint: Support the duplicate name validator for single inputs
36+
([#47]).
37+
3538
* fastq/record: Split name from definition on first separator.
3639

3740
This previously searched for the separator from the end of the definition,
@@ -40,6 +43,7 @@
4043

4144
This also affects how the name is extracted in the `filter` command.
4245

46+
[#47]: https://github.com/stjude-rust-labs/fq/issues/47
4347
[#48]: https://github.com/stjude-rust-labs/fq/issues/48
4448
[#49]: https://github.com/stjude-rust-labs/fq/issues/49
4549
[#51]: https://github.com/stjude-rust-labs/fq/issues/51

src/commands/lint.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,37 @@ fn validate_single(
6666
let (single_read_validators, _) =
6767
validators::filter_validators(single_read_validation_level, None, disabled_validators);
6868

69-
let span = info_span!("validate_single");
70-
let _span_ctx = span.enter();
69+
let mut duplicate_name_validator = DuplicateNameValidator::new();
70+
71+
let code = duplicate_name_validator.code();
72+
let name = duplicate_name_validator.name();
73+
let use_special_validator = !disabled_validators.contains(&code.to_string());
74+
75+
let validators = if use_special_validator {
76+
format!(r#""[{code}] {name}""#)
77+
} else {
78+
String::new()
79+
};
80+
81+
info!("enabled special validators: [{}]", validators);
82+
83+
let span = info_span!("validate_single", pass = 1);
84+
let span_ctx = span.enter();
7185

7286
info!("start");
7387

7488
let mut record = Record::default();
89+
7590
let mut record_counter = 0;
7691
let mut failure_count = 0;
7792

7893
while reader.read_record(&mut record)? != 0 {
7994
record.reset(record_definition_separator);
8095

96+
if use_special_validator {
97+
duplicate_name_validator.insert(&record);
98+
}
99+
81100
for validator in &single_read_validators {
82101
if let Err(e) = validator.validate(&record) {
83102
failure_count += 1;
@@ -88,6 +107,27 @@ fn validate_single(
88107
record_counter += 1;
89108
}
90109

110+
info!(record_count = record_counter, "end");
111+
drop(span_ctx);
112+
113+
if !use_special_validator {
114+
return Ok(failure_count);
115+
}
116+
117+
let span = info_span!("validate_single", pass = 2);
118+
let _span_ctx = span.enter();
119+
120+
info!("start");
121+
122+
let (record_counter, duplicate_name_failure_count) = validate_duplicate_names(
123+
r1_src,
124+
record_definition_separator,
125+
lint_mode,
126+
duplicate_name_validator,
127+
)?;
128+
129+
failure_count += duplicate_name_failure_count;
130+
91131
info!(record_count = record_counter, "end");
92132

93133
Ok(failure_count)

0 commit comments

Comments
 (0)