p42ai / js-assistant

120+ refactorings and code-assists for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=p42ai.refactor
MIT License
119 stars 7 forks source link

Support to convert if-else if to switch case. #8

Closed chandan192 closed 2 years ago

chandan192 commented 2 years ago

Can we have an option to convert if else if to switch case?

I am using tslint but it only shows the linting but does not refactors it.

lgrammel commented 2 years ago

Thanks, great idea! Converting if-else to switch has been on my list for a while. Do you have a reference to the lint rule? The conversion only makes sense in certain cases.

chandan192 commented 2 years ago

image

Please see this image for reference.

lgrammel commented 2 years ago

@chandan192 I've just released version 1.61, which supports converting if-else to switch. Thanks for the suggestion!

chandan192 commented 2 years ago

Hi @lgrammel, Hope you are doing well.

refactoring if-else to switch case doesn't work for if condition with && or || operation.

image

lgrammel commented 2 years ago

@chandan192 thanks for the bug report. I'll look into adding support for ||. It is not clear to me how to translate && into a switch, do you have an example?

chandan192 commented 2 years ago

@lgrammel, you are right, I didn't think of the condition with &&. But we can have support for ||.

lgrammel commented 2 years ago

Fixed in 1.64.2 - thanks for the bug report!