Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add javascript_not_expression switch #47

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

keithamus
Copy link
Contributor

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

@keithamus keithamus force-pushed the feat-add-javascript-not-expression branch from d5bd6c1 to 8b79572 Compare July 31, 2017 11:42
@@ -526,6 +526,15 @@ ES6-style variable declaraions (g:switch_builtins.javascript_es6_declarations)
<
Switching to var from const or let is unsupported, since it's assumed to be an unlikely case.

Comparison to false vs negation operator (g:switch_builtins.javascript_not_expression)
>
if (foo == false) { }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the regex, I think this should be a ===.

@AndrewRadev
Copy link
Owner

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants