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.

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'.
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.
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

Configures ESLint to disallow function declarations after return, with a failing example.

// .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; }
}