eslint-plugin-nextjs-enforce-runtime-edge v1.0.5
ESLint Plugin for Next.js on Cloudflare Pages to Enforce Edge Runtime
This ESLint plugin enforces the inclusion of export const runtime = 'edge'; for files in the Next.js src/app directory, ensuring compliance with Cloudflare Pages edge runtime.
The rule helps to:
- Warn or error when the declaration is missing.
- Automatically fix the issue (if configured to run with --fix).
Installation
Install the plugin via npm:
npm install -D eslint-plugin-nextjs-enforce-runtime-edge
Usage
Configuration for .cjs
- Import the plugin in your eslint.config.cjs file:
const enforceRuntimeEdgeRule = require('eslint-plugin-nextjs-enforce-runtime-edge');
- Add the configuration to your ESLint rules:
module.exports = [
// Other rules or base configurations...
// Enforce "runtime = 'edge';" in src/app files
{
files: ['src/app/**/*.ts', 'src/app/**/*.tsx'],
ignores: ['src/app/**/*.test.ts', 'src/app/**/*.test.tsx'],
plugins: {
'eslint-plugin-nextjs-enforce-runtime-edge': enforceRuntimeEdgeRule,
},
rules: {
'nextjs-enforce-runtime-edge/enforce-runtime-edge': 'error',
},
},
// Other rules...
];
Configuration for .mjs
If you’re using an .mjs setup for your ESLint configuration: 1. Import the plugin dynamically:
import enforceRuntimeEdgeRule from 'eslint-plugin-nextjs-enforce-runtime-edge';
- Add the configuration to your ESLint rules:
export default [
// Other rules or base configurations...
// Enforce "runtime = 'edge';" in src/app files
{
files: ['src/app/**/*.ts', 'src/app/**/*.tsx'],
ignores: ['src/app/**/*.test.ts', 'src/app/**/*.test.tsx'],
plugins: {
'eslint-plugin-nextjs-enforce-runtime-edge': enforceRuntimeEdgeRule,
},
rules: {
'nextjs-enforce-runtime-edge/enforce-runtime-edge': 'error',
},
},
// Other rules...
];
Running ESLint
After configuring ESLint with the plugin, run the linter as usual:
npx eslint . --fix
Auto-Fix Behavior
When used with the --fix flag, the plugin automatically adds:
export const runtime = 'edge';
at the appropriate location in the file if it’s missing.
Rule Details
- Rule name: nextjs-enforce-runtime-edge/enforce-runtime-edge
- Fixable: Yes, it can automatically add the missing export.
Contribution
If you’d like to contribute or report issues, feel free to open an issue or PR on the GitHub repository. Contributions are welcome! See the dev docs