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

Clarification about: When using arrow functions as named exports, explicit return should always be used to maintain consistency with regular functions. #57

Closed
AndreaPontrandolfo opened this issue Jan 4, 2024 · 5 comments

Comments

@AndreaPontrandolfo
Copy link

When using arrow functions as named exports, explicit return should always be used to maintain consistency with regular functions.

Can you expand in the docs what you mean by this, and what is the purpose?

@u3u
Copy link
Owner

u3u commented Jan 5, 2024

Hi, thank you for your report. This is actually just my personal coding style 😂

👇 Please see the example below:

// A simple function with named export
export const getUser = async () => fetch('/api/user').then(res => res.json())

// A React component with named export
export const User = ({ user }) => <u className="no-underline font-medium">{user.name}</u>

// ---
// Compare regular functions, I think they are more intuitive.

export async function getUser() {
  return fetch('/api/user').then(res => res.json())
}

export function User({ user }) {
  // I can add things here at any time.
  return <u className="no-underline font-medium">{user.name}</u>
}

When used as named exports, it proves that they are reusable. I hope to maintain a consistent function style, which will also make it easier to add code in the future. My idea is that although implicit return is concise, it is not conducive to expansion, so it is best to use it only in very simple anonymous callback functions.

If you really don't like this, I can add an option to allow disabling it.

@AndreaPontrandolfo
Copy link
Author

I see what you mean, it mostly make sense. But yeah, a config option for this could be nice

@u3u
Copy link
Owner

u3u commented Jan 5, 2024

Hmm, yes, after all, everyone has different habits. I will add it.

@u3u
Copy link
Owner

u3u commented Jan 6, 2024

https://github.com/u3u/eslint-plugin-arrow-return-style/releases/tag/v1.3.0
The option has been added, and now it should be possible to disable it with
/* eslint arrow-return-style/arrow-return-style: ['warn', { namedExportsAlwaysUseExplicitReturn: false }] */ .

@AndreaPontrandolfo
Copy link
Author

Thank you, that's perfect!

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

2 participants