Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to only allow named function *expressions*, not declarations #23

Open
Peeja opened this issue Nov 28, 2023 · 0 comments
Open

Option to only allow named function *expressions*, not declarations #23

Peeja opened this issue Nov 28, 2023 · 0 comments

Comments

@Peeja
Copy link

Peeja commented Nov 28, 2023

Description

Many libraries require named functions for various things, but almost all of them end up taking those functions as expressions, rather than requiring them to be declarations. For instance, React's forwardRef works best with a named function rather than an arrow function, because React will use the name for things like debugging information. But that function is an expression passed to forwardRef(); it isn't usually (and never has to be) a function declaration which binds the function to a variable in scope. That's the thing our team actually wants to avoid. We want to always use const to declare variables, never function; and we never want to use anonymous non-arrow function expressions; but we sometimes need to use named function expressions to work well with certain libraries.

Suggested Solution

An option such that this code is correct:

# Arrow function
const doSomething = () => {
  console.log('Doing something!');
};

# Named function expression
useThisFunction(function doSomething() {
  console.log('Doing something!');
});

while this code is incorrect:

# Named function declaration
function doSomething() {
  console.log('Doing something!');
}

# Anonymous (non-arrow) function expression
useThisFunction(doSomething() {
  console.log('Doing something!');
});

Perhaps allowNamedFunctions: "only-expressions"?

Help Needed

I may be able to work on this if it would be accepted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant