Skip to content

Refuse non-function push listeners and clear Codacy findings - #510

Merged
turtledreams merged 1 commit into
stagingfrom
codacy-cleanup
Oct 18, 2026
Merged

turtledreams merged 1 commit into
stagingfrom
codacy-cleanup

Conversation

@turtledreams

Copy link
Copy Markdown
Contributor

What

Follow-up to #508 and #509: clears the 8 Codacy findings that #508 introduced, and fixes a listener-input bug found while doing it.

  • registerForNotification / registerForNotificationOpened with a listener that is not a function
    • Both now log an error, keep the current listener and return a subscription whose remove() does nothing. This is the same placeholder the no-push package already returns.
    • Before: registerForNotification removed the current listener and then threw React Native's EventEmitter.addListener(...): 2nd argument must be a function., so a wrong argument crashed the call and silently dropped the working push listener.
    • Before: registerForNotificationOpened returned nothing, so .remove() on the result crashed. This was Codacy's "mixed return" finding.
  • 32-bit limits in Validators.js and its test are written as 2 ** 31 - 1 and -(2 ** 31). Codacy's "inaccurate numeric literal" warning was a false alarm, because JavaScript stores these integers exactly; the expressions also say why the numbers were chosen.
  • CHANGELOG: the three lines over the 300-character markdownlint limit are split, with no information lost. Added a fix line for registerForNotification.
  • Types: registerForNotificationOpened now returns EventSubscription, without the | void.

Tests

  • New test: a push listener that is not a function is refused, keeps the current listener and gets a subscription that does nothing. It failed on the old code with React Native's TypeError and passes now.
  • The test suite's stand-in for the event emitter now throws for non-function listeners the way React Native's does, so this class of bug can't hide behind the stand-in.
  • The old expectation that a bad listener returns undefined is replaced on purpose: the result is now a no-op subscription.

Checked

Jest 101/101, ESLint 0 errors, strict type check of Countly.d.ts OK, and npm run generate:no-push still applies cleanly.

After merge

Regenerate the no-push package into a new PR to staging-np, as in #509.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Lbwg6rsYZ3rHLE7T1JC9Qx

- registerForNotification and registerForNotificationOpened now refuse a listener that is not a function: they log an error, keep the current listener and return a subscription that does nothing. registerForNotification used to remove the current listener and then throw.
- The 32-bit limits are written as 2 ** 31 - 1 and -(2 ** 31), which Codacy's numeric literal rule accepts.
- CHANGELOG lines over 300 characters are split.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lbwg6rsYZ3rHLE7T1JC9Qx
@turtledreams
turtledreams merged commit fee7c2a into staging Oct 18, 2026
3 checks passed
@turtledreams
turtledreams deleted the codacy-cleanup branch October 18, 2026 09:04
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.

1 participant