Mahbub Ul Islam
Mahbub Ul Islam

Reputation: 1059

How to prevent prettier to break single line into multiline?

I have written a single line of code.

enter image description here

And after save prettier reformat the line into 2.

enter image description here

How to stop prettier from breaking lines into two?

Upvotes: 5

Views: 6993

Answers (3)

Deyvidas B
Deyvidas B

Reputation: 29

you can skip formatting of single line using // prettier-ignore

if (diceGenerator !== 1) {
    currentScore0El = Number(currentScore0El.textContent) + diceGenerator; // prettier-ignore
    currentScore += diceGenerator;
}

or single code block (the code that before ;)

export const FilterPersonZ: z.ZodType<_> = _FilterPersonZ
    .extend({
        pets: z.lazy(() => z.union([FilterPetZ.optional(), FilterPetZ.array()])),
        job: z.lazy(() => z.union([FilterJobZ.optional(), FilterJobZ.array()])),
    })
    .transform(
        s =>
            ({
                id: s.id,
                fullName: transform(s.fullName, ILike(`${s.fullName}%`)),
                birthDate: s.birthDate,
                pets: s.pets,
                job: s.job,
            } satisfies {[K in keyof Required<typeof s>]: (typeof s)[K]}),
    );
export const FilterPersonZ: z.ZodType<_> = _FilterPersonZ
    .extend({pets: z.lazy(() => z.union([FilterPetZ.optional(), FilterPetZ.array()])), job: z.lazy(() => z.union([FilterJobZ.optional(), FilterJobZ.array()]))})
    .transform(s => ({
        id: s.id,
        fullName: transform(s.fullName, ILike(`${s.fullName}%`)),
        birthDate: s.birthDate,
        pets: s.pets,
        job: s.job,
    } satisfies {[K in keyof Required<typeof s>]: (typeof s)[K]})); // prettier-ignore

or

// prettier-ignore
export const FilterPersonZ: z.ZodType<_> = _FilterPersonZ
    .extend({pets: z.lazy(() => z.union([FilterPetZ.optional(), FilterPetZ.array()])), job: z.lazy(() => z.union([FilterJobZ.optional(), FilterJobZ.array()]))})
    .transform(s => ({
        id: s.id,
        fullName: transform(s.fullName, ILike(`${s.fullName}%`)),
        birthDate: s.birthDate,
        pets: s.pets,
        job: s.job,
    } satisfies {[K in keyof Required<typeof s>]: (typeof s)[K]}));

Upvotes: 0

XAMT
XAMT

Reputation: 1627

Add your prettier config in package.json so I did that and it works.

  "prettier": {
    "printWidth": 200
  }

Upvotes: 1

lejlun
lejlun

Reputation: 4419

You need to increase the printWidth in your .prettierrc file:

The number is the number of characters before a wrap will be attempted, to stop lines from being wrapped at all set a high number like 1000.

.prettierrc

{
    "printWidth": 1000
}

From the prettier documentation

Print Width:
Specify the line length that the printer will wrap on.

Upvotes: 8

Related Questions