Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

An ESLint plugin to prevent function declaration after return statement

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

An ESLint plugin to prevent function declaration after return statement
Unit test npm npm bundle size npm

Install

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

Usage

In .eslintrc

{
  "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:

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)

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

  • Way to auto-fix the errors
  • Way to configure the error messages

Build with ♡ by

Bhumij Gupta

Bhumij profile picture

GitHub followers LinkedIn Twitter Follow


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

Keywords

FAQs

Package last updated on 05 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc