eslint-plugin-no-function-declare-after-return
raw JSON → 1.1.0 verified Sat Apr 25 auth: no javascript
An ESLint plugin that enforces a code style rule disallowing function declarations after a return statement within the same scope. Version 1.1.0 is the latest stable release, with auto-fix support added in this version. The plugin is mature, actively maintained, and has no known security issues. It differs from ESLint's built-in no-unreachable rule by focusing specifically on hoisted function declarations after return, which are syntactically valid but harm readability. The plugin is lightweight with zero runtime dependencies besides ESLint.
Common errors
error Error: Failed to load plugin 'no-function-declare-after-return': Unable to load rule 'no-function-declare-after-return/no-function-declare-after-return' ↓
cause The rule name is incorrectly spelled or the plugin isn't installed.
fix
npm install --save-dev eslint-plugin-no-function-declare-after-return and ensure the rule name is 'no-function-declare-after-return/no-function-declare-after-return'.
error ESLint: Configuration for rule 'no-function-declare-after-return' is unknown ↓
cause Used rule name without plugin prefix in flat config or missing plugin declaration.
fix
Add 'no-function-declare-after-return' to the plugins array and prefix the rule: 'no-function-declare-after-return/no-function-declare-after-return'.
Warnings
gotcha This rule enforces a stylistic preference; it does not prevent runtime errors because function declarations are hoisted. ↓
fix Use ESLint's 'no-unreachable' rule to catch truly unreachable code.
breaking Version 1.0.0 was the initial release; rules and plugin name may mismatch in early versions. ↓
fix Upgrade to >=1.0.0 and use the rule as described in the README.
deprecated The package name 'no-function-declare-after-return' used in install instructions may be mistaken for the plugin name; the plugin is imported as 'eslint-plugin-no-function-declare-after-return'. ↓
fix Always use 'no-function-declare-after-return' as the plugin name in .eslintrc, but the npm package name is the same.
Install
npm install eslint-plugin-no-function-declare-after-return yarn add eslint-plugin-no-function-declare-after-return pnpm add eslint-plugin-no-function-declare-after-return Imports
- plugin wrong
// Incorrect: { "rules": { "no-function-declare-after-return": "error" } } (omits plugin name prefix)correct// In .eslintrc: { "plugins": ["no-function-declare-after-return"], "rules": { "no-function-declare-after-return/no-function-declare-after-return": "error" } } - flat config (ESLint 9+) wrong
// Incorrect: using .eslintrc style with flat config or importing incorrectlycorrectimport noFunctionDeclareAfterReturn from 'eslint-plugin-no-function-declare-after-return'; export default [noFunctionDeclareAfterReturn.configs.recommended]; - CommonJS require wrong
// Incorrect: const plugin = require('eslint-plugin-no-function-declare-after-return/no-function-declare-after-return');correctconst plugin = require('eslint-plugin-no-function-declare-after-return'); // In .eslintrc: plugins: ["no-function-declare-after-return"], rules: { ... }
Quickstart
// .eslintrc.js
module.exports = {
plugins: ['no-function-declare-after-return'],
rules: {
'no-function-declare-after-return/no-function-declare-after-return': 'error',
},
};
// Example file that will fail:
function foo() {
return 1;
function bar() { return 2; }
}