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

Adding a space after function name is better #168

Closed
3 tasks done
zanminkian opened this issue Apr 11, 2023 · 3 comments
Closed
3 tasks done

Adding a space after function name is better #168

zanminkian opened this issue Apr 11, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@zanminkian
Copy link
Contributor

zanminkian commented Apr 11, 2023

Clear and concise description of the problem

Main opinion

When defining a function,

function fun () {
}

is better than

function fun() {
}

Example

Let's say I have 3 files.

// tmp1.ts
export function xxx(): string {
  return 'xxx'
}

// tmp2.ts
export const xxx = 'xxx'

// tmp3.ts
import { xxx } from './tmp1'

xxx()

If I want to search where has called xxx function globally, you will find that the definition and the usages will appear at the same time, which will disturb me. But if there is white space after xxx, like xxx (), we can easily separate the definition and the invokation (usage).
image

So, the adding a space after function name will be more convenient and it's the best practice I think.

Suggested solution

Enable https://eslint.org/docs/latest/rules/space-before-function-paren.

Alternative

No response

Additional context

No response

Validations

@zanminkian zanminkian added the enhancement New feature or request label Apr 11, 2023
@antfu
Copy link
Owner

antfu commented Apr 11, 2023

Thanks for bringing this up. I think it could be reasonable to some extent, but this thing is still opinionated in the end. I don't really have a strong opinion over which, but as this will affect a lot of existing code, I'd prefer to keep it as-it to reduce noises.

@antfu antfu closed this as not planned Won't fix, can't repro, duplicate, stale Apr 11, 2023
@zanminkian
Copy link
Contributor Author

but as this will affect a lot of existing code

Yes. Maybe this is the only reason.

@zanminkian
Copy link
Contributor Author

export function f<T>(t: T): T {
  return t
}

f<string>('abc')

I've re-thought it. In the case above, adding a space after function name does little help.

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

No branches or pull requests

2 participants