Skip to content

Commit c6f6bbf

Browse files
committed
perf(linter): small optimizations for file path checking
1 parent 2d798b7 commit c6f6bbf

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

crates/oxc_linter/src/rules/jsdoc/check_tag_names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl Rule for CheckTagNames {
237237
let config = &self.0;
238238
let user_defined_tags = settings.list_user_defined_tag_names();
239239

240-
let is_dts = ctx.file_path().to_str().is_some_and(|p| p.ends_with(".d.ts"));
240+
let is_dts = ctx.source_type().is_typescript_definition();
241241
// NOTE: The original rule seems to check `declare` context by visiting AST nodes.
242242
// https://github.com/gajus/eslint-plugin-jsdoc/blob/e343ab5b1efaa59b07c600138aee070b4083857e/src/rules/checkTagNames.js#L121
243243
// But...

crates/oxc_linter/src/rules/react/only_export_components.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,22 +255,26 @@ impl Rule for OnlyExportComponents {
255255
}
256256

257257
fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
258-
let Some(filename) = ctx.file_path().file_name().and_then(|s| s.to_str()) else {
259-
return false;
260-
};
261-
262258
let should_scan = {
263259
let ext = ctx.file_extension();
264260
matches!(ext, Some(e) if e.eq_ignore_ascii_case("tsx") || e.eq_ignore_ascii_case("jsx"))
265261
|| (self.check_js && matches!(ext, Some(e) if e.eq_ignore_ascii_case("js")))
266262
};
267263

264+
if !should_scan {
265+
return false;
266+
}
267+
268+
let Some(filename) = ctx.file_path().file_name().and_then(|s| s.to_str()) else {
269+
return false;
270+
};
271+
268272
let should_skip = filename.contains(".test.")
269273
|| filename.contains(".spec.")
270274
|| filename.contains(".cy.")
271275
|| filename.contains(".stories.");
272276

273-
should_scan && !should_skip
277+
!should_skip
274278
}
275279

276280
fn run_once(&self, ctx: &LintContext<'_>) {

0 commit comments

Comments
 (0)