eslint-plugin-hono
v1.4.0
Published
ESLint plugin for Hono and all Hono lovers
Maintainers
Readme
🔥 ESLint plugin for Hono and all Hono lovers
Installation
npm install -D eslint-plugin-honoRequires ESLint 9 or later (flat config).
Usage
Add the recommended configuration to your eslint.config.js:
import hono from "eslint-plugin-hono";
export default [
hono.configs.recommended,
];The config registers the plugin for you — there is no need to declare plugins yourself.
To enable every rule, including the stylistic and runtime-specific ones, use all instead:
import hono from "eslint-plugin-hono";
export default [
hono.configs.all,
];To apply the rules only to specific files, or to tweak individual rules, spread the config and add your own entry after it:
import tseslint from "typescript-eslint";
import hono from "eslint-plugin-hono";
export default [
...tseslint.configs.recommended,
{
...hono.configs.recommended,
files: ["src/**/*.ts"],
},
{
files: ["src/**/*.ts"],
rules: {
"hono/no-process-env": "error",
"hono/route-grouping": "warn",
},
},
];Rules
Each rule links to its own documentation page.
✅ = enabled in recommended. All rules are enabled in all.
🔧 = automatically fixable by the --fix CLI option.
| Rule | Description | ✅ | Severity in all | 🔧 |
| :--- | :--- | :---: | :---: | :---: |
| param-name-mismatch | Ensure parameter name in c.req.param() matches the route definition | ✅ | 🚨 error | |
| no-duplicate-path-params | Disallow declaring the same path parameter name twice in one route path (/users/:id/posts/:id) | ✅ | 🚨 error | |
| no-duplicate-routes | Disallow registering the same route (HTTP method and path) more than once, including across basePath() and app.route() | ✅ | 🚨 error | |
| no-multiple-next | Disallow multiple calls to next() in a single middleware execution path | ✅ | 🚨 error | |
| no-unused-context-response | Disallow unused calls to Context response methods (c.json, c.text, etc.) | ✅ | 🚨 error | |
| prefer-http-exception | Suggest using HTTPException instead of generic Error for HTTP errors | ✅ | ⚠️ warn | |
| no-commented-out-route | Disallow commented-out Hono routes and middleware (app.get(...), app.use(...), etc.) | ✅ | ⚠️ warn | |
| max-path-name-length | Enforce a maximum length for each /-separated segment of a route path (default: 30) | ✅ | ⚠️ warn | |
| route-grouping | Enforce grouping and ordering of routes by HTTP method and Hono instance | | ⚠️ warn | 🔧 |
| no-process-env | Disallow the use of process.env in favor of c.env | | ⚠️ warn | |
| global-middleware-placement | Enforce that global middleware is placed before route definitions | | ⚠️ warn | |
| max-return | Enforce a maximum number of return statements in a single route handler (default: 5) | | ⚠️ warn | |
| valid-route-path | Enforce naming conventions on route paths (mustMatch, mustNotMatch, disallowedWords) | | ⚠️ warn | |
| basepath-variable-name | Enforce that a variable holding a basePath() instance is named after its base path | | ⚠️ warn | 🔧 |
| hono-instance-name | Enforce a required prefix and/or suffix (prefixes, suffixes) on variables holding a new Hono() instance; basePath() instances are left to basepath-variable-name | | ⚠️ warn | |
recommended deliberately contains only the rules that catch real bugs and are safe for any Hono project, plus max-path-name-length, whose generous default limit only flags endpoint names that are almost certainly a design smell. Stylistic rules (route-grouping, global-middleware-placement) and runtime-specific ones (no-process-env — process.env is perfectly valid on Node.js, Bun and Deno) are left out so that adding this plugin to an existing project does not flood it with errors.
License
MIT
