File tree Expand file tree Collapse file tree 1 file changed +17
-16
lines changed
crates/oxc_linter/src/rules/nextjs Expand file tree Collapse file tree 1 file changed +17
-16
lines changed Original file line number Diff line number Diff line change @@ -61,16 +61,17 @@ const THRESHOLD: usize = 1;
6161
6262impl Rule for NoTypos {
6363 fn should_run ( & self , ctx : & ContextHost ) -> bool {
64- let Some ( path) = ctx. file_path ( ) . to_str ( ) else {
65- return false ;
66- } ;
67- let Some ( path_after_pages) = path. split ( "pages" ) . nth ( 1 ) else {
68- return false ;
69- } ;
70- if path_after_pages. starts_with ( "/api" ) {
71- return false ;
64+ let path = ctx. file_path ( ) ;
65+ let mut found_pages = false ;
66+ for component in path. components ( ) {
67+ if found_pages {
68+ return component. as_os_str ( ) != "api" ;
69+ }
70+ if component. as_os_str ( ) == "pages" {
71+ found_pages = true ;
72+ }
7273 }
73- true
74+ false
7475 }
7576
7677 fn run < ' a > ( & self , node : & AstNode < ' a > , ctx : & LintContext < ' a > ) {
@@ -222,17 +223,17 @@ fn test() {
222223 ) ,
223224 // even though there is a typo match, this should not fail because a file is inside pages/api directory
224225 (
225- r"
226- export default function Page() {
227- return <div></div>;
228- }
229- export const getStaticpaths = async () => {};
230- export const getStaticProps = async () => {};
231- " ,
226+ r"export const getStaticpaths = async () => {};" ,
232227 None ,
233228 None ,
234229 Some ( PathBuf :: from( "pages/api/test.tsx" ) ) ,
235230 ) ,
231+ (
232+ r"export const getStaticpaths = async () => {};" ,
233+ None ,
234+ None ,
235+ Some ( PathBuf :: from( "pages\\ api\\ test.tsx" ) ) ,
236+ ) ,
236237 ] ;
237238
238239 let fail = vec ! [
You can’t perform that action at this time.
0 commit comments