cmstead / js-codeformer

A JS refactoring and code automation tool for building better source
MIT License
27 stars 2 forks source link

Convert ternary to if/else #17

Closed cmstead closed 3 years ago

cmstead commented 3 years ago

This is a carry-over from JS Refactor. Please see the link below:

https://github.com/cmstead/js-refactor/issues/93

The original issue was a little light on specifics, so I want to make sure I draw out a clear boundary of what will be supported.

I see four distinct cases I can support without running into really strange cases which may not be "worth the squeeze" so to speak:

  1. A ternary used in a return statement
  2. A ternary used in a variable initialization
  3. A ternary used in a variable assignment
  4. A ternary used in isolation as a side-effect behavior
    • This will only be supported at a block or program scope

Any other cases, such as ternaries inside of if conditions, for loop expressions, while conditions, etc. won't be supported as there isn't any clear way they could be.

cmstead commented 3 years ago

I've opted to bypass the assignment-only behavior and only support variable declarations for the moment. Otherwise, this is complete and available in the latest release:

https://github.com/cmstead/js-codeformer/releases/tag/v1.11.0