Skip to content

Function calls that take a single lambda should not be on a new line #418

Closed
@JaidenAshmore

Description

@JaidenAshmore

Overview

When there is a only a single argument in a function call it seems unnecessary to place it onto a new line. This misaligns with how other prettier languages work, like in Javascript:

A single argument taking a lambda

image

When there are multiple arguments, e.g. two lambdas

image

Steps to reproduce

Prettier-Java 0.8.0

Stream methods (map, filter, etc)

Input:

final List<Integer> values = Stream.of(1, 2)
    .map(n -> {
        // testing method
        return n * 2;
    })
    .collect(Collectors.toList());

Output:

final List<Integer> values = Stream
    .of(1, 2)
    .map(
        n -> {
            // testing method
            return n * 2;
        }
    )
    .collect(Collectors.toList());

Expected behavior:

final List<Integer> values = Stream
    .of(1, 2)
    .map(n -> {
        // testing method
        return n * 2;
     })
    .collect(Collectors.toList());

Completable Futures (single argument)

Input:

CompletableFuture.supplyAsync(() -> {
    // some processing
    return 2;
});

Output:

CompletableFuture.supplyAsync(
    () -> {
        // some processing
        return 2;
    }
);

Expected behavior:

CompletableFuture.supplyAsync(() -> {
    // some processing
    return 2;
});

Completable Future (Multiple Arguments)

Input:

CompletableFuture.supplyAsync(() -> {
       // some processing
       return 2;
}, executor);

Output:

CompletableFuture.supplyAsync(
    () -> {
         // some processing
         return 2;
    },
    executor
);

Expected behavior:

CompletableFuture.supplyAsync(
    () -> {
        // some processing
        return 2;
     },
     executor
);

Function arguments that exceed width

Input:

myFunction((one, two, three, four, five, six) -> {
       // some processing
       return 2;
});

Output:

myFunction(
      (one, two, three, four, five, six) -> {
           // some processing
           return 2;
      }
);

Expected behavior:

myFunction(
      (one, two, three, four, five, six) -> {
           // some processing
           return 2;
      }
);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions