Is there a way to configure ESLint to throw an error when the code uses localStorage or sessionStorage?
This is needed as I use a third party library for the storage, and I want all the storage to be done through it.
I already tried searching for a plugin, with no results.
You can also use no-restricted-syntax, if you want to forbid all localStorage.method() calls.
'no-restricted-syntax': [
  'error',
  {
    selector: "CallExpression[callee.object.name='localStorage']",
    message: 'Do not use `localStorage` directly, use the storage wrapper instead',
  },
  {
    selector: "CallExpression[callee.object.name='sessionStorage']",
    message: 'Do not use `sessionStorage` directly, use the storage wrapper instead',
  },
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With