Skip to content

Conversation

roccomuso
Copy link
Contributor

Fix lint

@roccomuso roccomuso self-assigned this Feb 24, 2025
@roccomuso roccomuso requested review from ChALkeR and feri42 February 24, 2025 16:33
module.exports = globalThis.WebSocket
} else {
// Node.js or Electron browser process
// eslint-disable-next-line unicorn/no-typeof-undefined
Copy link

Choose a reason for hiding this comment

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

Is there a good reason for typeof? Why not just globalThis.WebSocket === undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the reason is If WebSocket is not defined (like in older browsers versions, server-side runtimes etc), directly accessing globalThis.WebSocket might throw a ReferenceError if WebSocket is not even declared.

Using typeof ensures the check does not break, as typeof safely returns 'undefined' instead of throwing an error.

@roccomuso roccomuso merged commit bb9cf8e into master Feb 25, 2025
1 check passed
@roccomuso roccomuso deleted the rocco/fix-websocket-lint branch February 25, 2025 17:54
Copy link

🎉 This PR is included in version 1.7.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

2 participants