diff --git a/.changeset/neat-deers-work.md b/.changeset/neat-deers-work.md new file mode 100644 index 000000000..989dbee94 --- /dev/null +++ b/.changeset/neat-deers-work.md @@ -0,0 +1,5 @@ +--- +'eslint-plugin-next-on-pages': patch +--- + +Support for using src folder with no-app-not-found-runtime lint rule diff --git a/.changeset/rare-rings-own.md b/.changeset/rare-rings-own.md new file mode 100644 index 000000000..ebb11c0ce --- /dev/null +++ b/.changeset/rare-rings-own.md @@ -0,0 +1,5 @@ +--- +'eslint-plugin-next-on-pages': patch +--- + +Use correct name for export of no-app-not-found-runtime lint rule diff --git a/packages/eslint-plugin-next-on-pages/src/index.ts b/packages/eslint-plugin-next-on-pages/src/index.ts index 161b600e9..0034d48db 100644 --- a/packages/eslint-plugin-next-on-pages/src/index.ts +++ b/packages/eslint-plugin-next-on-pages/src/index.ts @@ -1,6 +1,6 @@ import noNodeJsRuntime from './rules/no-nodejs-runtime'; import noUnsupportedConfigs from './rules/no-unsupported-configs'; -import noAppNotFound from './rules/no-app-not-found-runtime'; +import noAppNotFoundRuntime from './rules/no-app-not-found-runtime'; import type { ESLint } from 'eslint'; @@ -8,13 +8,13 @@ const config: ESLint.Plugin = { rules: { 'no-nodejs-runtime': noNodeJsRuntime, 'no-unsupported-configs': noUnsupportedConfigs, - 'no-app-not-found': noAppNotFound, + 'no-app-not-found-runtime': noAppNotFoundRuntime, }, configs: { recommended: { plugins: ['eslint-plugin-next-on-pages'], rules: { - 'next-on-pages/no-app-not-found': 'error', + 'next-on-pages/no-app-not-found-runtime': 'error', 'next-on-pages/no-nodejs-runtime': 'error', 'next-on-pages/no-unsupported-configs': 'error', }, diff --git a/packages/eslint-plugin-next-on-pages/src/rules/no-app-not-found-runtime.ts b/packages/eslint-plugin-next-on-pages/src/rules/no-app-not-found-runtime.ts index e3deb2780..6c5b39b77 100644 --- a/packages/eslint-plugin-next-on-pages/src/rules/no-app-not-found-runtime.ts +++ b/packages/eslint-plugin-next-on-pages/src/rules/no-app-not-found-runtime.ts @@ -3,7 +3,7 @@ import type { Rule } from 'eslint'; const rule: Rule.RuleModule = { create: context => { const isAppNotFoundRoute = new RegExp( - `${context.cwd}/app/not-found\\.(tsx|jsx)`, + `${context.cwd}(/src)?/app/not-found\\.(tsx|jsx)$`, ).test(context.filename); return { ExportNamedDeclaration: node => { @@ -22,7 +22,7 @@ const rule: Rule.RuleModule = { ) { context.report({ message: - 'Only static not-found pages are currently supported, please remove the runtime export.' + + 'Only static not-found pages are currently supported, please remove the runtime export in ' + context.filename, node, fix: fixer => fixer.remove(node), diff --git a/packages/eslint-plugin-next-on-pages/tests/rules/no-app-not-found-runtime.test.ts b/packages/eslint-plugin-next-on-pages/tests/rules/no-app-not-found-runtime.test.ts new file mode 100644 index 000000000..67d11b66b --- /dev/null +++ b/packages/eslint-plugin-next-on-pages/tests/rules/no-app-not-found-runtime.test.ts @@ -0,0 +1,76 @@ +import path from 'path'; +import { RuleTester } from 'eslint'; + +import rule from '../../src/rules/no-app-not-found-runtime'; +import { describe, test } from 'vitest'; + +const tester = new RuleTester({ + parser: require.resolve('@typescript-eslint/parser'), +}); + +const contextCwd = path.join(__dirname, '../..'); + +describe('no-app-not-found-runtime', () => { + test('should work', () => { + tester.run('no-app-not-found-runtime', rule, { + valid: [ + { + filename: path.join(contextCwd, '/app/not-found.tsx'), + code: ` + export default function Page() { + return 'Not Found'; + } + `, + }, + { + filename: path.join(contextCwd, '/app/page.tsx'), + code: ` + export const runtime = 'edge'; + export default function Page() { + return 'Hello'; + } + `, + }, + ], + invalid: [ + { + filename: path.join(contextCwd, '/app/not-found.tsx'), + code: "export const runtime = 'edge';", + errors: [ + { + message: `Only static not-found pages are currently supported, please remove the runtime export in ${contextCwd}/app/not-found.tsx`, + }, + ], + output: '', + }, + ], + }); + }); + + test('should work with src folder', () => { + tester.run('no-app-not-found-runtime', rule, { + valid: [ + { + filename: path.join(contextCwd, '/src/app/not-found.tsx'), + code: ` + export default function Page() { + return 'Not Found'; + } + `, + }, + ], + invalid: [ + { + filename: path.join(contextCwd, '/src/app/not-found.tsx'), + code: "export const runtime = 'edge';", + errors: [ + { + message: `Only static not-found pages are currently supported, please remove the runtime export in ${contextCwd}/src/app/not-found.tsx`, + }, + ], + output: '', + }, + ], + }); + }); +});