Skip to content

Commit

Permalink
perf(linter): add should_run to check path only once to nextjs/no_t…
Browse files Browse the repository at this point in the history
…ypos (#5584)
  • Loading branch information
Boshen committed Sep 7, 2024
1 parent 3835189 commit cd81d12
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions crates/oxc_linter/src/rules/nextjs/no_typos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,20 @@ const NEXTJS_DATA_FETCHING_FUNCTIONS: phf::Set<&'static str> = phf_set! {
const THRESHOLD: i32 = 1;

impl Rule for NoTypos {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
fn should_run(&self, ctx: &LintContext) -> bool {
let Some(path) = ctx.file_path().to_str() else {
return;
return false;
};
let Some(path_after_pages) = path.split("pages").nth(1) else {
return;
return false;
};
if path_after_pages.starts_with("/api") {
return;
return false;
}
true
}

fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
if let AstKind::ModuleDeclaration(ModuleDeclaration::ExportNamedDeclaration(en_decl)) =
node.kind()
{
Expand Down

0 comments on commit cd81d12

Please sign in to comment.