From c95f2e093742290343efcd2120b8359d0b58bb05 Mon Sep 17 00:00:00 2001 From: Boshen Date: Fri, 20 Oct 2023 10:05:32 +0800 Subject: [PATCH] fix(linter): fix panic with `strip_prefix` (#1013) fixes #1011 --- crates/oxc_linter/src/service.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/oxc_linter/src/service.rs b/crates/oxc_linter/src/service.rs index 8f7ae3f78..1900f82d7 100644 --- a/crates/oxc_linter/src/service.rs +++ b/crates/oxc_linter/src/service.rs @@ -1,4 +1,3 @@ -use dashmap::DashMap; use std::{ collections::HashMap, fs, @@ -7,16 +6,18 @@ use std::{ sync::{Arc, Condvar, Mutex}, }; +use dashmap::DashMap; +use rayon::{iter::ParallelBridge, prelude::ParallelIterator}; +use rustc_hash::FxHashSet; + use oxc_allocator::Allocator; use oxc_diagnostics::{DiagnosticSender, DiagnosticService}; use oxc_parser::Parser; use oxc_resolver::{ResolveOptions, Resolver}; use oxc_semantic::{ModuleRecord, SemanticBuilder}; use oxc_span::{SourceType, VALID_EXTENSIONS}; -use rustc_hash::FxHashSet; use crate::{Fixer, LintContext, LintOptions, Linter, Message}; -use rayon::{iter::ParallelBridge, prelude::ParallelIterator}; #[derive(Clone)] pub struct LintService { @@ -153,7 +154,7 @@ impl Runtime { if !messages.is_empty() { let errors = messages.into_iter().map(|m| m.error).collect(); - let path = path.strip_prefix(&self.cwd).unwrap(); + let path = path.strip_prefix(&self.cwd).unwrap_or(path); let diagnostics = DiagnosticService::wrap_diagnostics(path, &source_text, errors); tx_error.send(Some(diagnostics)).unwrap(); }