1+ // @ts -check
12const path = require ( 'path' )
23const fs = require ( 'fs' )
4+ const getRootDir = require ( '../utils/get-root-dirs' )
35const {
46 getUrlFromPagesDirectories,
57 normalizeURL,
@@ -20,7 +22,7 @@ const fsExistsSyncCache = {}
2022module . exports = {
2123 meta : {
2224 docs : {
23- description : 'Prohibit full page refresh for nextjs pages' ,
25+ description : 'Prohibit full page refresh for Next.js pages' ,
2426 category : 'HTML' ,
2527 recommended : true ,
2628 } ,
@@ -43,14 +45,27 @@ module.exports = {
4345 ] ,
4446 } ,
4547
48+ /**
49+ * Creates an ESLint rule listener.
50+ *
51+ * @param {import('eslint').Rule.RuleContext } context - ESLint rule context
52+ * @returns {import('eslint').Rule.RuleListener } An ESLint rule listener
53+ */
4654 create : function ( context ) {
47- const [ customPagesDirectory ] = context . options
48- const pagesDirs = customPagesDirectory
49- ? [ customPagesDirectory ] . flat ( )
50- : [
51- path . join ( context . getCwd ( ) , 'pages' ) ,
52- path . join ( context . getCwd ( ) , 'src' , 'pages' ) ,
53- ]
55+ /** @type {(string|string[])[] } */
56+ const ruleOptions = context . options
57+ const [ customPagesDirectory ] = ruleOptions
58+
59+ const rootDirs = getRootDir ( context )
60+
61+ const pagesDirs = ( customPagesDirectory
62+ ? [ customPagesDirectory ]
63+ : rootDirs . map ( ( dir ) => [
64+ path . join ( dir , 'pages' ) ,
65+ path . join ( dir , 'src' , 'pages' ) ,
66+ ] )
67+ ) . flat ( )
68+
5469 const foundPagesDirs = pagesDirs . filter ( ( dir ) => {
5570 if ( fsExistsSyncCache [ dir ] === undefined ) {
5671 fsExistsSyncCache [ dir ] = fs . existsSync ( dir )
0 commit comments