# eslint-plugin-no-function-declare-after-return

> An ESLint plugin to prevent function declaration after return statement

Latest version **1.1.0** (published 2020-10-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install eslint-plugin-no-function-declare-after-return
pnpm add eslint-plugin-no-function-declare-after-return
yarn add eslint-plugin-no-function-declare-after-return
bun add eslint-plugin-no-function-declare-after-return
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2020-10-05 |
| First published | 2020-08-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | bhumijgupta |
| Maintainers | bhumijgupta |
| Keywords | eslint, eslint-plugin, eslintplugin, function, declaration, after, return |

## Links

- npm: https://www.npmjs.com/package/eslint-plugin-no-function-declare-after-return
- Repository: https://github.com/bhumijgupta/eslint-plugin-no-function-declare-after-return
- Homepage: https://github.com/bhumijgupta/eslint-plugin-no-function-declare-after-return#readme
- Issues: https://github.com/bhumijgupta/eslint-plugin-no-function-declare-after-return/issues
- npm.io page: https://npm.io/package/eslint-plugin-no-function-declare-after-return

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@pandacss/eslint-plugin](https://npm.io/package/@pandacss/eslint-plugin.md) — 18.7K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2020-10-05
- 1.0.0 — 2020-08-29

## README

# eslint-plugin-no-function-declare-after-return

An ESLint plugin to prevent function declaration after return statement  
![Unit test](https://github.com/bhumijgupta/eslint-plugin-no-function-declare-after-return/workflows/Unit%20test/badge.svg) ![npm](https://img.shields.io/npm/dm/eslint-plugin-no-function-declare-after-return) ![npm bundle size](https://img.shields.io/bundlephobia/min/eslint-plugin-no-function-declare-after-return) ![npm](https://img.shields.io/npm/v/eslint-plugin-no-function-declare-after-return)

## Install

```bash
# Using npm
npm i -S no-function-declare-after-return
# Using yarn
yarn add no-function-declare-after-return
```

## Usage

In `.eslintrc`

```javascript
{
  "plugins": [
    "no-function-declare-after-return"
  ],
  "rules": {
    "no-function-declare-after-return/no-function-declare-after-return": 2
  }
}
```

## Motivation

Let's consider a code example:

```javascript
function publicMethods(obj){
    if(obj instanceof customClass)
        return {
            set: methodSetter(obj),
            get: methodGetter(obj),
        }
    function methodSetter(obj){
        .
        .
        .
    }
    function methodGetter(obj){
        .
        .
        .
    }
}
```

The function compiles succesfully even though the functions are used before declaration. This is due to the fact that -

> Function declarations in JavaScript are hoisted to the top of the enclosing function or global scope. ([More Info](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function))

But considering from a readability standpoint, it is quite difficult to figure out where the function is defined and also difficult for new comers to keep in mind the concept of hoisting.  
This plugin will enforce that there are no function declarations are the return statement.

**Note** : This plugin is separate, and in no way replaces `no-unreachable-code` of ESLint.

## Future features

- [x] Way to auto-fix the errors
- [ ] Way to configure the error messages

## Build with ♡ by

### Bhumij Gupta

<img src="https://avatars.githubusercontent.com/bhumijgupta?size=200" alt="Bhumij profile picture">

![GitHub followers](https://img.shields.io/github/followers/bhumijgupta?label=Follow&style=social) [![LinkedIn](https://img.shields.io/static/v1.svg?label=connect&message=@bhumijgupta&color=success&logo=linkedin&style=flat&logoColor=white)](https://www.linkedin.com/in/bhumijgupta/) ![Twitter Follow](https://img.shields.io/twitter/follow/bhumijgupta?style=social)

---

```javascript
if (repo.isAwesome || repo.isHelpful) {
  StarRepo();
}
```

---
_Source: https://npm.io/package/eslint-plugin-no-function-declare-after-return · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
