Skip to content
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

Undesirable line break in property accessors #6266

Open
toshi-toma opened this issue Jul 2, 2019 · 2 comments
Open

Undesirable line break in property accessors #6266

toshi-toma opened this issue Jul 2, 2019 · 2 comments
Labels
area:member chains lang:javascript Issues affecting JS status:needs discussion Issues needing discussion and a decision to be made before action can be taken

Comments

@toshi-toma
Copy link

Prettier 1.18.2
Playground link

--parser babylon

Input:

let myApp = {
  /* deeply nested objects */
};

myApp.name.is.too.long.name.space.and.myApp.name.is.too.long.name.space.myApp.name.is.too.long.name.space  = "My First JavaScript App"; // Good

let newApp = myApp.name.is.too.long.name.space.and.myApp.name.is.too.long.name.space.myApp.name.is.too.long.name.space; // Untoward line break

consle.log(myApp.name.is.too.long.name.space.and.myApp.name.is.too.long.name.space.myApp.name.is.too.long.name.space /* Untoward line break*/, 1, 2, 3);

Output:

let myApp = {
  /* deeply nested objects */
};

myApp.name.is.too.long.name.space.and.myApp.name.is.too.long.name.space.myApp.name.is.too.long.name.space =
  "My First JavaScript App"; // Good

let newApp =
  myApp.name.is.too.long.name.space.and.myApp.name.is.too.long.name.space.myApp
    .name.is.too.long.name.space; // Untoward line break

consle.log(
  myApp.name.is.too.long.name.space.and.myApp.name.is.too.long.name.space.myApp
    .name.is.too.long.name.space /* Untoward line break*/,
  1,
  2,
  3
);

if have line break in property accessors, Searchability is degradation.

Expected behavior:

Preferably no line break in property accessors. 🙏

let myApp = {
  /* deeply nested objects */
};

myApp.name.is.too.long.name.space.and.myApp.name.is.too.long.name.space.myApp.name.is.too.long.name.space =
  "My First JavaScript App";

let newApp =
  myApp.name.is.too.long.name.space.and.myApp.name.is.too.long.name.space.myApp.name.is.too.long.name.space;

consle.log(
  myApp.name.is.too.long.name.space.and.myApp.name.is.too.long.name.space.myApp.name.is.too.long.name.space,
  1,
  2,
  3
);
@toshi-toma toshi-toma changed the title Untoward line break in property accessors Undesirable line break in property accessors Jul 2, 2019
@luis-fors-cb
Copy link

This is especially a problem when one long fully-qualified es6 class extends another long fully-qualified es6 class. I would prefer the line to break before or after the extends keyword, but it usually breaks inside one of the class names, harming searchability.

@alexander-akait alexander-akait added lang:javascript Issues affecting JS status:needs discussion Issues needing discussion and a decision to be made before action can be taken labels Aug 7, 2019
@aaronadamsCA
Copy link

Here's some code you should probably never write (Playground link):

  const { originalSrc, transformedSrc } = (await v.json()).data.product.images
    .edges[0].node;

Nonetheless, Prettier is probably making the "wrong" choice here too, in that it breaks within the property chain as opposed to literally anywhere else. OP makes a great point that this would thwart a codebase search for images.edges. It also just looks funny.

A lot of JavaScript line break scenarios were greatly improved in v2.3 but this was not one of them. It's easily worked around by writing better code, but the example does succinctly demonstrate the current limitation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:member chains lang:javascript Issues affecting JS status:needs discussion Issues needing discussion and a decision to be made before action can be taken
Projects
None yet
Development

No branches or pull requests

5 participants