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

Allow one line arrow functions #22

Closed
jhnns opened this issue Mar 8, 2018 · 1 comment
Closed

Allow one line arrow functions #22

jhnns opened this issue Mar 8, 2018 · 1 comment

Comments

@jhnns
Copy link
Member

jhnns commented Mar 8, 2018

We currently disallow arrow functions in favor of a consistent function style. They are only allowed within other functions. However, if the function returns immediately (which is very common in functional programming), it is more readable if we use arrow functions:

// Good
const bla = () => true;
// Good
const bla = () => ({
    prop: true
});
// Bad
const bla = () => {
    return true;
};
// Bad
const bla = () => {
    const blub = true;
    return  blub;
};

See also discussion: eslint/eslint#7765

With the https://github.com/TristonJ/eslint-plugin-prefer-arrow plugin, it's finally possible to define that rule:

        "func-style": [
            "error",
            "declaration",
            {
                "allowArrowFunctions": true
            }
        ],
        "prefer-arrow/prefer-arrow-functions": [
            "error",
            {
                "singleReturnOnly": true
            }
        ]

We should do that.

jhnns added a commit that referenced this issue Aug 26, 2018
See also #22

BREAKING CHANGE: This adds a new rule and might break existing tests
jhnns added a commit that referenced this issue Aug 26, 2018
See also #22

BREAKING CHANGE: This adds a new rule and might break existing tests
@jhnns
Copy link
Member Author

jhnns commented Aug 26, 2018

I prefer a consistent style. Either we use function declarations or arrow functions for everything because refactoring becomes painful if we have both styles. Every time a one-line arrow function becomes a two-line function, I would need to refactor it to a function declaration.

So closing this in favor of #23

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