mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
refactor(linter): use ctx.source_range(comment.content_span()) API (#7155)
This commit is contained in:
parent
3da9443b0e
commit
8c0a362b8b
8 changed files with 8 additions and 9 deletions
|
|
@ -79,7 +79,7 @@ impl Rule for DefaultCase {
|
|||
.comments_range(last_case.span.start..switch.span.end)
|
||||
.last()
|
||||
.is_some_and(|comment| {
|
||||
let raw = comment.content_span().source_text(ctx.source_text()).trim();
|
||||
let raw = ctx.source_range(comment.content_span()).trim();
|
||||
match &self.comment_pattern {
|
||||
Some(comment_pattern) => comment_pattern.is_match(raw),
|
||||
None => raw.eq_ignore_ascii_case("no default"),
|
||||
|
|
|
|||
|
|
@ -382,7 +382,7 @@ impl NoFallthrough {
|
|||
let is_fallthrough_comment_in_range = |range: Range<u32>| {
|
||||
let comment = semantic
|
||||
.comments_range(range)
|
||||
.map(|comment| comment.content_span().source_text(semantic.source_text()))
|
||||
.map(|comment| ctx.source_range(comment.content_span()))
|
||||
.last()
|
||||
.map(str::trim);
|
||||
|
||||
|
|
|
|||
|
|
@ -60,9 +60,8 @@ impl Rule for NoCommentedOutTests {
|
|||
Regex::new(r#"(?mu)^\s*[xf]?(test|it|describe)(\.\w+|\[['"]\w+['"]\])?\s*\("#).unwrap();
|
||||
}
|
||||
let comments = ctx.semantic().comments();
|
||||
let source_text = ctx.source_text();
|
||||
let commented_tests = comments.iter().filter_map(|comment| {
|
||||
let text = comment.content_span().source_text(source_text);
|
||||
let text = ctx.source_range(comment.content_span());
|
||||
if RE.is_match(text) {
|
||||
Some(comment.content_span())
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ impl Rule for BanTslintComment {
|
|||
let comments = ctx.semantic().comments();
|
||||
let source_text_len = ctx.semantic().source_text().len();
|
||||
for comment in comments {
|
||||
let raw = comment.content_span().source_text(ctx.source_text());
|
||||
let raw = ctx.source_range(comment.content_span());
|
||||
if is_tslint_comment_directive(raw) {
|
||||
let comment_span = get_full_comment(source_text_len, comment.span);
|
||||
ctx.diagnostic_with_fix(
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ impl Rule for PreferTsExpectError {
|
|||
let comments = ctx.semantic().comments();
|
||||
|
||||
for comment in comments {
|
||||
let raw = comment.content_span().source_text(ctx.source_text());
|
||||
let raw = ctx.source_range(comment.content_span());
|
||||
|
||||
if !is_valid_ts_ignore_present(*comment, raw) {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ impl Rule for TripleSlashReference {
|
|||
let mut refs_for_import = FxHashMap::default();
|
||||
|
||||
for comment in ctx.semantic().comments_range(0..comments_range_end) {
|
||||
let raw = comment.content_span().source_text(ctx.source_text());
|
||||
let raw = ctx.source_range(comment.content_span());
|
||||
if let Some((group1, group2)) = get_attr_key_and_value(raw) {
|
||||
if (group1 == "types" && self.types == TypesOption::Never)
|
||||
|| (group1 == "path" && self.path == PathOption::Never)
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ fn has_triple_slash_directive(ctx: &LintContext<'_>) -> bool {
|
|||
if !comment.is_line() {
|
||||
continue;
|
||||
}
|
||||
let text = comment.content_span().source_text(ctx.source_text());
|
||||
let text = ctx.source_range(comment.content_span());
|
||||
if text.starts_with("///") {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -226,7 +226,7 @@ pub fn has_pure_notation(span: Span, ctx: &LintContext) -> bool {
|
|||
let Some(comment) = ctx.semantic().comments_range(..span.start).next_back() else {
|
||||
return false;
|
||||
};
|
||||
let raw = comment.content_span().source_text(ctx.source_text());
|
||||
let raw = ctx.source_range(comment.content_span());
|
||||
raw.contains("@__PURE__") || raw.contains("#__PURE__")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue