Prettier putting if statement on one line

北城以北 提交于 2021-01-26 07:39:45

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/54326285/prettier-putting-if-statement-on-one-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!