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

space-before-function-paren rules for 'asyncArrow' #27

Open
SukkaW opened this issue Dec 14, 2019 · 4 comments
Open

space-before-function-paren rules for 'asyncArrow' #27

SukkaW opened this issue Dec 14, 2019 · 4 comments

Comments

@SukkaW
Copy link
Member

SukkaW commented Dec 14, 2019

I have faced the issue during reviewing the PR hexojs/hexo#3954

Currently we are using ['error', 'never']:

'space-before-function-paren': ['error', 'never'],

function foo() {
    // ...
}

var bar = function() {
    // ...
};

var bar = function foo() {
    // ...
};

class Foo {
    constructor() {
        // ...
    }
}

var foo = {
    bar() {
        // ...
    }
};

var foo = async() => 1

IMHO we could add a space between async & await and function for better distinguishment (['error', {"anonymous": "never", "named": "never", "asyncArrow": "always"}]), which will resulted in:

function foo() {
    // ...
}

var bar = function() {
    // ...
};

class Foo {
    constructor() {
        // ...
    }
}

var foo = {
    bar() {
        // ...
    }
};

var foo = async (a) => await a

"anonymous" and "named" retain never for consistency.

@SukkaW SukkaW changed the title space-before-function-paren rules space-before-function-paren rules for 'asyncArrow' Dec 14, 2019
@curbengh
Copy link
Contributor

curbengh commented Dec 15, 2019

All the new rules (especially ES6) inherits from airbnb style. I prefer to follow their space-before-function-paren, if that's alright.

['error', {"anonymous": "always", "named": "never", "asyncArrow": "always"}]

I don't mind either way, feel free to PR.


I think the reason to have a space for anonymous function is to avoid the possible confusion that function() {} is a function named function. But I don't think it matters much, I believe most (all?) of the anonymous function is already refactored to arrow function.

@curbengh
Copy link
Contributor

Speaking of airbnb, I also prefer 'arrow-parens': 'error' (instead of the current 'arrow-parens': ['error', 'as-needed']). This means parenthesis is always required even when there is only one parameter. I find it easier to locate the parameter.

I previously retain 'as-needed' since hexo largely use that. But then I later found both of us actually always use parenthesis.

@SukkaW
Copy link
Member Author

SukkaW commented Dec 15, 2019

Currently I am using ['error', {"anonymous": "always", "named": "never", "asyncArrow": "always"}] in my own project.
But for consistency, I suggest to only add "asyncArrow": "always" at this time and we could include it in [email protected]

@curbengh
Copy link
Contributor

Agree with adding asyncArrow only for now, others can defer to v5.

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