p42ai / js-assistant

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

Unsafe suggestions #61

Closed pdcmoreira closed 2 years ago

pdcmoreira commented 2 years ago

I've just installed this extension and the first suggestion I got raised a huge red flag for me, as it changes the output of the function instead of just the syntax.

The suggestion is the following:

image

But by applying that, changes the behavior of the function to null and '' (empty string) values!

// Original
const funcA = a => {
  a = a || 'Default'

  return a
}

// Suggested change
const funcB = (a = 'Default') => {
  return a
}

;[undefined, null, '', 'test'].forEach(p => console.log(funcA(p) === funcB(p))) // outputs: true, false, false, true

Is there a way to disable unsafe suggestions?

lgrammel commented 2 years ago

@pdcmoreira thanks for your feedback!

I'll add a configuration option to turn off unsafe suggestions in the diagnostics and the side panel.

lgrammel commented 2 years ago

I've just released v2.5.0 which contains a new configuration option to turn off unsafe suggestions:

image

Thanks again for the idea!