Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bhumijgupta/eslint-plugin-no-function-declare-after-return
An ESLint plugin to prevent using function declaration after return statement
https://github.com/bhumijgupta/eslint-plugin-no-function-declare-after-return
eslint eslint-plugin hacktoberfest javascript
Last synced: about 19 hours ago
JSON representation
An ESLint plugin to prevent using function declaration after return statement
- Host: GitHub
- URL: https://github.com/bhumijgupta/eslint-plugin-no-function-declare-after-return
- Owner: bhumijgupta
- Created: 2020-08-29T04:19:09.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-10-05T03:49:32.000Z (about 4 years ago)
- Last Synced: 2024-11-15T03:43:32.187Z (5 days ago)
- Topics: eslint, eslint-plugin, hacktoberfest, javascript
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/eslint-plugin-no-function-declare-after-return
- Size: 43.9 KB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
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
![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();
}
```