Skip to content

Commit cd81d12

Browse files
committedSep 7, 2024·
perf(linter): add should_run to check path only once to nextjs/no_typos (#5584)
1 parent 3835189 commit cd81d12

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed
 

‎crates/oxc_linter/src/rules/nextjs/no_typos.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,20 @@ const NEXTJS_DATA_FETCHING_FUNCTIONS: phf::Set<&'static str> = phf_set! {
4747
const THRESHOLD: i32 = 1;
4848

4949
impl Rule for NoTypos {
50-
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
50+
fn should_run(&self, ctx: &LintContext) -> bool {
5151
let Some(path) = ctx.file_path().to_str() else {
52-
return;
52+
return false;
5353
};
5454
let Some(path_after_pages) = path.split("pages").nth(1) else {
55-
return;
55+
return false;
5656
};
5757
if path_after_pages.starts_with("/api") {
58-
return;
58+
return false;
5959
}
60+
true
61+
}
62+
63+
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
6064
if let AstKind::ModuleDeclaration(ModuleDeclaration::ExportNamedDeclaration(en_decl)) =
6165
node.kind()
6266
{

0 commit comments

Comments
 (0)