Javascript S1848 and Notification API

This rule states: “There is no good reason to create a new object to not do anything with it.”

I generally agree with the idea behind this rule, the problem is when you run into poorly designed APIs that have constructors that have side effects. The rule says to change the constructor to not have side effects, but that is not possible if the API is, for example, a web standard you have no control over like the Notification API Notification - Web APIs | MDN . In this API simply doing new Notification('msg') will actually send the notification. I don’t know how such terrible design got codified as a web standard, but it did, and to use this API, you have no choice but to violate this rule.

Therefore, this rule should have a list of exceptions for very common APIs with constructors that have side effects. Specifically, APIs that are widely accepted web standards like the Notification API.

Hello David,

Thank you for bringing this up. We’ll look into this one!

For future reference, here’s a link to rule S1848.


Hello David,

Thank you for the feedback,

Indeed this use case should be implemented as an exception to the S1848 rule and not be flagged as an issue.

We created a Ticket to track this false positive.

Best Regards,