question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discussion about formatting "rules" (i.e. the one with parenthesis)

See original GitHub issue

Note: this is primarily for others who’ve used prettier since its inception to understand, as formatting styles have changed, the underlying rationale behind formatting decisions.

tldr; How would you describe the “rules” that prettier operates against when deciding to keep or remove structural syntax?.


Background

(Related to #1733 and now #2065)

This tweet got some attention from some notable folks:

https://twitter.com/ericclemmons/status/876179258888081408 “I like prettier, but I’d prefer that parenthesis didn’t change instances like these.” – @ericclemmons screen shot 2017-06-17 at 3 41 02 pm screen shot 2017-06-17 at 3 41 18 pm

Rationale

My take on Prettier’s “rationale” (rules) for formatting is to balance legibility with consistency.

Based on the changes since 1.3.1 (IIRC), it’s more like balance legibility with ~consistency~ simplicity.

Early on, my sense was that ArrowExpressions generally matched the following:

  • Single-line expressions with implicit return:

    () => 42
    
  • Multi-line expressions with implicit return:

    (props) => (
      <div>
        Hello there, {props.children}!
      </div>
    );`
    
  • Multi-line expressions with explicit return:

    (props) => {
      const { children } = props;
    
      return (
        <div>
          Hello there, {children}!
        </div>
      );
    }`
    

As complexity grew (going from () to (props) to ({ children }), etc.), formatting changes were minimal.

It seems now that there’s a bit more of a jello effect, where it wiggles in more places than where you poked it 😉

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:23
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

21reactions
Haroenvcommented, Jun 22, 2017

I’d prefer parenthesis for all multi-line arrow functions as well. Before prettier I was not aware that it was possible to do that, and it looks quite scary to me. The parenthesis around jsx also made it easier to move parts, since it’s completely separated from other parts of the code.

11reactions
btnwtncommented, Jun 29, 2017

I want enforced parens for single parameter arrow functions so badly 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use Brackets in Academic Writing: Some Common Rules
Different types of brackets are used in academic writing based on discipline and style guide. This article provides common rules in APA, MLA, ......
Read more >
i.e. vs. e.g.: How to Use i.e. or e.g.
In formal writing in the U.S., a leading tendency is to follow the abbreviations with a comma and enclose the text in parentheses....
Read more >
How to Use 'E.g.' and 'I.e.' - AJE
I.e. and E.g. Punctuation and Formatting · Parenthesis are not completely necessary, but they help the reader follow and understand the use of...
Read more >
Does Punctuation Go Inside or Outside Parentheses?
Rule #1 ... If the words that appear inside the parentheses are not a complete sentence, then place the terminal punctuation after the...
Read more >
Formatting punctuation - Microsoft Style Guide
Use the same font style for the closing parenthesis or bracket that you use for the opening parenthesis or bracket. Recommended content. Use ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found