Skip to content

Add line break before the right-hand side of an assignment #379

Open
@cjpearson

Description

@cjpearson

There are a couple cases where I'd like dprint to behave a little bit more like prettier. The goals is that for assignments where the right-hand side is a binary expression, dprint would first add a line break after the equals sign, then break apart the expression only if necessary. The same would also apply to object properties.

I've looked through the options and don't think it's currently possible, but I may be missing something.

dprint-plugin-typescript version: 0.69.1

Input Code

const camelcasedName = defaultName.split('-').map((x) => x.charAt(0).toUpperCase() + x.substring(1)).join('');
const namespacedName = 'Foo' + defaultName.split('-').map((x) => x.charAt(0).toUpperCase() + x.substring(1)).join('');

const myObject = {
    long_concatenated_value: "Hello" + "World" + "this" + "is" + "a" + "long" + "string",
    long_concatenated_value_two: "This" + "expression" + "exceeds" + "the" + "line" + "width" + "on" + "its" + "own"
};

const linebreak_test_1 = "Hello" + "World" + "this" + "is" + "a" + "long" + "string";
const linebreak_test_2 = "This" + "expression" + "exceeds" + "the" + "line" + "width" + "on" + "its" + "own";

Desired Output

const camelcasedName = defaultName
    .split("-")
    .map((x) => x.charAt(0).toUpperCase() + x.substring(1))
    .join("");
const namespacedName =
    "Foo" +
    defaultName
        .split("-")
        .map((x) => x.charAt(0).toUpperCase() + x.substring(1))
        .join("");

const myObject = {
    long_concatenated_value:
        "Hello" + "World" + "this" + "is" + "a" + "long" + "string",
    long_concatenated_value_two:
        "This" +
        "expression" +
        "exceeds" +
        "the" +
        "line" +
        "width" +
        "on" +
        "its" +
        "own",
};

const linebreak_test_1 =
    "Hello" + "World" + "this" + "is" + "a" + "long" + "string";
const linebreak_test_2 =
    "This" +
    "expression" +
    "exceeds" +
    "the" +
    "line" +
    "width" +
    "on" +
    "its" +
    "own";

Actual Output

const camelcasedName = defaultName
    .split("-")
    .map((x) => x.charAt(0).toUpperCase() + x.substring(1))
    .join("");
const namespacedName = "Foo" +
    defaultName
        .split("-")
        .map((x) => x.charAt(0).toUpperCase() + x.substring(1))
        .join("");

const myObject = {
    long_concatenated_value: "Hello" +
        "World" +
        "this" +
        "is" +
        "a" +
        "long" +
        "string",
    long_concatenated_value_two: "This" +
        "expression" +
        "exceeds" +
        "the" +
        "line" +
        "width" +
        "on" +
        "its" +
        "own",
};

const linebreak_test_1 = "Hello" +
    "World" +
    "this" +
    "is" +
    "a" +
    "long" +
    "string";
const linebreak_test_2 = "This" +
    "expression" +
    "exceeds" +
    "the" +
    "line" +
    "width" +
    "on" +
    "its" +
    "own";

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions