prettier / eslint-config-prettier

Turns off all rules that are unnecessary or might conflict with Prettier.
MIT License
5.4k stars 254 forks source link

Need help with one rule! #154

Closed wispamulet closed 4 years ago

wispamulet commented 4 years ago

Hi!

I'm using prettier integrating with eslint now. I have installed eslint-config-prettier and eslint-plugin-prettier and it worked as fine as I expected.

Somehow I want to write my code like this (it doesn't make any sense, but I'm just curious 🙄

if (foo)
  foo++;

By default it would be fixed to one line because obviously it's much less than printWidth. Or I can manually add curly braces around this one-line statement.

if (foo) foo++;

//or

if (foo) {
  foo++;
}

Then I found two rules related to this: curly nonblock-statement-body-position

For this rule curly, "multi-or-nest" is what I'm looking for, But on the README of this repo, it says, This rule requires certain options. which means it would only work when setting to "all", so the code would always be like this,

if (foo) {
  foo++;
}

For the other one, it would conflict between eslint and prettier when I set to this 'nonblock-statement-body-position': [1, "below"], eslint yelled 'Expected a linebreak before this statement.' but prettier insisted to make them on one line.

😲 So, is there any method to omit curly braces with a block when there is only one line statement and enforce body to next line?

lydell commented 4 years ago

Hi! No, there isn’t. You have Prettier’s way or always curlies to choose between. I’d suggest always using curlies – it’s just one extra line compared to your wanted style (and it makes it easy to add another line to the if).