File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -26,18 +26,24 @@ This rule helps prevent the use of browser global variables that can cause error
26
26
27
27
/* ✓ GOOD */
28
28
onMount(() => {
29
- const a = window. localStorage.getItem('myCat');
29
+ const a = localStorage.getItem('myCat');
30
30
console.log(a);
31
31
});
32
32
33
33
/* ✓ GOOD */
34
34
if (browser) {
35
- const a = window.localStorage.getItem('myCat');
35
+ const a = localStorage.getItem('myCat');
36
+ console.log(a);
37
+ }
38
+
39
+ /* ✓ GOOD */
40
+ if (typeof localStorage !== 'undefined') {
41
+ const a = localStorage.getItem('myCat');
36
42
console.log(a);
37
43
}
38
44
39
45
/* ✗ BAD */
40
- const a = window. localStorage.getItem('myCat');
46
+ const a = localStorage.getItem('myCat');
41
47
console.log(a);
42
48
</script>
43
49
```
You can’t perform that action at this time.
0 commit comments