|
1 | 1 | #![allow(rustdoc::private_intra_doc_links)] // useful for intellisense
|
2 | 2 | mod host;
|
3 | 3 |
|
4 |
| -use std::{path::Path, rc::Rc}; |
| 4 | +use std::{ops::Deref, path::Path, rc::Rc}; |
5 | 5 |
|
6 | 6 | use oxc_cfg::ControlFlowGraph;
|
7 | 7 | use oxc_diagnostics::{OxcDiagnostic, Severity};
|
8 |
| -use oxc_semantic::{AstNodes, JSDocFinder, ScopeTree, Semantic, SymbolTable}; |
9 |
| -use oxc_span::{GetSpan, SourceType, Span}; |
10 |
| -use oxc_syntax::module_record::ModuleRecord; |
| 8 | +use oxc_semantic::Semantic; |
| 9 | +use oxc_span::{GetSpan, Span}; |
11 | 10 |
|
12 | 11 | #[cfg(debug_assertions)]
|
13 | 12 | use crate::rule::RuleFixMeta;
|
@@ -56,6 +55,15 @@ pub struct LintContext<'a> {
|
56 | 55 | severity: Severity,
|
57 | 56 | }
|
58 | 57 |
|
| 58 | +impl<'a> Deref for LintContext<'a> { |
| 59 | + type Target = Semantic<'a>; |
| 60 | + |
| 61 | + #[inline] |
| 62 | + fn deref(&self) -> &Self::Target { |
| 63 | + self.parent.semantic() |
| 64 | + } |
| 65 | +} |
| 66 | + |
59 | 67 | impl<'a> LintContext<'a> {
|
60 | 68 | /// Base URL for the documentation, used to generate rule documentation URLs when a diagnostic is reported.
|
61 | 69 | const WEBSITE_BASE_URL: &'static str = "https://oxc.rs/docs/guide/usage/linter/rules";
|
@@ -111,24 +119,12 @@ impl<'a> LintContext<'a> {
|
111 | 119 | &self.parent.disable_directives
|
112 | 120 | }
|
113 | 121 |
|
114 |
| - /// Source code of the file being linted. |
115 |
| - #[inline] |
116 |
| - pub fn source_text(&self) -> &'a str { |
117 |
| - self.semantic().source_text() |
118 |
| - } |
119 |
| - |
120 | 122 | /// Get a snippet of source text covered by the given [`Span`]. For details,
|
121 | 123 | /// see [`Span::source_text`].
|
122 | 124 | pub fn source_range(&self, span: Span) -> &'a str {
|
123 | 125 | span.source_text(self.semantic().source_text())
|
124 | 126 | }
|
125 | 127 |
|
126 |
| - /// [`SourceType`] of the file currently being linted. |
127 |
| - #[inline] |
128 |
| - pub fn source_type(&self) -> &SourceType { |
129 |
| - self.semantic().source_type() |
130 |
| - } |
131 |
| - |
132 | 128 | /// Path to the file currently being linted.
|
133 | 129 | #[inline]
|
134 | 130 | pub fn file_path(&self) -> &Path {
|
@@ -321,41 +317,6 @@ impl<'a> LintContext<'a> {
|
321 | 317 | pub fn frameworks(&self) -> FrameworkFlags {
|
322 | 318 | self.parent.frameworks
|
323 | 319 | }
|
324 |
| - |
325 |
| - /// AST nodes |
326 |
| - /// |
327 |
| - /// Shorthand for `self.semantic().nodes()`. |
328 |
| - pub fn nodes(&self) -> &AstNodes<'a> { |
329 |
| - self.semantic().nodes() |
330 |
| - } |
331 |
| - |
332 |
| - /// Scope tree |
333 |
| - /// |
334 |
| - /// Shorthand for `ctx.semantic().scopes()`. |
335 |
| - pub fn scopes(&self) -> &ScopeTree { |
336 |
| - self.semantic().scopes() |
337 |
| - } |
338 |
| - |
339 |
| - /// Symbol table |
340 |
| - /// |
341 |
| - /// Shorthand for `ctx.semantic().symbols()`. |
342 |
| - pub fn symbols(&self) -> &SymbolTable { |
343 |
| - self.semantic().symbols() |
344 |
| - } |
345 |
| - |
346 |
| - /// Imported modules and exported symbols |
347 |
| - /// |
348 |
| - /// Shorthand for `ctx.semantic().module_record()`. |
349 |
| - pub fn module_record(&self) -> &ModuleRecord { |
350 |
| - self.semantic().module_record() |
351 |
| - } |
352 |
| - |
353 |
| - /// JSDoc comments |
354 |
| - /// |
355 |
| - /// Shorthand for `ctx.semantic().jsdoc()`. |
356 |
| - pub fn jsdoc(&self) -> &JSDocFinder<'a> { |
357 |
| - self.semantic().jsdoc() |
358 |
| - } |
359 | 320 | }
|
360 | 321 |
|
361 | 322 | /// Gets the prefixed plugin name, given the short plugin name.
|
|
0 commit comments