Skip to content

Update 10.2 as per func-style allowArrowFunction#270

Merged
sambostock merged 1 commit intomasterfrom
update-10-2-as-per-func-style-allow-arrow-functions
Oct 26, 2018
Merged

Update 10.2 as per func-style allowArrowFunction#270
sambostock merged 1 commit intomasterfrom
update-10-2-as-per-func-style-allow-arrow-functions

Conversation

@sambostock
Copy link
Contributor

This updates rule 10.2 following the change in Shopify/eslint-plugin-shopify#188 allowing arrow function expressions.

@sambostock sambostock requested a review from lemonmade October 25, 2018 17:12
@sambostock
Copy link
Contributor Author

The current Why? section looks like this

Why? Function declarations are named, so they’re easier to identify in call stacks. Also, the whole body of a function declaration is hoisted, whereas only the reference of a function expression is hoisted. This rule makes it possible to always use Arrow Functions in place of function expressions.

I'm not sure how to update it, especially since

This rule makes it possible to always use Arrow Functions in place of function expressions.

is already there... 🤔

I could add something like

Arrow functions are acceptable when their this semantics are required, or when function expression typing semantics are desired, if working with TypeScript. For example:

interface Props { className: string }
const Div: React.SFC<Props> = ({className, children}) => <div className={className}>{children}</div>

Thoughts @lemonmade?

Copy link
Member

@lemonmade lemonmade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is all you need. You could bring in the reasoning that sometimes arrow functions are useful for typing, but I’d like to avoid showing the SFC example because that’s actually not the pattern we would usually lean towards (especially in the context of new stuff in React where they are largely demonstrating features in function declarations)

README.md Outdated
const bad = function() {}

// okay
const okay = () => {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can mark this as “also good”

@sambostock sambostock force-pushed the update-10-2-as-per-func-style-allow-arrow-functions branch from 72b521f to 465ddd1 Compare October 26, 2018 14:16
@sambostock sambostock changed the title [WIP] Update 10.2 as per func-style allowArrowFunction Update 10.2 as per func-style allowArrowFunction Oct 26, 2018
@sambostock sambostock merged commit 0e350b4 into master Oct 26, 2018
@sambostock sambostock deleted the update-10-2-as-per-func-style-allow-arrow-functions branch October 26, 2018 14:18
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

Successfully merging this pull request may close these issues.

2 participants