prettier icon indicating copy to clipboard operation
prettier copied to clipboard

Ugly positioning for promise then/catch

Open ackvf opened this issue 6 years ago • 3 comments

This change makes the code harder to follow.

image

Input:

      dispatch(RequestsDuck.submitRequestComment(id, { text, files }))
        .then(() => this.setState({text: '', files: [] }))

then takes up one line and is self contained.

Output:

      dispatch(RequestsDuck.submitRequestComment(id, { text, files })).then(() =>
        this.setState({ text: '', files: [] })
      );

then takes up three lines, starts at the end of another functionality and is overall harder to follow.

Expected behavior: Expected is that .then starts the new line so that it is more clear and easier to follow the chain, instead of having to look at the end of a line.

ackvf avatar Mar 01 '19 14:03 ackvf

Ugly Position for .catch:

Playground Link

Input:

  const token = await psApi
  	.tokenAsync(formRef.current)
  	.catch(errors => {
 		// do something with errors
  		return null;
	});

Output:

  const token = await psApi.tokenAsync(formRef.current).catch(erros => {
    // do something with errors
    return null;
  });

Expected behavior:

.catch should be a "header" for a reject callback to make reject handling obvious.

Better -- keep input unchanged. Acceptable:

  const token = await psApi.tokenAsync(formRef.current)
  	.catch(errors => {
 		// do something with errors
  		return null;
	});

try { ... } catch { ... } is much more verbose then .catch chain call and requires to use let declaration for token.

DScheglov avatar Feb 25 '20 12:02 DScheglov

So vue users can't use prettier because of this ugly feature ?

Mikaleb avatar Apr 16 '21 09:04 Mikaleb

2024 here, any updates on this?

avelops avatar Mar 26 '24 21:03 avelops