Coder Social home page Coder Social logo

Comments (8)

francescogior avatar francescogior commented on August 25, 2024

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.

gabro avatar gabro commented on August 25, 2024

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.

ascariandrea avatar ascariandrea commented on August 25, 2024

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.

gabro avatar gabro commented on August 25, 2024

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.

gabro avatar gabro commented on August 25, 2024

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.

giogonzo avatar giogonzo commented on August 25, 2024

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.

gabro avatar gabro commented on August 25, 2024

👼 https://github.com/buildo/eslint-plugin-fat-arrow-same-line

from eslint-config.

gabro avatar gabro commented on August 25, 2024

Since there's no agreement on this, I'll close it for now

from eslint-config.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.