Skip to content

Commit 57daa54

Browse files
committed
refactor(tsgolint): remove always Some option wrapper (#14296)
1 parent 79eadf8 commit 57daa54

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

crates/oxc_linter/src/tsgolint.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ impl TsGoLintState {
151151
while cursor.position() < buffer.len() as u64 {
152152
let start_pos = cursor.position();
153153
match parse_single_message(&mut cursor) {
154-
Ok(Some(TsGoLintMessage::Error(err))) => {
154+
Ok(TsGoLintMessage::Error(err)) => {
155155
return Err(err.error);
156156
}
157-
Ok(Some(TsGoLintMessage::Diagnostic(tsgolint_diagnostic))) => {
157+
Ok(TsGoLintMessage::Diagnostic(tsgolint_diagnostic)) => {
158158
processed_up_to = cursor.position();
159159

160160
let path = tsgolint_diagnostic.file_path.clone();
@@ -219,10 +219,6 @@ impl TsGoLintState {
219219
return Ok(());
220220
}
221221
}
222-
Ok(None) => {
223-
// Successfully parsed but no diagnostic to add
224-
processed_up_to = cursor.position();
225-
}
226222
Err(_) => {
227223
// Could not parse a complete message, break and keep remaining data
228224
cursor.set_position(start_pos);
@@ -351,12 +347,10 @@ impl TsGoLintState {
351347
while cursor.position() < buffer.len() as u64 {
352348
let start_pos = cursor.position();
353349
match parse_single_message(&mut cursor) {
354-
Ok(Some(TsGoLintMessage::Error(err))) => {
350+
Ok(TsGoLintMessage::Error(err)) => {
355351
return Err(err.error);
356352
}
357-
Ok(Some(TsGoLintMessage::Diagnostic(
358-
tsgolint_diagnostic,
359-
))) => {
353+
Ok(TsGoLintMessage::Diagnostic(tsgolint_diagnostic)) => {
360354
processed_up_to = cursor.position();
361355

362356
let path = tsgolint_diagnostic.file_path.clone();
@@ -400,10 +394,6 @@ impl TsGoLintState {
400394

401395
result.push(message_with_position);
402396
}
403-
Ok(None) => {
404-
// Successfully parsed but no diagnostic to add
405-
processed_up_to = cursor.position();
406-
}
407397
Err(_) => {
408398
// Could not parse a complete message, break and keep remaining data
409399
cursor.set_position(start_pos);
@@ -701,9 +691,7 @@ impl MessageType {
701691
/// Parses a single message from the binary tsgolint output.
702692
// Messages are encoded as follows:
703693
// | Payload Size (uint32 LE) - 4 bytes | Message Type (uint8) - 1 byte | Payload |
704-
fn parse_single_message(
705-
cursor: &mut std::io::Cursor<&[u8]>,
706-
) -> Result<Option<TsGoLintMessage>, String> {
694+
fn parse_single_message(cursor: &mut std::io::Cursor<&[u8]>) -> Result<TsGoLintMessage, String> {
707695
let mut size_bytes = [0u8; 4];
708696
if cursor.read_exact(&mut size_bytes).is_err() {
709697
return Err("Failed to read size bytes".to_string());
@@ -728,21 +716,21 @@ fn parse_single_message(
728716
let error_payload = serde_json::from_str::<TsGoLintErrorPayload>(&payload_str)
729717
.map_err(|e| format!("Failed to parse tsgolint error payload: {e}"))?;
730718

731-
Ok(Some(TsGoLintMessage::Error(TsGoLintError { error: error_payload.error })))
719+
Ok(TsGoLintMessage::Error(TsGoLintError { error: error_payload.error }))
732720
}
733721
MessageType::Diagnostic => {
734722
let diagnostic_payload =
735723
serde_json::from_str::<TsGoLintDiagnosticPayload>(&payload_str)
736724
.map_err(|e| format!("Failed to parse tsgolint diagnostic payload: {e}"))?;
737725

738-
Ok(Some(TsGoLintMessage::Diagnostic(TsGoLintDiagnostic {
726+
Ok(TsGoLintMessage::Diagnostic(TsGoLintDiagnostic {
739727
range: diagnostic_payload.range,
740728
rule: diagnostic_payload.rule,
741729
message: diagnostic_payload.message,
742730
fixes: diagnostic_payload.fixes,
743731
suggestions: diagnostic_payload.suggestions,
744732
file_path: diagnostic_payload.file_path,
745-
})))
733+
}))
746734
}
747735
}
748736
}

0 commit comments

Comments
 (0)