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
Unexpected block statement surrounding arrow body arrow-body-style #5498
Comments
If you wrap the object in parentheses, it will parse correctly and the rule won't error: this.post('/post', () => ({
post: {
foo: 1,
bar: 2,
},
}); |
Sorry, pressed wrong button. |
@ilyavolodin No, it was the right button. This is not a bug. |
@michaelficarra is right. This is intended behavior. If |
Ok thx |
@platinumazure Thanks! I've added your example to the docs https://github.com/eslint/eslint/pull/6242/files \0/ |
what about this React code?
I get the error, but I have no clue how to rewrite it... |
|
I know this is closed but I was hoping someone could help with my issue. I don't know what to do to fix it. As soon as I try one thing I get a different error.
|
@Medros Please stop by in the Gitter chat to discuss. (And please include info about what errors you're getting and on which lines!) Thanks! |
What about const productsReduced = products.reduce((prev, curr) => {
return prev.concat(curr.product);
}, []); |
const productsReduced = products.reduce((prev, curr) => prev.concat(curr.product), []); |
@michaelficarra oh, nice, thank you! |
Sorry to bump this again, but after trying the multiple suggestion here, i'm still unable to make the error go away, this is my code: const SortableItem = new SortableElement((processor) => {
return (
<Row key={processor.id}>
....
</Row>
);
}); EDIT: Figured out i had to remove the 'return' as im returning a single expression |
I had a bunch of these in my express app when returning function calls. Hope this clarifies for some people. As the rule states: Arrow functions have two syntactic forms for their function bodies. They may be defined with a block body (denoted by curly braces) Keep in mind that a function can be this "value" that's implicitly returned. In general, you can just nuke the braces and the Ex:
becomes
|
For what it's worth, |
@not-an-aardvark thank you for pointing that out. but is there a way to find the exact version when it's been added? |
@alexanderkartavtsev The fixer was added in ESLint 3.9.0. I found this by opening the rule file, using "Blame" to find the commit which introduced the |
@JeffBaumgardt if that's still an issue for you. Change the curly braces to parentheses. i.e changeSite: () => (
SystemJS.import('app/lib/components/sites-list/sites-list.js')
.then(() = (...))
); |
so, if return is just an object, you do not need block statement. and if return is just a statement, you do not need 'return' |
What about this: jest.mock('material-ui/Dialog', () => { // Unexpected block statement... (arrow-body-style)
return ({ children }) => { // Unexpected block statement... (arrow-body-style)
return <div>{children}</div>;
};
}); |
@albert-olive try jest.mock('material-ui/Dialog', () => (
({ children }) => (
<div>{children}</div>
);
)); |
What should I do with this piece of code inside jsx? {profile.user_metadata.backendUrlVariants ?
profile.user_metadata.backendUrlVariants.map((url, i) => {
return <MenuItem key={i} value={url} primaryText={url}/>;
}) : null} |
@Badbreaddead this should work: {
profile.user_metadata.backendUrlVariants
? profile.user_metadata.backendUrlVariants.map((url, i) => (
<MenuItem key={i} value={url} primaryText={url}/>
))
: null
} |
@bl4ckdu5t Sorry, didn't quite catch what you meant by ()... |
I see you edited your question @Badbreaddead so I've edited my answer to reflect how you'd write that to prevent being stopped by the rule |
I feel like the earliest comments (i.e. the ones people see when the first show up at this page looking for help) should be edited or something to be clearer: the issue is that an anonymous function containing only a |
#5498 gets more than twice as much traffic as any of our other issues. My interpretation of this fact is that people are often confused by errors from the `arrow-body-style` rule, and end up searching and finding that issue. This commit updates the error message for `arrow-body-style` to be more specific about how to fix the problem.
#5498 gets more than twice as much traffic as any of our other issues. My interpretation of this fact is that people are often confused by errors from the `arrow-body-style` rule, and end up searching and finding that issue. This commit updates the error message for `arrow-body-style` to be more specific about how to fix the problem.
What version of ESLint are you using?
2.3.0
What configuration and parser (Espree, Babel-ESLint, etc.) are you using?
Babel-Eslint version babel/babel-eslint#d2f90c7239e152b8994f250c69c83604cde93292 (from 07 march 2016, need this commit for fix 'estraverse-fb')
What did you do? Please include the actual source code causing the issue.
Error:
1:28 error Unexpected block statement surrounding arrow body arrow-body-style
I cant remove the { } after removing the 'return' because I want to response a object: { }
What did you expect to happen?
No error message with the default setting 'as-needed'
The text was updated successfully, but these errors were encountered: