Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
fs,
path::{Path, PathBuf},
sync::{Arc, OnceLock},
};
Expand All @@ -14,7 +13,7 @@ use tower_lsp_server::{
use oxc_allocator::Allocator;
use oxc_linter::{
LINTABLE_EXTENSIONS, LintService, LintServiceOptions, Linter, MessageWithPosition,
loader::Loader,
loader::Loader, read_to_string,
};

use super::error_with_position::{
Expand Down Expand Up @@ -103,7 +102,7 @@ impl IsolatedLintHandler {
debug!("extension not supported yet.");
return None;
}
let source_text = source_text.or_else(|| fs::read_to_string(path).ok())?;
let source_text = source_text.or_else(|| read_to_string(path).ok())?;

debug!("lint {path:?}");

Expand Down
1 change: 1 addition & 0 deletions crates/oxc_linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub use crate::{
options::{AllowWarnDeny, InvalidFilterKind, LintFilter, LintFilterKind},
rule::{RuleCategory, RuleFixMeta, RuleMeta, RuleWithSeverity},
service::{LintService, LintServiceOptions},
utils::read_to_string,
};
use crate::{
config::{LintConfig, OxlintEnv, OxlintGlobals, OxlintSettings, ResolvedLinterState},
Expand Down
5 changes: 5 additions & 0 deletions crates/oxc_linter/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ pub fn is_eslint_rule_adapted_to_typescript(rule_name: &str) -> bool {
TYPESCRIPT_COMPATIBLE_ESLINT_RULES.binary_search(&rule_name).is_ok()
}

/// Reads the content of a path and returns it.
/// This function is faster than native `fs:read_to_string`.
///
/// # Errors
/// When the content of the path is not a valid UTF-8 bytes
pub fn read_to_string(path: &Path) -> io::Result<String> {
// `simdutf8` is faster than `std::str::from_utf8` which `fs::read_to_string` uses internally
let bytes = std::fs::read(path)?;
Expand Down
Loading