Skip to content

Commit 5f79f25

Browse files
committed
refator(linter): add source_text_offset to ContextSubHost
1 parent b149f2d commit 5f79f25

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

crates/oxc_linter/src/context/host.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,31 @@ pub struct ContextSubHost<'a> {
3030
// Specific framework options, for example, whether the context is inside `<script setup>` in Vue files.
3131
#[expect(dead_code)]
3232
pub(super) framework_options: FrameworkOptions,
33+
/// The source text offset of the sub host
34+
#[expect(dead_code)]
35+
pub(super) source_text_offset: u32,
3336
}
3437

3538
impl<'a> ContextSubHost<'a> {
36-
pub fn new(semantic: Rc<Semantic<'a>>, module_record: Arc<ModuleRecord>) -> Self {
37-
Self::new_with_framework_options(semantic, module_record, FrameworkOptions::Default)
39+
pub fn new(
40+
semantic: Rc<Semantic<'a>>,
41+
module_record: Arc<ModuleRecord>,
42+
source_text_offset: u32,
43+
) -> Self {
44+
Self::new_with_framework_options(
45+
semantic,
46+
module_record,
47+
source_text_offset,
48+
FrameworkOptions::Default,
49+
)
3850
}
3951

4052
/// # Panics
4153
/// If `semantic.cfg()` is `None`.
4254
pub fn new_with_framework_options(
4355
semantic: Rc<Semantic<'a>>,
4456
module_record: Arc<ModuleRecord>,
57+
source_text_offset: u32,
4558
frameworks_options: FrameworkOptions,
4659
) -> Self {
4760
// We should always check for `semantic.cfg()` being `Some` since we depend on it and it is
@@ -57,6 +70,7 @@ impl<'a> ContextSubHost<'a> {
5770
Self {
5871
semantic,
5972
module_record,
73+
source_text_offset,
6074
disable_directives: Rc::new(disable_directives),
6175
framework_options: frameworks_options,
6276
}

crates/oxc_linter/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl Linter {
133133

134134
let ctx_host = Rc::new(ContextHost::new(
135135
path,
136-
vec![ContextSubHost::new(semantic, module_record)],
136+
vec![ContextSubHost::new(semantic, module_record, 0)],
137137
self.options,
138138
config,
139139
));

crates/oxc_linter/src/utils/jest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ mod test {
328328
vec![ContextSubHost::new(
329329
Rc::clone(&semantic_ret),
330330
Arc::new(ModuleRecord::default()),
331+
0,
331332
)],
332333
LintOptions::default(),
333334
Arc::default(),

0 commit comments

Comments
 (0)