Skip to content

no-restricted-globals doesn't allow self in service worker envs #1632

@perrin4869

Description

@perrin4869

Upgrading to eslint-config-airbnb broke my service worker linting and the fix is not clear.

Inside a service worker, self is a global variable referring to the ServiceWorkerGlobalScope and is the standard method for setting event listeners. However, the new no-restricted-globals rule disallows the use of self, even if the top of the file includes /* global self */.

One possible solution to the problem would be to set const self = this explicitly on top of the file, but this poses an issue with es modules, where you cannot have this on the global context, and bundlers like rollup actually rewrite this as undefined.

Maybe removing self as a restricted global would be the way to go, or maybe the restricted globals should depend on the environment itself...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions