brodycj / prettierx

a less opinionated fork of Prettier code formatter
MIT License
209 stars 22 forks source link

switch-case indentation should be optional #20

Open lukescott opened 5 years ago

lukescott commented 5 years ago

Looking for an option to not indent cases:

switch(type) {
case "one":
  // ...
case "two": {
  let foo = "bar"
  // ...
  break
}
case "three": {
  let something = "here"
  // ...
  break
}}

Cannot get normal prettier to cooperate w/ our style guidelines here. The reason for this is we write Go and TypeScript code, and Go mandates case formatting be inline, so we have standardized on that. We try to keep our formatting standards as close as possible between languages.

So I'm looking for a fork to provide such an option. Unfortunately there isn't much out there besides prettier.

If I could have my way, I would like a tslint plugin that handled the line wrapping and use the other auto-fix rules for everything else. But nothing like that exists that I know of.

brodycj commented 5 years ago

Thanks @lukescott, I will rewrite the title then give my response.

brodycj commented 5 years ago

I would really favor this kind of an enhancement, and a contribution would be very welcome. I hope to make this soon, cannot make any promises right now. Here are a few comments I have:

I would consider this to be applicable to JavaScript and supported derivatives such as Flow and TypeScript. Whenever we add a test case, it is possible to specify that it be run over parsers such as Babel (was born as Babylon), Flow, and TypeScript.

I found the original title to be a bit confusing since I am not so familiar with the tslint tooling. Here is the reference documentation that I think the title was referring to: https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/terIndentRule.md

If I could have my way, I would like a tslint plugin that handled the line wrapping and use the other auto-fix rules for everything else. But nothing like that exists that I know of.

I suspect you mean some kind of a TypeScript equivalent to eslint-plugin-prettier (see https://prettier.io/docs/en/eslint.html) or prettier-eslint.

I think the ultimate solution would be some kind of a pipeline-based toolset using the Acorn parser data structure, as I described in https://github.com/brodybits/prettierx/issues/8#issuecomment-468468549.

And please accept my apologies for the small delay.