Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prettier putting if statement on one line

Tags:

prettier

Prettier formats if statement without curley braces into one line.

This means that this :

function getErrorMessage(response) {
    let errorMessage = null;

    if (!response.originalError.response) 
        errorMessage = 'network error';
    else 
        errorMessage = response.originalError.response.data.errorMessage;

    return errorMessage;
}

becomes this :

function getErrorMessage(response) {
    let errorMessage = null;

    if (!response.originalError.response) errorMessage = 'network error';
    else errorMessage = response.originalError.response.data.errorMessage;

    return errorMessage;
}

which is FAR more unreadable.

Is there a way of disabling this?

like image 306
Oliver Watkins Avatar asked Jan 23 '19 11:01

Oliver Watkins


1 Answers

As asked in a similar question, it turns out that the answer is that you can not and will not be able to.

As for the WFT that an average senses, well... Apparently, opinionated doesn't mean respected and well-considered in opinion of many. It means that it's implementing the author's opinion.

So, surprisingly, the unexpected thing isn't the lack of configurability but rather that there are any options to be set at all! Go figure... Someone should create a new package called EvenPrettier or FexiblyPrettier and fork in more options. If I only knew how, I'd do it.

like image 104
Konrad Viltersten Avatar answered Oct 07 '22 00:10

Konrad Viltersten