Comments (8)
I like to use implicit return for functions that returns 'templates', even if split in lines
specialTemplate = ({ arg1, arg2, ...args }) => (
<div>
<EhiComeVa />
<BeneTe />
<UnPoDiAcchiacchi />
<MiSpiace />
</div>
)
from eslint-config.
good point, I think that's acceptable.
It's not a matter of single/multiple lines, rather whether the expression is "linked" to the line where =>
is.
New formulation of the "rule":
implicit returned expression of arrow functions must begin on the same line of the arrow.
Another similar example
({ foo, bar }) => `
Hey ${foo}
ci vediamo al ${bar}?
`
from eslint-config.
I don't think you resolve readability on last example by make the return explicit:
({ foo, bar }) => {
return `
Hey ${foo}
ci vediamo al ${bar}?
`;
}
What's the fat arrow implicit return purpose? Avoid the overhead of writing return statement for functions with single declaration in body?
I think we should encourage that as long as is readable.
arrayOfArrays.map(x =>
x.filter(y => someCondition(y))
.map(y => y * 2)
)
from eslint-config.
Sorry, I realize I wasn't clear.
The last example I posted is a good one, in my view. The implicit return is made clear by the fact that the expression begins right after the =>
.
The last you posted is not, in my opinion. I find it hard to parse, because of the new line after the =>
from eslint-config.
To sum it up
Good cases
[1, 2, 3].map(i => i);
[1, 2, 3].map(i => {
return i;
});
[1, 2, 3].map(i => `
${i}
`);
[1, 2, 3].map(i => (
<span>
${i}
</span>
);
Bad cases
[1, 2, 3].map(i =>
i
);
[1, 2, 3].map(i =>
(
<span>
{i}
</span>
)
);
from eslint-config.
implicit returned expression of arrow functions must begin on the same line of the arrow
I'd say this sums it up perfectly, 👍
But I don't think there's any rule for that (slightly related: http://eslint.org/docs/rules/arrow-body-style)
from eslint-config.
👼 https://github.com/buildo/eslint-plugin-fat-arrow-same-line
from eslint-config.
Since there's no agreement on this, I'll close it for now
from eslint-config.
Related Issues (20)
- curly HOT 6
- rule proposal: method names HOT 2
- max-len should ignore URLs, strings and imports HOT 4
- update eslint peer dep
- rule proposal: promise plugin HOT 8
- Empty lines HOT 15
- upgrade eslint-plugin-react HOT 1
- upgrade eslint-plugin-no-loops
- Create test project to test our rules against
- Find a way to document code HOT 1
- Evaluate eslint-plugin-compat HOT 6
- Add array-bracket-spacing
- Add spaced-comment and no-multi-spaces HOT 4
- Add gdsm to linto config
- Add consistent-return HOT 4
- add eslint-plugin-import/first
- pin eslint-plugin-react to <6.10.1 HOT 2
- Disallow Use of `undefined` Variable (no-undefined) HOT 2
- Enfore space before '/>' in self-closing tags HOT 14
- add smooth release
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-config.