From cd81d126244445dc4f3d21f59198e2005bf1250d Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Sat, 7 Sep 2024 13:03:23 +0000 Subject: [PATCH] perf(linter): add `should_run` to check path only once to nextjs/no_typos (#5584) --- crates/oxc_linter/src/rules/nextjs/no_typos.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/oxc_linter/src/rules/nextjs/no_typos.rs b/crates/oxc_linter/src/rules/nextjs/no_typos.rs index c1036bf999271..39f8d96c27174 100644 --- a/crates/oxc_linter/src/rules/nextjs/no_typos.rs +++ b/crates/oxc_linter/src/rules/nextjs/no_typos.rs @@ -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() {