Skip to content

Commit

Permalink
Fixes for ESLint rule no-app-not-found-runtime (#539)
Browse files Browse the repository at this point in the history
* Use correct name for export of no-app-not-found-runtime lint rule

Fixes #530

* Add support for src folder to no-app-not-found-runtime lint rule

Fixes #531
  • Loading branch information
mattiasw authored Nov 13, 2023
1 parent 3dc3ac4 commit 48796ca
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-deers-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-next-on-pages': patch
---

Support for using src folder with no-app-not-found-runtime lint rule
5 changes: 5 additions & 0 deletions .changeset/rare-rings-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-next-on-pages': patch
---

Use correct name for export of no-app-not-found-runtime lint rule
6 changes: 3 additions & 3 deletions packages/eslint-plugin-next-on-pages/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
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';

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',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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: '',
},
],
});
});
});

0 comments on commit 48796ca

Please sign in to comment.