switch.vim icon indicating copy to clipboard operation
switch.vim copied to clipboard

feat: add javascript_not_expression switch

Open keithamus opened this issue 8 years ago • 1 comments

This adds a switch to JavaScript to switch between something === false and !something - which is a common thing I find I am refactoring.

keithamus avatar Jul 31 '17 11:07 keithamus

This might be reasonable, although I'm not sure about the pattern. The foo.has(bar) expression won't work if it happens to be written as foo.has( bar ). Admittedly, I'm not sure what should be done about that. We could change it to something like \<\([a-zA-z.]\+\%((.\{})\)\), to add an optional (<anything>) group. It still won't work if there are nested brackets, but that might be more of an edge case, so maybe not interesting.

In general, I have to say I'm on the fence about whether this can be considered a common pattern that should be included in the built-ins. I can see the logic in it, and I can see that it might be a common thing in particular refactoring scenarios, but it could just be considered a nice-to have in specific situations. There's a wiki where I point people for this kind of stuff: https://github.com/AndrewRadev/switch.vim/wiki. Putting it in the wiki would also mean it's not necessary to worry too much about brackets and spaces and such, since it's not "official", but something people could copy and adjust to their needs.

What are your thoughts on this idea?

AndrewRadev avatar Aug 12 '17 08:08 AndrewRadev