Skip to content

Commit e7671e4

Browse files
committed
update doc
1 parent 281322a commit e7671e4

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

docs/rules/no-top-level-browser-globals.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,24 @@ This rule helps prevent the use of browser global variables that can cause error
2626
2727
/* ✓ GOOD */
2828
onMount(() => {
29-
const a = window.localStorage.getItem('myCat');
29+
const a = localStorage.getItem('myCat');
3030
console.log(a);
3131
});
3232
3333
/* ✓ GOOD */
3434
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');
3642
console.log(a);
3743
}
3844
3945
/* ✗ BAD */
40-
const a = window.localStorage.getItem('myCat');
46+
const a = localStorage.getItem('myCat');
4147
console.log(a);
4248
</script>
4349
```

0 commit comments

Comments
 (0)