Skip to content

Commit

Permalink
perf(linter): run rules which require typescript syntax only when sou…
Browse files Browse the repository at this point in the history
…rce type is actually typescript (#8166)
  • Loading branch information
Sysix authored Dec 28, 2024
1 parent 9d62284 commit d8d2ec6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ impl Rule for ConsistentGenericConstructors {
.unwrap_or_default(),
}))
}

fn should_run(&self, ctx: &crate::rules::ContextHost) -> bool {
ctx.source_type().is_typescript()
}
}

impl ConsistentGenericConstructors {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ impl Rule for NoEmptyObjectType {
_ => {}
}
}

fn should_run(&self, ctx: &crate::rules::ContextHost) -> bool {
ctx.source_type().is_typescript()
}
}

fn check_interface_declaration(
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_linter/src/rules/typescript/no_misused_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ impl Rule for NoMisusedNew {
_ => {}
}
}

fn should_run(&self, ctx: &crate::rules::ContextHost) -> bool {
ctx.source_type().is_typescript()
}
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ impl Rule for NoUnsafeFunctionType {
_ => {}
}
}

fn should_run(&self, ctx: &crate::rules::ContextHost) -> bool {
ctx.source_type().is_typescript()
}
}

fn handle_function_type<'a>(identifier: &'a IdentifierReference<'a>, ctx: &LintContext<'a>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ impl Rule for NoWrapperObjectTypes {
}
}
}

fn should_run(&self, ctx: &crate::rules::ContextHost) -> bool {
ctx.source_type().is_typescript()
}
}

#[test]
Expand Down

0 comments on commit d8d2ec6

Please sign in to comment.