Skip to content

Commit 423720e

Browse files
committed
refactor(linter): remove lifetime of Message
1 parent 77938e4 commit 423720e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+235
-383
lines changed

crates/oxc_language_server/src/linter/error_with_position.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub enum PossibleFixContent {
3535
// we assume that the fix offset will not exceed 2GB in either direction
3636
#[expect(clippy::cast_possible_truncation)]
3737
pub fn message_to_lsp_diagnostic(
38-
message: &Message<'_>,
38+
message: &Message,
3939
uri: &Uri,
4040
source_text: &str,
4141
rope: &Rope,
@@ -134,7 +134,7 @@ pub fn message_to_lsp_diagnostic(
134134
DiagnosticReport { diagnostic, fixed_content }
135135
}
136136

137-
fn fix_to_fixed_content(fix: &Fix<'_>, rope: &Rope, source_text: &str) -> FixedContent {
137+
fn fix_to_fixed_content(fix: &Fix, rope: &Rope, source_text: &str) -> FixedContent {
138138
let start_position = offset_to_position(rope, fix.span.start, source_text);
139139
let end_position = offset_to_position(rope, fix.span.end, source_text);
140140

crates/oxc_language_server/src/linter/isolated_lint_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl IsolatedLintHandler {
145145
&self,
146146
directives: &DisableDirectives,
147147
severity: AllowWarnDeny,
148-
) -> Vec<Message<'_>> {
148+
) -> Vec<Message> {
149149
let diagnostics = create_unused_directives_diagnostics(directives, severity);
150150
diagnostics
151151
.into_iter()

crates/oxc_linter/src/context/host.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub struct ContextHost<'a> {
132132
/// Diagnostics reported by the linter.
133133
///
134134
/// Contains diagnostics for all rules across a single file.
135-
diagnostics: RefCell<Vec<Message<'a>>>,
135+
diagnostics: RefCell<Vec<Message>>,
136136
/// Whether or not to apply code fixes during linting. Defaults to
137137
/// [`FixKind::None`] (no fixing).
138138
///
@@ -241,15 +241,15 @@ impl<'a> ContextHost<'a> {
241241
/// Add a diagnostic message to the end of the list of diagnostics. Can be used
242242
/// by any rule to report issues.
243243
#[inline]
244-
pub(crate) fn push_diagnostic(&self, mut diagnostic: Message<'a>) {
244+
pub(crate) fn push_diagnostic(&self, mut diagnostic: Message) {
245245
if self.current_sub_host().source_text_offset != 0 {
246246
diagnostic.move_offset(self.current_sub_host().source_text_offset);
247247
}
248248
self.diagnostics.borrow_mut().push(diagnostic);
249249
}
250250

251251
// Append a list of diagnostics. Only used in report_unused_directives.
252-
fn append_diagnostics(&self, mut diagnostics: Vec<Message<'a>>) {
252+
fn append_diagnostics(&self, mut diagnostics: Vec<Message>) {
253253
if self.current_sub_host().source_text_offset != 0 {
254254
let offset = self.current_sub_host().source_text_offset;
255255
for diagnostic in &mut diagnostics {
@@ -345,7 +345,7 @@ impl<'a> ContextHost<'a> {
345345
}
346346

347347
/// Take ownership of all diagnostics collected during linting.
348-
pub fn take_diagnostics(&self) -> Vec<Message<'a>> {
348+
pub fn take_diagnostics(&self) -> Vec<Message> {
349349
// NOTE: diagnostics are only ever borrowed here and in push_diagnostic, append_diagnostics.
350350
// The latter drops the reference as soon as the function returns, so
351351
// this should never panic.
@@ -368,7 +368,7 @@ impl<'a> ContextHost<'a> {
368368
}
369369

370370
#[cfg(debug_assertions)]
371-
pub fn get_diagnostics(&self, cb: impl FnOnce(&mut Vec<Message<'a>>)) {
371+
pub fn get_diagnostics(&self, cb: impl FnOnce(&mut Vec<Message>)) {
372372
cb(self.diagnostics.borrow_mut().as_mut());
373373
}
374374

@@ -450,7 +450,7 @@ impl<'a> ContextHost<'a> {
450450
}
451451
}
452452

453-
impl<'a> From<ContextHost<'a>> for Vec<Message<'a>> {
453+
impl<'a> From<ContextHost<'a>> for Vec<Message> {
454454
fn from(ctx_host: ContextHost<'a>) -> Self {
455455
ctx_host.diagnostics.into_inner()
456456
}

crates/oxc_linter/src/context/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl<'a> LintContext<'a> {
222222

223223
/// Add a diagnostic message to the list of diagnostics. Outputs a diagnostic with the current rule
224224
/// name, severity, and a link to the rule's documentation URL.
225-
fn add_diagnostic(&self, mut message: Message<'a>) {
225+
fn add_diagnostic(&self, mut message: Message) {
226226
if self.parent.disable_directives().contains(self.current_rule_name, message.span()) {
227227
return;
228228
}
@@ -272,7 +272,7 @@ impl<'a> LintContext<'a> {
272272
#[inline]
273273
pub fn diagnostic_with_fix<C, F>(&self, diagnostic: OxcDiagnostic, fix: F)
274274
where
275-
C: Into<RuleFix<'a>>,
275+
C: Into<RuleFix>,
276276
F: FnOnce(RuleFixer<'_, 'a>) -> C,
277277
{
278278
self.diagnostic_with_fix_of_kind(diagnostic, FixKind::SafeFix, fix);
@@ -293,7 +293,7 @@ impl<'a> LintContext<'a> {
293293
#[inline]
294294
pub fn diagnostic_with_suggestion<C, F>(&self, diagnostic: OxcDiagnostic, fix: F)
295295
where
296-
C: Into<RuleFix<'a>>,
296+
C: Into<RuleFix>,
297297
F: FnOnce(RuleFixer<'_, 'a>) -> C,
298298
{
299299
self.diagnostic_with_fix_of_kind(diagnostic, FixKind::Suggestion, fix);
@@ -314,7 +314,7 @@ impl<'a> LintContext<'a> {
314314
#[inline]
315315
pub fn diagnostic_with_dangerous_suggestion<C, F>(&self, diagnostic: OxcDiagnostic, fix: F)
316316
where
317-
C: Into<RuleFix<'a>>,
317+
C: Into<RuleFix>,
318318
F: FnOnce(RuleFixer<'_, 'a>) -> C,
319319
{
320320
self.diagnostic_with_fix_of_kind(diagnostic, FixKind::DangerousSuggestion, fix);
@@ -342,7 +342,7 @@ impl<'a> LintContext<'a> {
342342
#[inline]
343343
pub fn diagnostic_with_dangerous_fix<C, F>(&self, diagnostic: OxcDiagnostic, fix: F)
344344
where
345-
C: Into<RuleFix<'a>>,
345+
C: Into<RuleFix>,
346346
F: FnOnce(RuleFixer<'_, 'a>) -> C,
347347
{
348348
self.diagnostic_with_fix_of_kind(diagnostic, FixKind::DangerousFix, fix);
@@ -360,7 +360,7 @@ impl<'a> LintContext<'a> {
360360
fix_kind: FixKind,
361361
fix: F,
362362
) where
363-
C: Into<RuleFix<'a>>,
363+
C: Into<RuleFix>,
364364
F: FnOnce(RuleFixer<'_, 'a>) -> C,
365365
{
366366
let (diagnostic, fix) = self.create_fix(fix_kind, fix, diagnostic);
@@ -386,11 +386,11 @@ impl<'a> LintContext<'a> {
386386
fix_one: (FixKind, F1),
387387
fix_two: (FixKind, F2),
388388
) where
389-
C: Into<RuleFix<'a>>,
389+
C: Into<RuleFix>,
390390
F1: FnOnce(RuleFixer<'_, 'a>) -> C,
391391
F2: FnOnce(RuleFixer<'_, 'a>) -> C,
392392
{
393-
let fixes_result: Vec<Fix<'a>> = vec![
393+
let fixes_result: Vec<Fix> = vec![
394394
self.create_fix(fix_one.0, fix_one.1, diagnostic.clone()).1,
395395
self.create_fix(fix_two.0, fix_two.1, diagnostic.clone()).1,
396396
]
@@ -417,13 +417,13 @@ impl<'a> LintContext<'a> {
417417
fix_kind: FixKind,
418418
fix: F,
419419
diagnostic: OxcDiagnostic,
420-
) -> (OxcDiagnostic, Option<Fix<'a>>)
420+
) -> (OxcDiagnostic, Option<Fix>)
421421
where
422-
C: Into<RuleFix<'a>>,
422+
C: Into<RuleFix>,
423423
F: FnOnce(RuleFixer<'_, 'a>) -> C,
424424
{
425425
let fixer = RuleFixer::new(fix_kind, self);
426-
let rule_fix: RuleFix<'a> = fix(fixer).into();
426+
let rule_fix: RuleFix = fix(fixer).into();
427427
#[cfg(debug_assertions)]
428428
debug_assert!(
429429
self.current_rule_fix_capabilities.supports_fix(fix_kind),

crates/oxc_linter/src/disable_directives.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub struct RuleCommentRule {
4040

4141
impl RuleCommentRule {
4242
#[expect(clippy::cast_possible_truncation)] // for `as u32`
43-
pub fn create_fix<'a>(&self, source_text: &'a str, comment_span: Span) -> Fix<'a> {
43+
pub fn create_fix(&self, source_text: &str, comment_span: Span) -> Fix {
4444
let before_source =
4545
&source_text[comment_span.start as usize..self.name_span.start as usize];
4646

0 commit comments

Comments
 (0)