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

fix: remove fallthrough switch statement #1247

Merged
merged 8 commits into from
Jul 1, 2021

Conversation

mmkal
Copy link
Contributor

@mmkal mmkal commented Oct 15, 2020

  • if this is your first time contributing, run npm run add-contributor and follow the prompts to add yourself to the README

This removes the use of a fall-through switch statement. While it technically works, it's confusing to humans - and, as it turns out, to machines.

I have a slightly strange use case, where the runtime I'm using can't handle async/await. I'm able to make isomorphic-git work by supplying it with a filesystem with purely sync operations. But to avoid promises, I'm using babel-plugin-transform-async-to-promises, which converts async/await statements into .then/.catch wrappers.

This allows shimming the global Promise object to do everything synchronously (or throw, in cases like http calls where that's impossible). Unfortunately babel-plugin-transform-async-to-promises can't handle switches with fallthrough. So most likely this is technically a bug with that package rather than isomorphic-git, but fixing it there would be really complicated since it involves dynamic code-generation, and requires very careful thought about edge-cases. Plus, the repo isn't very active. Fixing it here makes the code clearer, IMO and avoids the violation of a lint rule.

I haven't added or changed any tests because the functionality should be identical. If the existing tests pass, it should be safe to merge.

cc @wmhilton

}
case 'content': {
if (format === 'content') return result
break
Copy link
Contributor Author

@mmkal mmkal Oct 15, 2020

Choose a reason for hiding this comment

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

note: I don't think this break statement should have been here. I've kept the equivalent for consistency, by converting to a return, but by breaking here, we'd end up returning undefined instead of throwing, which seems wrong. I'd be happy to open another PR fixing that issue as a follow-up - I'd rather keep the functionality identical with this PR, in case there would be side effects to the fix.

@mmkal
Copy link
Contributor Author

mmkal commented Feb 7, 2021

@wmhilton any thoughts on this?

@mmkal
Copy link
Contributor Author

mmkal commented Jul 1, 2021

@jcubic conflicts are now resolved, this is ready to merge!

@jcubic jcubic merged commit 04fa3d9 into isomorphic-git:main Jul 1, 2021
@isomorphic-git-bot
Copy link
Member

🎉 This PR is included in version 1.8.10 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mojavelinux
Copy link
Contributor

I've looked at this code more than a few times and always thought to myself it needed to be changed. So I'm in support.

FYI, William isn't currently working on the project, so it is best not to mention him. The current maintainers already get notifications when a PR is submitted, so there's really no need to use the @ mention unless you are replying directly to that person.

@billiegoose
Copy link
Member

// BEHOLD! THE ONLY TIME I'VE EVER WANTED TO USE A CASE STATEMENT WITH FOLLOWTHROUGH!

Hahaha. So in the end, even this only time was a mistake! 😂

Good job y'all!

@mmkal mmkal deleted the remove-fallthrough-switch branch July 2, 2021 02:51
modesty pushed a commit to modesty/isomorphic-git that referenced this pull request Apr 9, 2024
* chore: fix broken link in README.md (isomorphic-git#1154)

* fix(react-native): fix for "<Intermediate Value>.stream is not a function" errors in React Native (isomorphic-git#1156)

* chore: remove fallthrough switch statement

* docs: add @mmkal as a contributor

* docs: add @mmkal as a contributor

Co-authored-by: Xavier Francisco <xavier.n.francisco@gmail.com>
Co-authored-by: Corbin Crutchley <crutchcorn@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants